建议alaya内置合约事件中,增加topics

我的问题

hi, 我在使用python sdk获取内置合约交易的event事件时,发现事件中的topics字段为空,这让我无法正常的使用filter获取想要的合约事件,建议针对内置合约,也增加topics。

示例:
//以下是锁仓合约交易的回执,可以看到topics字段为空,其他内置合约交易的event也是一样。


AttributeDict({
‘blockHash’: HexBytes(‘0x696e906bdef81bb359eae29323f772ed82e0171c8aebf00710975254847b87d1’),
‘blockNumber’: 458521,
‘contractAddress’: None,
‘cumulativeGasUsed’: 68632,
‘from’: ‘atp1zkrxx6rf358jcvr7nruhyvr9hxpwv9uncjmns0’,
‘gasUsed’: 68632,
‘logs’: [
AttributeDict({
‘address’: ‘atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp8h9fxw’,
‘topics’: [
],
‘data’: ‘0xc130’,
‘blockNumber’: 458521,
‘transactionHash’: HexBytes(‘0x7c09994a4404a5ab7d8d8c5186173d7c343ad7f663e1dc88d4ab94801f8cd3ac’),
‘transactionIndex’: 0,
‘blockHash’: HexBytes(‘0x696e906bdef81bb359eae29323f772ed82e0171c8aebf00710975254847b87d1’),
‘logIndex’: 0,
‘removed’: False
})],
‘logsBloom’: HexBytes(‘0x00000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000’),
‘status’: 1,
‘to’: ‘atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp8h9fxw’,
‘transactionHash’: HexBytes(‘0x7c09994a4404a5ab7d8d8c5186173d7c343ad7f663e1dc88d4ab94801f8cd3ac’),
‘transactionIndex’: 0
})


建议方法

增加topics使用与合约一样的方式即可:

The topics argument is order-dependent.
For non-anonymous events, the first item in the topic list is always the keccack hash of the event signature.
Subsequent topic items are the hex encoded values for indexed event arguments.

topic[0]: keccak(Transfer(param1,param2,param2,…)),对事件的所有参数做keccak散列运算
topic[1]: param1的十六进制编码,补齐64位
topic[2]: param2的十六进制编码,补齐64位
topic[N]: 同上,paramN的十六进制编码,补齐64位

但是也有例外情况,在进行staking的时候,现在的node ID和BLS key的hex长度超过了64,也许还有其他的情况,我想我们可以具体讨论一下。

使用方法

我想,在增加topics后,我可以在我的python代码中,通过topics来使用filter:

event_filter = web3.platon.filter({
“address”: myContract_address,
“topics”: [
event_signature_hash,
“0x000000000000000000000000000000000000000000000000000000000000000a”,
“0x000000000000000000000000000000000000000000000000000000000000000b”,

],
})

这有充足的自由度和更简单的方式,让我获得我想要的事件信息,在开发DApp的时候方便许多。

3 Likes

不错的建议 :+1:, 不过涉及到和旧数据兼容性问题,实施这个想法需要链上治理升级
另外,对于每个接口的正常、异常流程都需要明确topics填充规则, 建议整理成AIP提案!
看看大家有什么意见?