|
6 | 6 |
|
7 | 7 | import functools |
8 | 8 |
|
9 | | -from eth_utils import to_hex |
10 | 9 | from hexbytes import HexBytes |
11 | 10 |
|
| 11 | +from eth_utils import ( |
| 12 | + to_hex, |
| 13 | + function_abi_to_4byte_selector |
| 14 | +) |
12 | 15 | from tronapi.base.abi import ( |
13 | 16 | filter_by_name, |
14 | 17 | filter_by_encodability, |
15 | 18 | filter_by_argument_count, |
16 | 19 | get_fallback_func_abi, |
17 | | - abi_to_signature, get_abi_input_types, check_if_arguments_can_be_encoded, map_abi_data) |
| 20 | + abi_to_signature, |
| 21 | + get_abi_input_types, |
| 22 | + check_if_arguments_can_be_encoded, |
| 23 | + map_abi_data, |
| 24 | + merge_args_and_kwargs |
| 25 | +) |
18 | 26 |
|
19 | 27 | from tronapi.base.function_identifiers import FallbackFn |
20 | 28 | from tronapi.base.normalizers import abi_address_to_hex, abi_bytes_to_bytes, abi_string_to_text |
@@ -126,3 +134,19 @@ def encode_abi(tron, abi, arguments, data=None): |
126 | 134 | return to_hex(HexBytes(data) + encoded_arguments) |
127 | 135 | else: |
128 | 136 | return encode_hex(encoded_arguments) |
| 137 | + |
| 138 | + |
| 139 | +def get_function_info(fn_name, contract_abi=None, fn_abi=None, args=None, kwargs=None): |
| 140 | + if args is None: |
| 141 | + args = tuple() |
| 142 | + if kwargs is None: |
| 143 | + kwargs = {} |
| 144 | + |
| 145 | + if fn_abi is None: |
| 146 | + fn_abi = find_matching_fn_abi(contract_abi, fn_name, args, kwargs) |
| 147 | + |
| 148 | + fn_selector = encode_hex(function_abi_to_4byte_selector(fn_abi)) |
| 149 | + |
| 150 | + fn_arguments = merge_args_and_kwargs(fn_abi, args, kwargs) |
| 151 | + |
| 152 | + return fn_abi, fn_selector, fn_arguments |
0 commit comments