Skip to content

Instantly share code, notes, and snippets.

@daniellehrner
Last active April 8, 2019 13:33
Show Gist options
  • Save daniellehrner/c134ce5cd1b9bb660ec76620bb3d7e8c to your computer and use it in GitHub Desktop.
Save daniellehrner/c134ce5cd1b9bb660ec76620bb3d7e8c to your computer and use it in GitHub Desktop.
Iterable Eternal Storage
addAddressKey("balanceKeys", "0x12...");
function addAddressKey(bytes32 _listId, address _value) external {
// get the number of keys with _listId "balanceKeys"
uint256 size = getUInt256(keccak256(abi.encodePacked(_listId, "KEY_SIZE")));
// the new index (end of the list) is equal to the size of the keys
uint256 index = size;
// store _value as last item in the list
setAddress(keccak256(abi.encodePacked(_listId, "KEY_VALUES", index)), _value);
// increase the size of the list by one
setUInt256(keccak256(abi.encodePacked(_listId, "KEY_SIZE")), size + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment