BlockchainTransaction#

tradeexecutor.state.blockhain_transaction.BlockchainTransaction class.

class BlockchainTransaction[source]#

Bases: object

A stateful blockchain transaction.

  • The state tracks a transaction over its life cycle

  • Transactions are part of a larger logical operation (a trade)

  • Transactions can be resolved either to success or failed

  • Transaction information is easily exported to the frontend

Transaction has (rough) four phases

  1. Preparation

  2. Signing

  3. Broadcast

  4. Confirmation

__init__(chain_id=None, from_address=None, contract_address=None, function_selector=None, args=None, tx_hash=None, nonce=None, details=None, signed_bytes=None, broadcasted_at=None, included_at=None, block_number=None, block_hash=None, status=None, realised_gas_units_consumed=None, realised_gas_price=None, revert_reason=None)#
Parameters
Return type

None

Methods

__init__([chain_id, from_address, ...])

from_dict(kvs, *[, infer_missing])

from_json(s, *[, parse_float, parse_int, ...])

get_planned_gas_price()

How much wei per gas unit we planned to spend on this transactions.

get_transaction()

Return the transaction object as it would be in web3.py.

is_success()

Transaction is success if it's succeed flag has been set.

schema(*[, infer_missing, only, exclude, ...])

set_broadcast_information(nonce, tx_hash, ...)

Update the information we are going to use to broadcast the transaction.

set_confirmation_information(ts, ...[, ...])

Update the information we are going to use to broadcast the transaction.

set_target_information(chain_id, ...)

Update the information on which transaction we are going to perform.

to_dict([encode_json])

to_json(*[, skipkeys, ensure_ascii, ...])

Attributes

args

Arguments we passed to the smart contract function

block_hash

Block has of the transaction where the executor saw the inclusion

block_number

Block number when this transaction was included in a block

broadcasted_at

When this transaction was broadcasted

chain_id

Chain id from https://github.com/ethereum-lists/chains

contract_address

Contract we called.

details

Raw Ethereum transaction dict.

from_address

TODO: Part of signed bytes.

function_selector

Function we called

included_at

Block timestamp when this tranasction was included in a block

nonce

Blockchain bookkeeping

realised_gas_price

Gas price for the tx in gwei

realised_gas_units_consumed

Gas consumed by the tx

revert_reason

The transaction revert reason if we manage to extract it

signed_bytes

Raw bytes of the signed transaction

status

status from the tx receipt.

tx_hash

Blockchain bookkeeping

chain_id: Optional[int] = None#

Chain id from https://github.com/ethereum-lists/chains

from_address: Optional[str] = None#

TODO: Part of signed bytes. Create an accessor.

contract_address: Optional[str] = None#

Contract we called. Usually the Uniswap v2 router address.

function_selector: Optional[str] = None#

Function we called

args: Optional[Tuple[Any]] = None#

Arguments we passed to the smart contract function

tx_hash: Optional[str] = None#

Blockchain bookkeeping

nonce: Optional[int] = None#

Blockchain bookkeeping

details: Optional[Dict] = None#

Raw Ethereum transaction dict. Output from web3 buildTransaction()

Example:

{‘value’: 0, ‘maxFeePerGas’: 1844540158, ‘maxPriorityFeePerGas’: 1000000000, ‘chainId’: 61, ‘from’: ‘0x6B49598B34B9c7FbF7C57306d0b0578676D55ffA’, ‘gas’: 100000, ‘to’: ‘0xF2E246BB76DF876Cef8b38ae84130F4F55De395b’, ‘data’: ‘0x095ea7b30000000000000000000000006d411e0a54382ed43f02410ce1c7a7c122afa6e1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff’, ‘nonce’: 0}

signed_bytes: Optional[str] = None#

Raw bytes of the signed transaction

broadcasted_at: Optional[datetime] = None#

When this transaction was broadcasted

included_at: Optional[datetime] = None#

Block timestamp when this tranasction was included in a block

block_number: Optional[int] = None#

Block number when this transaction was included in a block

block_hash: Optional[str] = None#

Block has of the transaction where the executor saw the inclusion

status: Optional[bool] = None#

status from the tx receipt. True is success, false is revert.

realised_gas_units_consumed: Optional[int] = None#

Gas consumed by the tx

realised_gas_price: Optional[int] = None#

Gas price for the tx in gwei

revert_reason: Optional[str] = None#

The transaction revert reason if we manage to extract it

get_transaction()[source]#

Return the transaction object as it would be in web3.py.

Needed for analyse_trade_by_receipt(). This will reconstruct TypedTransaction instance from the raw signed transaction bytes. The object will have a dict containing “data” field which we can then use for the trade analysis.

Return type

dict

is_success()[source]#

Transaction is success if it’s succeed flag has been set.

Return type

bool

set_target_information(chain_id, contract_address, function_selector, args, details)[source]#

Update the information on which transaction we are going to perform.

Parameters
  • chain_id (int) –

  • contract_address (str) –

  • function_selector (str) –

  • args (list) –

  • details (dict) –

set_broadcast_information(nonce, tx_hash, signed_bytes)[source]#

Update the information we are going to use to broadcast the transaction.

Parameters
  • nonce (int) –

  • tx_hash (str) –

  • signed_bytes (str) –

set_confirmation_information(ts, block_number, block_hash, realised_gas_units_consumed, realised_gas_price, status, revert_reason=None)[source]#

Update the information we are going to use to broadcast the transaction.

Parameters
  • ts (datetime) –

  • block_number (int) –

  • block_hash (str) –

  • realised_gas_units_consumed (int) –

  • realised_gas_price (int) –

  • status (bool) –

  • revert_reason (Optional[str]) –

get_planned_gas_price()[source]#

How much wei per gas unit we planned to spend on this transactions.

Gets maxFeePerGas for EVM transction.

Returns

0 if unknown

Return type

int

__init__(chain_id=None, from_address=None, contract_address=None, function_selector=None, args=None, tx_hash=None, nonce=None, details=None, signed_bytes=None, broadcasted_at=None, included_at=None, block_number=None, block_hash=None, status=None, realised_gas_units_consumed=None, realised_gas_price=None, revert_reason=None)#
Parameters
Return type

None