Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates the bug in Solidity which results in structs not being correctly stored in mappings.
contract Whois {
mapping(bytes32 => Address) addresses;
//Struct representing a postal address
struct Address {
bool initialized;
string identifier;
string street;
string city;
}
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;
}
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.