Created
October 26, 2018 15:32
-
-
Save adamdossa/3c256ef52cf6f1c0329c8c9e71b74676 to your computer and use it in GitHub Desktop.
Solidity Callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract Data { | |
address[] investors; | |
function addData(uint256 _iters) public { | |
for (uint256 i = 0; i < _iters; i++) { | |
investors.push(address(i)); | |
} | |
} | |
function apply(uint256 _start, uint256 _end, function(address) external _callback) public { | |
for (uint256 i = _start; i < _end; i++) { | |
_callback(investors[i]); | |
} | |
} | |
} | |
contract Worker { | |
address public dataAddress; | |
event Log(address _sender, address _contract, address _investor); | |
constructor(address _dataAddress) public { | |
dataAddress = _dataAddress; | |
} | |
function applyWork(uint256 _start, uint256 _end) public { | |
Data(dataAddress).apply(_start, _end, this.callback); | |
} | |
function callback(address _investor) external { | |
emit Log(msg.sender, address(this), _investor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment