Skip to content

Instantly share code, notes, and snippets.

@blueplanet
Created February 2, 2018 14:13
Show Gist options
  • Select an option

  • Save blueplanet/8b728e47d7d5801433eadf61c60c315b to your computer and use it in GitHub Desktop.

Select an option

Save blueplanet/8b728e47d7d5801433eadf61c60c315b to your computer and use it in GitHub Desktop.

Revisions

  1. blueplanet created this gist Feb 2, 2018.
    35 changes: 35 additions & 0 deletions file0.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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;
    }
    }
    21 changes: 21 additions & 0 deletions file1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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 // 請求者がデポジットとして送信しなければならない必要額。
    ]
    );
    ...
    2 changes: 2 additions & 0 deletions file2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    npm i -g eac.js
    eac.js -c