Created
February 2, 2018 14:13
-
-
Save blueplanet/8b728e47d7d5801433eadf61c60c315b to your computer and use it in GitHub Desktop.
スマートコントラクトの定時実行を調べてみた ref: https://qiita.com/blueplanet/items/bb9effd226106dd39344
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
contract PackedArray { | |
uint[] public arrays; | |
function push(uint[] _args) public { | |
arrays = _args; | |
} | |
function remove(uint index) public { | |
PackedArray(this).pack(arrays, index); | |
} | |
function pack(uint256[] _arrays, uint256 _deleteIndex) external { | |
uint256 length = _arrays.length; | |
uint256[] memory copy = new uint256[](length - 1); | |
assembly { | |
//find array data pos; | |
let freep := mload(0x40) | |
mstore(0x40, add(freep, 0x20)) | |
calldatacopy(freep, 0x4, 0x20) | |
// array data first 32 byte is length. so slide to array body pos; | |
let arrayDataPos := add(mload(freep), 0x20) | |
let size := mul(0x20, _deleteIndex) | |
// method sig 4byte. | |
calldatacopy(add(copy, 0x20), add(0x04, arrayDataPos), size) | |
let afterpos := add(add(copy, 0x20), size) | |
let alldatasize := mul(0x20, length) | |
let aftersize := sub(alldatasize, add(size, 0x20)) | |
let afterindexPos := add(add(arrayDataPos, size), 0x20) | |
calldatacopy(afterpos, add(0x04, afterindexPos), aftersize) | |
} | |
arrays = copy; | |
} | |
} |
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
import 'contracts/Interface/SchedulerInterface.sol'; | |
... | |
SchedulerInterface scheduler = SchedulerInterface(0xTODO); | |
uint lockedUntil = block.number + _numBlocks; | |
scheduler.schedule.value(2 ether)( | |
myContractAddress, // 呼び出されたいスマートコントラクトアドレス | |
"", // 関数のパラメータデータ | |
[ | |
2000000, // 取引と一緒に送付されるガスの量。 | |
0, // 送信するガス量 | |
255, // 実行ウインドウのサイズ | |
lockedUntil, // 開始ブロック番号 | |
30000000000 wei, // GAS price | |
12345 wei, // 取引に含まれる寄付 | |
224455 wei, // 取引に含まれる支払い | |
20000 wei // 請求者がデポジットとして送信しなければならない必要額。 | |
] | |
); | |
... |
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
npm i -g eac.js | |
eac.js -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment