-
Notifications
You must be signed in to change notification settings - Fork 11
/
__init__.py
55 lines (45 loc) · 1.4 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import Any, List, Optional, Tuple, Union
from .decoder import InputDecoder
__all__ = (
"decode_constructor",
"decode_function",
"InputDecoder",
)
def decode_constructor(
abi: List[dict],
tx_input: Union[str, bytes],
bytecode: Optional[Union[str, bytes]] = None,
) -> List[Tuple[str, str, Any]]:
"""Decode constructor transaction input
Parameters
----------
abi: List[dict]
Contract ABI
tx_input: Union[str, bytes]
Transaction input to decode, with or without deployed contract bytecode
bytecode: Union[str, bytes], optional
Optional deployed contract bytecode. If this is set, `tx_input` should include bytecode
Returns
-------
List[Tuple[str, str, Any]]
Decoded type-name-value tuples
"""
decoder = InputDecoder(abi) # type:ignore[arg-type]
return decoder.decode_constructor(tx_input, bytecode).arguments
def decode_function(
abi: List[dict], tx_input: Union[str, bytes]
) -> List[Tuple[str, str, Any]]:
"""Decode function transaction input
Parameters
----------
abi: List[dict]
Contract ABI
tx_input: Union[str, bytes]
Transaction input to decode
Returns
-------
List[Tuple[str, str, Any]]
Decoded type-name-value tuples
"""
decoder = InputDecoder(abi) # type:ignore[arg-type]
return decoder.decode_function(tx_input).arguments