Skip to content

Instantly share code, notes, and snippets.

@coburncoburn
Created February 20, 2019 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coburncoburn/6d0265ad21b4bdea0364ee393e88245c to your computer and use it in GitHub Desktop.
Save coburncoburn/6d0265ad21b4bdea0364ee393e88245c to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.4+commit.9549d8ff.js&optimize=false&gist=
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment