Skip to content

Instantly share code, notes, and snippets.

@flada-auxv
Created August 23, 2018 09:32
Show Gist options
  • Save flada-auxv/0d05474f55308216c47e8ea0624a7d67 to your computer and use it in GitHub Desktop.
Save flada-auxv/0d05474f55308216c47e8ea0624a7d67 to your computer and use it in GitHub Desktop.
internal transaction で発生した event も元の transaction の receipt に含まれる

truffle のデフォルトのディレクトリ構成で contracts/ に Test.sol を配置して

truffle console
> migrate --reset

Fuga.deployed().then(c => c.FugaEvent().options.topics[0] )
// '0x036b5e160c95e397eb8e8ad88d596c87ba315b302a96e253e54a15d259ad4e1a'

Hoge.deployed().then(c => c.HogeEvent().options.topics[0] )
// '0x5e906742a1b3ef89a21bbbd245aacd34d1d972045b3998387fd14aa46b34f112'

fugaExecutedTX = Fuga.deployed().then(c => c.fuga(Hoge.address))
receipt = fugaExecutedTX.then(tx => tx.receipt)
logs = receipt.then(r => r.logs)
// [ { logIndex: 0,
//   transactionIndex: 0,
//   transactionHash: '0x74b9d304c749d28c2b1b6a36ae9ddd2eda5db957ddc93b239a3e8274b8c6c8ca',
//   blockHash: '0x1b46d16e9623ef59aa345c31072dda1c603e358cdee0606b32fad1195486b9d2',
//   blockNumber: 29,
//   address: '0xf5133f15e20f5ec84270fcfb51d7aedd9862c422',
//   data: '0x0000000000000000000000000000000000000000000000000000000000000003',
//   topics:
//    [ '0x036b5e160c95e397eb8e8ad88d596c87ba315b302a96e253e54a15d259ad4e1a',
//      '0x0000000000000000000000000000000000000000000000000000000000000004' ],
//   type: 'mined' },
// { logIndex: 1,
//   transactionIndex: 0,
//   transactionHash: '0x74b9d304c749d28c2b1b6a36ae9ddd2eda5db957ddc93b239a3e8274b8c6c8ca',
//   blockHash: '0x1b46d16e9623ef59aa345c31072dda1c603e358cdee0606b32fad1195486b9d2',
//   blockNumber: 29,
//   address: '0xf4b6cfc4123f264f2a05d272e12cf9eabe39fa08',
//   data: '0x0000000000000000000000000000000000000000000000000000000000000001',
//   topics:
//    [ '0x5e906742a1b3ef89a21bbbd245aacd34d1d972045b3998387fd14aa46b34f112',
//      '0x0000000000000000000000000000000000000000000000000000000000000002' ],
//   type: 'mined' } ]

// We can see logs of both Fuga's and Hoge's, that is, the event which occured within internall transaction is also included in transaction receipt for original transaction.
pragma solidity ^0.4.24;
contract Hoge {
event HogeEvent(uint arg1, uint indexed arg2);
function hoge() public {
emit HogeEvent(1, 2);
}
}
contract Fuga {
Hoge hoge;
event FugaEvent(uint arg1, uint indexed arg2);
function fuga(address hoge_address) public {
emit FugaEvent(3, 4);
hoge = Hoge(hoge_address);
hoge.hoge();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment