【发布时间】:2018-10-21 08:06:32
【问题描述】:
我有一个以太坊合约,其事件定义如下:
event Apple(address indexed a, address b, address c);
事件被触发,我可以在交易收据中看到日志。
通过 web3,当我尝试从收据解析日志时,我能够检索事件参数,但看起来 a 的值始终相同。
// compiled is the built contract. address is the contract address
const contract = new web3.eth.Contract(compiled.abi, address)
const eventJsonInterface = _.find(
contract._jsonInterface,
o => o.name === 'Apple' && o.type === 'event',
)
const log = _.find(
receipt.logs,
l => l.topics.includes(eventJsonInterface.signature)
)
web3.eth.abi.decodeLog(eventJsonInterface.inputs, log.data, log.topics)
我最终得到的是:
Result {
'0': '0x42087b16F33E688a9e73BFeef94F8F2bd2BfC98f',
'1': '0xfc36bFe712f30F75DF0BA9A60A109Ad51ac7Ca38',
'2': '0x6915d2f3D512F7CfEF968f653D1cA3ed4489798C',
__length__: 3,
a: '0x42087b16F33E688a9e73BFeef94F8F2bd2BfC98f',
b: '0xfc36bFe712f30F75DF0BA9A60A109Ad51ac7Ca38',
c: '0x6915d2f3D512F7CfEF968f653D1cA3ed4489798C' }
其中a 在触发的事件中始终是相同的地址。我正在为每笔交易生成一个新合约,a 是这个新合约的地址(我已经通过从生成的合约中触发一个单独的事件来验证它是正确的,该事件也发出a 的值),所以event Apple 的 a 解析值绝对不正确。
以前有人遇到过这种情况吗?
我正在使用 web3 1.0.0-beta.33
【问题讨论】:
-
你能分享发出事件的代码吗?