Guest User

Storage Operations Demo

a guest
Nov 8th, 2018
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. contract StorageOperationsDemo {
  2.     uint public x;
  3.     uint public y;
  4.    
  5.     function setX(uint value) public {
  6.         assembly {
  7.             sstore(add(x_slot, x_offset), value)
  8.         }
  9.     }
  10.    
  11.     function setY(uint value) public {
  12.         assembly {
  13.             sstore(add(y_slot, y_offset), value)
  14.         }
  15.     }
  16.    
  17.     function swapXY() public {
  18.         assembly {
  19.             let temp := sload(add(x_slot, x_offset))
  20.             let yVal := sload(add(y_slot, y_offset))
  21.             sstore(add(x_slot, x_offset), yVal)
  22.            
  23.             sstore(add(y_slot, y_offset), temp)
  24.         }
  25.     }
  26. }
RAW Paste Data