def normalize_filter_params(from_block, to_block, address, topics): yield from_block yield to_block if address is None: yield address elif is_address(address): yield to_canonical_address(address) elif is_list_like(address): yield tuple( to_canonical_address(item) for item in address ) else: raise TypeError("Address is not in a recognized format: {0}".format(address)) if topics is None: yield topics elif is_valid_topic_array(topics): yield tuple( normalize_topic_list(item) if is_list_like(item) else normalize_topic(item) for item in topics ) else: raise TypeError("Topics are not in a recognized format: {0}".format(address))
def is_empty_or_address(val): if val in {None, b'', ''}: return True elif is_address(val): return True else: return False
def is_rlp_structured_access_list(val): """Returns true if 'val' is a valid rlp-structured access list.""" if not is_list_like(val): return False for item in val: if not is_list_like(item): return False if len(item) != 2: return False address, storage_keys = item if not is_address(address): return False for storage_key in storage_keys: if not is_int_or_prefixed_hexstr(storage_key): return False return True
def is_rpc_structured_access_list(val): """Returns true if 'val' is a valid JSON-RPC structured access list.""" if not is_list_like(val): return False for d in val: if not is_dict(d): return False if len(d) != 2: return False address = d.get('address') storage_keys = d.get('storageKeys') if any(_ is None for _ in (address, storage_keys)): return False if not is_address(address): return False if not is_list_like(storage_keys): return False for storage_key in storage_keys: if not is_int_or_prefixed_hexstr(storage_key): return False return True
def buildMakeMultiSwapTx(transaction, defaultChainId): tx = transaction['params'] if len(tx) > 0: #print(tx) for ii in range(len(tx)): if 'ToAssetID' not in tx[ii]: raise ValueError( 'In buildMakeMultiSwapTx, could not find ToAssetID in tx') elif not isinstance(tx[ii]['ToAssetID'], list): raise ValueError( 'In buildMakeMultiSwapTx, ToAssetID is not a list') else: nToAsset = len(tx[ii]['ToAssetID']) if 'ToStartTime' not in tx[ii]: tx[ii]['ToStartTime'] = [] for jj in range(nToAsset): tx[ii]['ToStartTime'].append( to_hex_if_datestring('now')) else: if not isinstance(tx[ii]['ToStartTime'], list): raise ValueError( 'In buildMakeMultiSwapTx, ToStartTime is not a list' ) elif len(tx[ii]['ToStartTime']) != nToAsset: raise ValueError( 'In buildMakeMultiSwapTx, ToStartTime list is not the same length as ToAssetID' ) else: for jj in range(nToAsset): tx[ii]['ToStartTime'][jj] = to_hex_if_datestring( tx[ii]['ToStartTime'][jj]) if 'ToEndTime' not in tx[ii]: tx[ii]['ToEndTime'] = [] for jj in range(nToAsset): tx[ii]['ToEndTime'].append( to_hex_if_datestring('infinity')) else: if not isinstance(tx[ii]['ToEndTime'], list): raise ValueError( 'In buildMakeMultiSwapTx, ToEndTime is not a list') elif len(tx[ii]['ToEndTime']) != nToAsset: raise ValueError( 'In buildMakeMultiSwapTx, ToEndTime list is not the same length as ToAssetID' ) else: for jj in range(nToAsset): tx[ii]['ToEndTime'][jj] = to_hex_if_datestring( tx[ii]['ToEndTime'][jj]) if 'MinToAmount' not in tx[ii]: raise ValueError( 'In buildMakeMultiSwapTx, could not find MinToAmount in tx' ) else: if not isinstance(tx[ii]['MinToAmount'], list): raise ValueError( 'In buildMakeMultiSwapTx, MinToAmount is not a list' ) elif len(tx[ii]['MinToAmount']) != nToAsset: raise ValueError( 'In buildMakeMultiSwapTx, MinToAmount list is not the same length as ToAssetID' ) else: for jj in range(nToAsset): tx[ii]['MinToAmount'][ jj] = to_hex_if_integer_or_ascii( tx[ii]['MinToAmount'][jj]) if 'FromAssetID' not in tx[ii]: raise ValueError( 'In buildMakeMultiSwapTx, could not find FromAssetID in tx' ) elif not isinstance(tx[ii]['FromAssetID'], list): raise ValueError( 'In buildMakeMultiSwapTx, FromAssetID is not a list') else: nFromAsset = len(tx[ii]['FromAssetID']) if 'FromStartTime' not in tx[ii]: tx[ii]['FromStartTime'] = [] for jj in range(nFromAsset): tx[ii]['FromStartTime'].append( to_hex_if_datestring('now')) else: if not isinstance(tx[ii]['FromStartTime'], list): raise ValueError( 'In buildMakeMultiSwapTx, FromStartTime is not a list' ) elif len(tx[ii]['FromStartTime']) != nFromAsset: raise ValueError( 'In buildMakeMultiSwapTx, FromStartTime list is not the same length as FromAssetID' ) else: for jj in range(nFromAsset): tx[ii]['FromStartTime'][jj] = to_hex_if_datestring( tx[ii]['FromStartTime'][jj]) if 'FromEndTime' not in tx[ii]: tx[ii]['FromEndTime'] = [] for jj in range(nFromAsset): tx[ii]['FromEndTime'].append( to_hex_if_datestring('infinity')) else: if not isinstance(tx[ii]['FromEndTime'], list): raise ValueError( 'In buildMakeMultiSwapTx, FromEndTime is not a list' ) elif len(tx[ii]['FromEndTime']) != nFromAsset: raise ValueError( 'In buildMakeMultiSwapTx, FromEndTime list is not the same length as FromAssetID' ) else: for jj in range(nFromAsset): tx[ii]['FromEndTime'][jj] = to_hex_if_datestring( tx[ii]['FromEndTime'][jj]) if 'MinFromAmount' not in tx[ii]: raise ValueError( 'In buildMakeMultiSwapTx, could not find MinFromAmount in tx' ) else: if not isinstance(tx[ii]['MinFromAmount'], list): raise ValueError( 'In buildMakeMultiSwapTx, MinFromAmount is not a list' ) elif len(tx[ii]['MinFromAmount']) != nFromAsset: raise ValueError( 'In buildMakeMultiSwapTx, MinFromAmount list is not the same length as FromAssetID' ) else: for jj in range(nFromAsset): tx[ii]['MinFromAmount'][ jj] = to_hex_if_integer_or_ascii( tx[ii]['MinFromAmount'][jj]) if 'SwapSize' not in tx[ii]: raise ValueError( 'In buildMakeMultiSwapTx, could not find SwapSize in tx') else: tx[ii]['SwapSize'] = to_int(tx[ii]['SwapSize']) # if 'Targes' not in tx[ii]: raise ValueError( 'In buildMakeMultiSwapTx, could not find Targes in tx') elif not isinstance(tx[ii]['Targes'], list): raise ValueError( 'In buildMakeMultiSwapTx, Targes is not a list') else: for jj in range(len(tx[ii]['Targes'])): if not is_address(tx[ii]['Targes'][jj]): raise ValueError( 'In buildMakeMultiSwapTx, found an invalid address in Targes ', tx[ii]['Targes'][jj]) transaction['params'] = tx if 'nonce' not in transaction: raise ValueError( 'In buildMakeMultiSwapTx, could not find nonce in transaction') else: transaction['nonce'] = to_hex_if_integer_or_ascii(transaction['nonce']) if 'gas' in transaction: transaction['gas'] = to_hex_if_integer_or_ascii(transaction['gas']) if 'gasPrice' in transaction: transaction['gasPrice'] = to_hex_if_integer_or_ascii( transaction['gasPrice']) transaction['chainId'] = to_hex_if_integer_or_ascii(defaultChainId) return transaction