Created
February 4, 2016 17:21
-
-
Save clowestab/ca86d0ee43de1e918c22 to your computer and use it in GitHub Desktop.
Demonstrates the bug in Solidity which results in structs not being correctly stored in mappings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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