[Ethereum] Struct not being stored in mapping when it contains more than two ‘string’ properties. Bug

mappingsoliditystoragestringstruct

I am playing around with Solidity, and have encountered an extremely bemusing issue. I want to have a mapping of Address instances (postal addresses NOT the address type)

Address is a custom defined struct as follows:

//Struct representing a postal address
struct Address {

    bool initialized;

    string identifier;

    string street;
    string city;
}

Now, I have a public function for building an address, defined as follows:

function buildAddress(string identifier, string street, string city) public returns(string){

    Address storage addressInstance = addresses[sha3(identifier)];

    addressInstance.initialized = true;
    addressInstance.identifier = identifier;
    addressInstance.street = street;
    addressInstance.city = city;

    return identifier;
}

and I have a getter defined as follows:

function getAddressStreet(string addressIdentifier) public constant returns(string) {

    Address storage addressInstance = addresses[sha3(addressIdentifier)];

    if (addressInstance.initialized == false) {
        // Unknown node, just return 0x0;
        return "No address";
    }

    return addressInstance.street;   
}

My issue is that this does not work. 'Building' an address, mining the transaction, and then 'getting' the street name returns 'No address'.

What is bemusing however is that if I remove one string property from the address struct e.g city, it all works perfectly.. as expected.

That is to say that when there are more than 2 string properties in the struct, the Address is seemingly not persisted on the block chain.

I suspect this may be something to do with storage locations, but having read the appropriate documentation a number of times I cannot see anything that is obviously incorrect..

Could anyone provide any insight into this? This may well be a bug, but I imagine that it is more likely a simple oversight on my part. Any clarification would be appreciated !

Thomas

Best Answer

According to the comments on the question, this is likely a bug within solidity.

https://github.com/ethereum/solidity/issues/381

Related Topic