Skip to content

Instantly share code, notes, and snippets.

@sogoiii
Created February 19, 2018 21:06
Show Gist options
  • Save sogoiii/1cd241fca6c4572c66a7ee646240a07f to your computer and use it in GitHub Desktop.
Save sogoiii/1cd241fca6c4572c66a7ee646240a07f to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.18;
contract DB {
uint public data;
function updateData(uint _val) public {
data = _val;
}
}
contract Worker1 {
address public db;
function setN(uint _n) public {
db.delegatecall(bytes4(keccak256("updateData(uint256)")), _n);
}
function setDB(address _addr) public {
db = _addr;
}
}
contract Worker2 {
address public db;
function setN2(uint _n) public {
db.delegatecall(bytes4(keccak256("updateData(uint256)")), _n);
}
function setDB(address _addr) public {
db = _addr;
}
}
contract Factory {
address worker;
function updateWorker(address _w) public {
worker = _w;
}
function getWorker() view public returns (address) {
return worker;
}
function doWork(uint _val, string fnName) public {
worker.call(bytes4(keccak256(fnName)), _val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment