def get_normalized_abi_arg_type(abi_arg: ABIEventParams) -> str: """ Return the normalized type for the abi argument provided. In order to account for tuple argument types, this abstraction makes use of `collapse_if_tuple()` to collapse the appropriate component types within a tuple type, if present. """ return collapse_if_tuple(dict(abi_arg))
def _get_event_abi_types(abi_inputs: List[Dict]) -> Iterator[Union[str, Dict]]: for abi_input in abi_inputs: abi_type = grammar.parse(abi_input["type"]) if abi_type.is_dynamic: yield "bytes32" else: yield collapse_if_tuple(abi_input)
def get_aligned_abi_inputs( abi: ABIFunction, args: Union[Tuple[Any, ...], Mapping[Any, Any]] ) -> Tuple[Tuple[Any, ...], Tuple[Any, ...]]: """ Takes a function ABI (``abi``) and a sequence or mapping of args (``args``). Returns a list of type strings for the function's inputs and a list of arguments which have been aligned to the layout of those types. The args contained in ``args`` may contain nested mappings or sequences corresponding to tuple-encoded values in ``abi``. """ input_abis = abi.get('inputs', []) if isinstance(args, abc.Mapping): # `args` is mapping. Align values according to abi order. args = tuple(args[abi['name']] for abi in input_abis) return ( # typed dict cannot be used w/ a normal Dict # https://github.com/python/mypy/issues/4976 tuple(collapse_if_tuple(abi) for abi in input_abis), # type: ignore type(args)( _align_abi_input(abi, arg) for abi, arg in zip(input_abis, args) ), )
def encode_function_call_abi(abi: dict, params: list) -> str: signature = function_abi_to_4byte_selector(abi) inputs = ",".join([ collapse_if_tuple(abi_input) for abi_input in abi.get("inputs", []) ]) params = encode_single(f"({inputs})", params) return encode_hex(signature + params)
def get_abi_output_types(abi: ABIFunction) -> List[str]: if abi['type'] == 'fallback': return [] else: return [ collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi['outputs'] ]
def function_definition_to_text_signature(abi: Dict[str, Any]) -> str: return '{fn_name}({fn_input_types})'.format( fn_name=abi['name'], fn_input_types=','.join([ collapse_if_tuple(abi_input) for abi_input in abi.get('inputs', []) ]), )
def get_abi_input_types(abi: ABIFunction) -> List[str]: if 'inputs' not in abi and (abi['type'] == 'fallback' or abi['type'] == 'receive'): return [] else: return [ collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi['inputs'] ]
def get_event_abi_types_for_decoding(event_inputs): """ Event logs use the `keccak(value)` for indexed inputs of type `bytes` or `string`. Because of this we need to modify the types so that we can decode the log entries using the correct types. """ for input_abi in event_inputs: if input_abi['indexed'] and is_dynamic_sized_type(input_abi['type']): yield 'bytes32' else: yield collapse_if_tuple(input_abi)
def get_function_inputs_abi(self, fn_name): fn_abi = self.get_function_abi(fn_name) if fn_abi is not None: inputs = fn_abi["inputs"] inputsres = [] #print(">>>>",inputs) for item in inputs: #将里面的tuple转义 inputsres.append(collapse_if_tuple(item)) #print("get_function_inputs_abi",inputsres) return inputsres return None
def get_aligned_abi_inputs(abi, args): """ Takes a function ABI (``abi``) and a sequence or mapping of args (``args``). Returns a list of type strings for the function's inputs and a list of arguments which have been aligned to the layout of those types. The args contained in ``args`` may contain nested mappings or sequences corresponding to tuple-encoded values in ``abi``. """ input_abis = abi.get('inputs', []) if isinstance(args, abc.Mapping): # `args` is mapping. Align values according to abi order. args = tuple(args[abi['name']] for abi in input_abis) return ( tuple(collapse_if_tuple(abi) for abi in input_abis), type(args)(_align_abi_input(abi, arg) for abi, arg in zip(input_abis, args)), )
def get_abi_output_types(abi: 'ABIFunction') -> List[str]: return ([] if abi['type'] == 'fallback' else [ collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi['outputs'] ])
def get_abi_output_types(abi): if abi['type'] == 'fallback': return [] else: return [collapse_if_tuple(arg) for arg in abi['outputs']]
def get_abi_input_types(abi): if 'inputs' not in abi and abi['type'] == 'fallback': return [] else: return [collapse_if_tuple(arg) for arg in abi['inputs']]
def get_abi_output_types(abi: Union[ABIFunction, ABIEvent]) -> List[str]: if abi['type'] == 'fallback': return [] else: return [collapse_if_tuple(arg) for arg in abi['outputs']]
def get_fn_abi_types(abi,name): if abi['type'] == 'fallback': return [] else: return [collapse_if_tuple(arg) for arg in abi[name]]
def exclude_indexed_event_inputs_to_abi(event_abi): args_not_indexed =exclude_indexed_event_inputs(event_abi) result = [collapse_if_tuple(arg) for arg in args_not_indexed] return result