async def is_ancestor( ancestor: bytes, descendant: bytes, limit: int = 240) -> bool: ''' Determine if ancestor precedes descendant ancestor and descendant MUST be LE ''' data = calldata.call( "isAncestor", [ancestor, descendant, limit], relay_ABI) res = await shared.CONNECTION._RPC( method='eth_call', params=[ { 'from': config.get()['ETH_ADDRESS'], 'to': config.get()['CONTRACT'], 'data': f'0x{data.hex()}' }, 'latest' # block height parameter ] ) # returned as 0x-prepended hex string representing 32 bytes return bool(int(res, 16))
def create_open_data( partial_tx: str, reservePrice: int, reqDiff: int, asset: str, value: int) -> bytes: '''Makes an data blob for calling open Args: partial_tx (str): the partial transaction to submit reservePrice (int): the lowest acceptable price (not enforced) reqDiff (int): the amount of difficult required in the proof's header chain asset (str): asset address value (int): asset amount or 721 ID Returns: (bytes): the data blob ''' contract_method_args = [ bytes.fromhex(partial_tx), reservePrice, reqDiff, asset, value] return calldata.call('open', contract_method_args, ABI)
async def find_height(digest_le: bytes) -> int: data = calldata.call( "findHeight", [digest_le], relay_ABI) res = await shared.CONNECTION._RPC( method='eth_call', params=[ { 'from': config.get()['ETH_ADDRESS'], 'to': config.get()['CONTRACT'], 'data': f'0x{data.hex()}' }, 'latest' # block height parameter ] ) logger.debug(f'findHeight for {digest_le.hex()} is {res}') return int(res, 16)
def create_claim_data( tx: bytes, proof: bytes, index: int, headers: bytes) -> bytes: '''Makes an unsigned transaction calling claim Args: tx (bytes): the fully signed tx proof (bytes): the merkle inclusion proof index (int): the index of the tx for merkle verification headers (bytes): the header chain containing work Returns: (bytes): the data blob ''' contract_method_args = [ tx, proof, index, headers] return calldata.call('claim', contract_method_args, ABI)
def make_call_tx(contract: str, abi: List[Dict[str, Any]], method: str, args: List[Any], nonce: int, value: int = 0, gas: int = DEFAULT_GAS, gas_price: int = DEFAULT_GAS_PRICE) -> UnsignedEthTx: ''' Sends tokens to a recipient Args: contract (str): address of contract being called abi (dict): contract ABI method (str): the name of the method to call args (list): the arguments to the method call nonce (int): the account nonce for the txn value (int): ether in wei gas_price (int): the price of gas in wei or gwei Returns: (UnsignedEthTx): the unsigned tx object ''' logger.debug(f'making tx call {method} on {contract} ' f'with value {value} and {len(args)} args') gas_price = _adjust_gas_price(gas_price) chainId = config.get()['CHAIN_ID'] data = calldata.call(method, args, abi) txn = UnsignedEthTx(to=contract, value=value, gas=gas, gasPrice=gas_price, nonce=nonce, data=data, chainId=chainId) return txn