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
address[] memory addressKeys = getAddressKeys("balanceKeys"); | |
function getAddressKeys(bytes32 _listId) external view returns (address[] memory) { | |
// get the number of keys with _listId "balanceKeys" | |
uint256 size = getUInt256(keccak256(abi.encodePacked(_listId, "KEY_SIZE"))); | |
// create an address array with the size of the list | |
address[] memory keys = new address[](size); | |
// iterate over the list |
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
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 |
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
_balances[_who] = _balances[_who] / (10 ** 16) |
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
function setBalance(address _who, uint256 _value) external { | |
_balances[_who] = _value; | |
} |
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
function setBalance(address _who, uint256 _value) external { | |
setUInt256( | |
// computes the Ethereum-SHA-3 (Keccak-256) hash | |
keccak256( | |
// performs packed encoding of the given arguments, | |
// as the hash function only accepts one argument | |
abi.encodePacked( | |
// we use a hardcoded string to create a different | |
// hash for the same dynamic value | |
"balance", |
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
mapping(bytes32 => uint256) internal uInt256Storage; | |
function getUInt256(bytes32 _key) external view returns (uint256) { | |
return uInt256Storage[_key]; | |
} | |
function setUInt256(bytes32 _key, uint256 _value) external { | |
uInt256Storage[_key] = _value; | |
} |