def dict_to_spoof_transaction( chain: AsyncChain, header: BlockHeader, transaction_dict: Dict[str, Any]) -> SpoofTransaction: """ Convert dicts used in calls & gas estimates into a spoof transaction """ txn_dict = normalize_transaction_dict(transaction_dict) sender = txn_dict.get('from', ZERO_ADDRESS) if 'nonce' in txn_dict: nonce = txn_dict['nonce'] else: vm = chain.get_vm(header) nonce = vm.state.account_db.get_nonce(sender) gas_price = txn_dict.get('gasPrice', 0) gas = txn_dict.get('gas', header.gas_limit) unsigned = chain.get_vm_class(header).create_unsigned_transaction( nonce=nonce, gas_price=gas_price, gas=gas, to=txn_dict['to'], value=txn_dict['value'], data=txn_dict['data'], ) return SpoofTransaction(unsigned, from_=sender)
def receive_transaction_to_dict(transaction: BaseReceiveTransaction, chain: AsyncChain) -> Dict[str, str]: tx_hash = transaction.hash dict_to_return = all_rlp_fields_to_dict_camel_case(transaction) dict_to_return['isReceive'] = to_hex(True) dict_to_return['hash'] = encode_hex(tx_hash) from_address = chain.get_block_header_by_hash( transaction.sender_block_hash).chain_address dict_to_return['from'] = to_hex(from_address) originating_transaction = chain.chaindb.get_transaction_by_hash( transaction.send_transaction_hash, send_tx_class=chain.get_vm().get_transaction_class(), receive_tx_class=chain.get_vm().get_receive_transaction_class()) if transaction.is_refund: value = originating_transaction.remaining_refund else: value = originating_transaction.value dict_to_return['value'] = to_hex(value) dict_to_return['gasPrice'] = to_hex(originating_transaction.gas_price) dict_to_return['to'] = to_hex(originating_transaction.to) try: dict_to_return['gasUsed'] = to_hex( chain.chaindb.get_transaction_receipt(transaction.hash).gas_used) except TransactionNotFound: dict_to_return['gasUsed'] = to_hex(0) try: block_hash, receive_tx_index, _ = chain.chaindb.get_transaction_index( tx_hash) num_send_transactions = chain.chaindb.get_number_of_send_tx_in_block( block_hash) block_tx_index = num_send_transactions + receive_tx_index dict_to_return['transactionIndex'] = to_hex(block_tx_index) dict_to_return['blockHash'] = to_hex(block_hash) except TransactionNotFound: pass return dict_to_return
async def account_db_at_block(chain: AsyncChain, at_block: Union[str, int], read_only: bool = True) -> BaseAccountDB: at_header = await get_header(chain, at_block) vm = chain.get_vm(at_header) return vm.state.account_db