为了解析来自私有链事务的数据并获取为特定事务发送的输入数据,我想了解这一点,我尝试过许多解码器,但在某些时候,它们失败了。这是我尝试使用混合的简单的智能契约。
contract simple{
uint256 deliveryID;
string status;
function stringAndUint(string _status,uint256 _deliveryID){
status=_status;
deliveryID=_deliveryID;
}
} 生成的输入数据:- 0x3c38b7fd0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000067374617475730000000000000000000000000000000000000000000000000000
我可以从上面解释以下内容。
发布于 2018-07-11 22:00:51
试着看看这里的http://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#argument-encoding和http://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#use-of-dynamic-types
将编码拆分为32字节块将得到:
发布于 2018-07-11 22:06:28
所使用的编码是什么?
Solidity使用“合同ABI”规范进行编码。
额外的40和6有什么关系?
@Brendan关于这些值的答案比我的要好,所以我将删除这一节。我会把答案贴在网上,因为下面的部分仍然很有用。
按程序复制
在python中有一个名为eth-abi的ABI解码工具,您可以这样使用:
from eth_utils import to_bytes
encoded = to_bytes(hexstr="0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000067374617475730000000000000000000000000000000000000000000000000000")
from eth_abi import decode_abi
decoded = decode_abi(['string', 'uint256'], encoded)
assert decoded == (b'status', 12)https://stackoverflow.com/questions/51294460
复制相似问题