def decode_raw_tx(raw_tx: str) -> DecodedRawTx: tx: Any = rlp.decode(hex_to_bytes(raw_tx), RPLTransaction) tx_hash = Web3.toHex(keccak(hex_to_bytes(raw_tx))) from_ = w3.eth.account.recover_transaction(raw_tx) to = w3.toChecksumAddress(tx.to) if tx.to else None data = w3.toHex(tx.data) r = hex(tx.r) s = hex(tx.s) chain_id = (tx.v - 35) // 2 if tx.v % 2 else (tx.v - 36) // 2 return DecodedRawTx(**md(tx_hash, from_, to, data, chain_id, r, s, tx.v, tx.gas, tx.gas_price, tx.value, tx.nonce))
def encode_raw_tx_with_signature( *, nonce: int, gas_price: int, gas: int, v: int, r: str, s: str, data: Optional[str] = None, value: Optional[int] = None, to: Optional[str] = None, ): if to: to = hex_to_bytes(to) # type:ignore if data: data = hex_to_bytes(data) # type:ignore if not value: value = 0 r = int(r, 16) # type:ignore s = int(s, 16) # type:ignore tx = RPLTransaction.new_tx( **md(nonce, gas_price, gas, data, value, to, v, r, s)) return Web3.toHex(rlp.encode(tx))
def decode_data(types: list[str], data: str): return eth_abi.decode_abi(types, hex_to_bytes(data))
def decode_single(type_: str, data: str): return eth_abi.decode_single(type_, hex_to_bytes(data))
def encode_transfer_input_data(recipient: str, value: int) -> str: input_data = hex_to_bytes(TRANSFER_METHOD) + encode_abi(["address", "uint256"], [recipient, value]) return to_hex(input_data)