Guest User

Untitled

a guest
Jan 13th, 2021
8
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity 0.4.24;
  2.  
  3. import "@aragon/os/contracts/common/UnstructuredStorage.sol";
  4.  
  5. /**
  6. * @title UnstructuredCounter
  7. * @dev Implements demo unstructured equivalent to `mapping (address => uint256)`
  8. */
  9. contract UnstructuredCounter {
  10.  
  11. using UnstructuredStorage for bytes32;
  12.  
  13. // Should be equivalent to the following Solidity mapping, except starting from slot COUNTER_ROOT_POSITION
  14. // mapping (address => uint256) private counter;
  15. bytes32 internal constant COUNTER_ROOT_POSITION = keccak256("someNamespace.UnstructuredCounter.counter");
  16.  
  17.  
  18. function _getCounter(address _account) internal view returns (uint256) {
  19. bytes32 accountCountPosition = keccak256(abi.encodePacked(_account, COUNTER_ROOT_POSITION));
  20. return accountCountPosition.getStorageUint256();
  21. }
  22.  
  23. function _setCounter(address _account, uint256 _value) internal {
  24. bytes32 accountCountPosition = keccak256(abi.encodePacked(_account, COUNTER_ROOT_POSITION));
  25. accountCountPosition.setStorageUint256(_value);
  26. }
  27.  
  28. /**
  29. * @dev Store value in variable
  30. * @param num value to store
  31. */
  32. function store(uint256 num) public {
  33. _setCounter(msg.sender, num);
  34. }
  35.  
  36. /**
  37. * @dev Return value
  38. * @return value of 'number'
  39. */
  40. function retrieve() public view returns (uint256){
  41. return _getCounter(msg.sender);
  42. }
  43. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×