15

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

6
  • I had a very similar problem a few months ago with a string in a struct with other variables (ints in my case). It did turn out to be a bug. Here is the issue on the <a href="forum.ethereum.org/discussion/3475/…> and <a href="github.com/ethereum/solidity/issues/74">a link to the github issue</a> which was closed. I'd say open up an issue, definitely looks like a similar bug with storage locations. Commented Feb 3, 2016 at 16:52
  • 2
    @RobertMcCone for future reference, links are formated as [text](link) in comments. Commented Feb 3, 2016 at 19:44
  • Could you please provide the full code for a simple contract that behaves like that? Especially the mapping you use is of interest.
    – chriseth
    Commented Feb 4, 2016 at 15:27
  • Chris, I have updated the Github issue with a link to a gist which demonstrates the issue. The Github issue lists steps to reproduce. Commented Feb 4, 2016 at 17:26
  • 2
    @PiperMerriam I converted your answer to a comment, with the hope of attracting an actual answer, since even the Github issue has been closed without resolution.
    – eth
    Commented Apr 4, 2016 at 22:17

1 Answer 1

2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.