TransactionController

TransactionController

Transaction Controller is an aggregate of sub-controllers and trackers composing them in a way to be exposed to the metamask controller
- txStateManager responsible for the state of a transaction and storing the transaction
- pendingTxTracker watching blocks for transactions to be include and emitting confirmed events
- txGasUtil gas calculations and safety buffering
- nonceTracker calculating nonces

Constructor

new TransactionController(opts)

Source:
Parameters:
Name Type Description
opts object

opts

Properties
Name Type Attributes Description
initState object

initial transaction list default is an empty array

networkStore Object

an observable store for network number

blockTracker Object

An instance of eth-blocktracker

provider Object

A network provider.

signTransaction function

function the signs an ethereumjs-tx

getGasPrice function <optional>

optional gas price calculator

signTransaction function

ethTx signer that returns a rawTx

txHistoryLimit Number <optional>

number optional for limiting how many transactions are in state

preferencesStore Object

Methods

_mapMethods()

Source:

maps methods for convenience

_markNonceDuplicatesDropped(txId)

Source:

Sets other txMeta statuses to dropped if the txMeta that has been confirmed has other transactions in the list have the same nonce

Parameters:
Name Type Description
txId Number

the txId of the transaction that has been confirmed in a block

_onBootCleanUp()

Source:

If transaction controller was rebooted with transactions that are uncompleted in steps of the transaction signing or user confirmation process it will either transition txMetas to a failed state or try to redo those tasks.

_setupListeners()

Source:

is called in constructor applies the listeners for pendingTxTracker txStateManager and blockTracker

_updateMemstore()

Source:

Updates the memStore in transaction controller

addTx()

Source:

Adds a tx to the txlist

Fires:
  • ${txMeta.event:id}:unapproved

(async) addTxGasDefaults(txMeta) → {Promise.<object>}

Source:

adds the tx gas defaults: gas && gasPrice

Parameters:
Name Type Description
txMeta Object

the txMeta object

Returns:

resolves with txMeta

Type
Promise.<object>

(async) addUnapprovedTransaction() → {txMeta}

Source:

Validates and generates a txMeta with defaults and puts it in txStateManager store

Returns:
Type
txMeta

(async) approveTransaction(txId)

Source:

sets the tx status to approved auto fills the nonce signs the transaction publishes the transaction if any of these steps fails the tx status will be set to failed

Parameters:
Name Type Description
txId number

the tx's Id

(async) cancelTransaction(txId) → {Promise.<void>}

Source:

Convenience method for the ui thats sets the transaction to rejected

Parameters:
Name Type Description
txId number

the tx's Id

Returns:
Type
Promise.<void>

(async) createCancelTransaction(originalTxId, customGasPriceopt) → {txMeta}

Source:

Creates a new approved transaction to attempt to cancel a previously submitted transaction. The new transaction contains the same nonce as the previous, is a basic ETH transfer of 0x value to the sender's address, and has a higher gasPrice than that of the previous transaction.

Parameters:
Name Type Attributes Description
originalTxId number

the id of the txMeta that you want to attempt to cancel

customGasPrice string <optional>

the hex value to use for the cancel transaction

Returns:
Type
txMeta

getChainId() → {number}

Source:
Returns:

the chainId

Type
number

getFilteredTxList()

Source:

see txStateManager

getNetwork()

Source:
Returns:

the network number stored in networkStore

getPendingTxCount(account)

Source:
Parameters:
Name Type Description
account String

hex prefixed account

Returns:

a number that represents how many transactions have the status submitted

getSelectedAddress()

Source:
Returns:

the user selected address

getState()

Source:
Returns:

the state in transaction controller

getUnapprovedTxCount()

Source:

Returns an array of transactions whos status is unapproved

(async) newUnapprovedTransaction(txParams, opts) → {Promise.<string>}

Source:

add a new unapproved transaction to the pipeline

Parameters:
Name Type Description
txParams object

txParams for the transaction

opts object

with the key origin to put the origin on the txMeta

Returns:

the hash of the transaction after being submitted to the network

Type
Promise.<string>

(async) publishTransaction(txId, rawTx) → {Promise.<void>}

Source:

publishes the raw tx and sets the txMeta to submitted

Parameters:
Name Type Description
txId number

the tx's Id

rawTx string

the hex string of the serialized signed transaction

Returns:
Type
Promise.<void>

(async) retryTransaction(originalTxId) → {txMeta}

Source:

Creates a new txMeta with the same txParams as the original to allow the user to resign the transaction with a higher gas values

Parameters:
Name Type Description
originalTxId number

the id of the txMeta that you want to attempt to retry

Returns:
Type
txMeta

setTxHash(txId, txHash)

Source:

Sets the txHas on the txMeta

Parameters:
Name Type Description
txId number

the tx's Id

txHash string

the hash for the txMeta

(async) signTransaction(txId) → {string}

Source:

adds the chain id and signs the transaction and set the status to signed

Parameters:
Name Type Description
txId number

the tx's Id

Returns:
  • rawTx
Type
string

(async) updateAndApproveTransaction(txMeta)

Source:

updates and approves the transaction

Parameters:
Name Type Description
txMeta Object

(async) updateTransaction(txMeta)

Source:

updates the txMeta in the txStateManager

Parameters:
Name Type Description
txMeta Object

the updated txMeta

wipeTransactions(address)

Source:

Wipes the transactions for a given account

Parameters:
Name Type Description
address string

hex string of the from address for txs being removed