Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.2;
- contract StoraTheExplora {
- address delegate;
- constructor() public {
- }
- function setBacon(uint a) public {
- (bool success, bytes memory data) = delegate.delegatecall(abi.encodePacked(bytes4(keccak256("setBacon(uint256)")), a));
- }
- function getBacon() public returns (uint256) {
- (bool success, bytes memory data) = delegate.delegatecall(abi.encodePacked(bytes4(keccak256("getBacon()"))));
- return bytesToUint(data);
- }
- function bytesToUint(bytes memory b) public returns (uint256){
- uint256 number;
- for(uint i=0;i<b.length;i++){
- number = number + uint(uint8(b[i]))*(2**(8*(b.length-(i+1))));
- }
- return number;
- }
- function setDelegate(address d) public {
- delegate = d;
- }
- }
- contract StoraDelegateV1 {
- address delegate;
- uint bacon;
- function setBacon(uint b) public {
- bacon = b;
- }
- function getBacon() public view returns (uint) {
- return bacon;
- }
- }
- contract StoraDelegateV2 {
- // consider all storage declarations to basically
- // override those in the contract doing the delegate calling
- // so they must be declared in the same order or previously stored
- // value will be lost
- address delegate;
- uint bacon;
- uint eggs;
- function setBacon(uint c) public {
- eggs = c;
- }
- function getBacon() public view returns (uint) {
- return eggs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement