5

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

  • You can answer your own question by posting your results below. This will help other users to faster spot the solution and vote up on helpful content. Thanks! – Waqar Lim Jun 23 '16 at 6:22
3

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 for the hint with the binary data.

  • 1
    posted here because 5chdn asked me to – akrueger Jun 23 '16 at 15:42
  • Thanks. You can also mark it as accepted by clicking the tick under the vote score. – Waqar Lim Jun 24 '16 at 9:05
  • Done. You are great! – akrueger Jun 24 '16 at 21:28
2

The JSONRPC returns the data field hex-encoded and the decode_abi function expects binary data, so you need to decoded the data field before calling decode_abi.

import ethereum.abi
logdata_hex = filterChanges[0]['data']
logdata = logdata_hex.decode('hex')
# the addresses will be hex-encoded
data = ethereum.abi.decode_abi(['address', 'address', uint256'], logdata)
  • almost. I had to remove the "0x" then it worked. I have edited my OP. Thanks a lot @hack.augusto – akrueger Jun 22 '16 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.