Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. pragma solidity ^0.5.2;
  2. contract StoraTheExplora {
  3. address delegate;
  4.  
  5. constructor() public {
  6. }
  7.  
  8. function setBacon(uint a) public {
  9. (bool success, bytes memory data) = delegate.delegatecall(abi.encodePacked(bytes4(keccak256("setBacon(uint256)")), a));
  10. }
  11.  
  12. function getBacon() public returns (uint256) {
  13. (bool success, bytes memory data) = delegate.delegatecall(abi.encodePacked(bytes4(keccak256("getBacon()"))));
  14. return bytesToUint(data);
  15. }
  16.  
  17. function bytesToUint(bytes memory b) public returns (uint256){
  18. uint256 number;
  19. for(uint i=0;i<b.length;i++){
  20. number = number + uint(uint8(b[i]))*(2**(8*(b.length-(i+1))));
  21. }
  22. return number;
  23. }
  24.  
  25. function setDelegate(address d) public {
  26. delegate = d;
  27. }
  28. }
  29.  
  30. contract StoraDelegateV1 {
  31. address delegate;
  32. uint bacon;
  33.  
  34. function setBacon(uint b) public {
  35. bacon = b;
  36. }
  37.  
  38. function getBacon() public view returns (uint) {
  39. return bacon;
  40. }
  41. }
  42.  
  43. contract StoraDelegateV2 {
  44. // consider all storage declarations to basically
  45. // override those in the contract doing the delegate calling
  46. // so they must be declared in the same order or previously stored
  47. // value will be lost
  48. address delegate;
  49. uint bacon;
  50. uint eggs;
  51.  
  52. function setBacon(uint c) public {
  53. eggs = c;
  54. }
  55.  
  56. function getBacon() public view returns (uint) {
  57. return eggs;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement