Skip to content

Commit

Permalink
docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jan 5, 2019
1 parent f485096 commit e54a7dd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions eth_event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@


def get_topics(abi):
"""Generate encoded event topics from a contract ABI.
Arguments:
abi -- A contract ABI formatted as a list
Returns a dictionary in the following format:
{'Event Name': "encoded bytes32 topic as a string"}
"""
return dict((
i['name'], "0x" + keccak("{}({})".format(
i['name'],
Expand All @@ -15,6 +25,26 @@ def get_topics(abi):


def decode_event(event, abi):
"""Decode a transaction event.
Arguments:
event -- A single event from a transaction log.
abi -- The contract event ABI. You can supply the specific
event as a dict, or the entire contract ABI as a list
that will be processed with get_topics()
Returns a dictionary in the following format:
{
'name':"Event Name",
'data':[{
'name': "name of variable",
'type': "data type",
'value': "decoded value"
}, ...]
}
"""
if type(abi) is list:
topics = get_topics(abi).items()
topic = next(k for k, v in topics if v == event['topics'][0])
Expand Down

0 comments on commit e54a7dd

Please sign in to comment.