Edit: solved, scroll down.
How to decode filter results?
A contract is emitting this Event
event Send(address from, address to, uint value)
With ethjsonrpc
and its eth_getFilterChanges
I am receiving this filterlog:
filterChanges=[{u'address': u'0x3673d5b436089c9aa3f59df5062c7431c86c21d7',
u'blockHash': u'0x4bf30aba20336f634cfb638dab2bc72b06f79ae21072466102d3bde1247a016c',
u'blockNumber': u'0xb5bed',
u'data': u'0x000000000000000000000000157fb756013257b2705833f12d9897de8600b91f00000000000000000000000043bc6919fd3c40dce81fb4b00bd7e33db68b7be10000000000000000000000000000000000000000000000000000000000000002',
u'logIndex': u'0x0',
u'topics': [u'0x93eb3c629eb575edaf0252e4f9fc0c5ccada50496f8c1d32f0f93a65a8257eb5'],
u'transactionHash': u'0x76b0bf4e5cdaee03725c97710ee3d3f218971664231c7e3259935d3d1b210443',
u'transactionIndex': u'0x0'}]
Now I am trying to decipher that 'data'
-item which is clearly (address, address, amount).
But how to transform it with the python libraries?
data = filterChanges[0]["data"]
print data
print len(data)
import ethereum.abi
data_dec = ethereum.abi.decode_abi(["address", "address", "uint256"], data)
pprint (data_dec)
results in
0x000000000000000000000000157fb756013257b2705833f12d9897de8600b91f00000000000000000000000043bc6919fd3c40dce81fb4b00bd7e33db68b7be10000000000000000000000000000000000000000000000000000000000000002
194
['3030303030303030303030303030313537666237',
'3538333366313264393839376465383630306239',
22343880564164347692490066462159793276992634768622606872680301975360839562809L]
Any hints?
Thx.
Edit: Solved
the decode_abi function expects binary data
filterChanges=[{u'address': u'0x3673d5b436089c9aa3f59df5062c7431c86c21d7',
u'blockHash': u'0xabbaaefe73c34ddfce9c3656ede6a754d105f1a2b43fbcf28baad633703d095c',
u'blockNumber': u'0xb914d',
u'data': u'0x00000000000000000000000043bc6919fd3c40dce81fb4b00bd7e33db68b7be1000000000000000000000000157fb756013257b2705833f12d9897de8600b91f000000000000000000000000000000000000000000000000000000000000002a',
u'logIndex': u'0x0',
u'topics': [u'0x93eb3c629eb575edaf0252e4f9fc0c5ccada50496f8c1d32f0f93a65a8257eb5'],
u'transactionHash': u'0x89247c65380bf66a194a72b01a750356ee4cb8e3ce336dbaaba89b527c21de47',
u'transactionIndex': u'0x0'}]
logdata_hex = filterChanges[0]["data"]
print; print logdata_hex; print len(logdata_hex)
logdata_hex_wo_0x = logdata_hex[2:]
print; print logdata_hex_wo_0x; print len(logdata_hex_wo_0x)
logdata = logdata_hex_wo_0x.decode('hex')
print; print logdata; print len(logdata)
import ethereum.abi
data_dec = ethereum.abi.decode_abi(["address", "address", "uint256"], logdata)
print; pprint (data_dec)
results in:
0x00000000000000000000000043bc6919fd3c40dce81fb4b00bd7e33db68b7be1000000000000000000000000157fb756013257b2705833f12d9897de8600b91f000000000000000000000000000000000000000000000000000000000000002a
194
00000000000000000000000043bc6919fd3c40dce81fb4b00bd7e33db68b7be1000000000000000000000000157fb756013257b2705833f12d9897de8600b91f000000000000000000000000000000000000000000000000000000000000002a
192
C�i�<@������=��{��V2W�pX3�-��ކ�*
96
['43bc6919fd3c40dce81fb4b00bd7e33db68b7be1',
'157fb756013257b2705833f12d9897de8600b91f',
42]
Thanks to @hack.augusto
tags: Python, contract-logs, pyethereum, ethjsonrpc, decode
Best Answer
Solved
the decode_abi function expects binary data
results in:
Thanks to @hack.augusto for the hint with the binary data.