TransactionStateManager

TransactionStateManager

TransactionStateManager is responsible for the state of a transaction and storing the transaction it also has some convenience methods for finding subsets of transactions

STATUS METHODS
statuses:
- 'unapproved' the user has not responded
- 'rejected' the user has responded no!
- 'approved' the user has approved the tx
- 'signed' the tx is signed
- 'submitted' the tx is sent to a server
- 'confirmed' the tx has been included in a block.
- 'failed' the tx failed for some reason, included on tx data.
- 'dropped' the tx nonce was already used

Constructor

new TransactionStateManager(opts)

Source:
Parameters:
Name Type Description
opts object
Properties
Name Type Attributes Default Description
initState object <optional>
{ transactions: [] }

initial transactions list with the key transaction {array}

txHistoryLimit number <optional>

limit for how many finished transactions can hang around in state

getNetwork function

return network number

Methods

_saveTxList(transactions)

Source:

Saves the new/updated txList.

Parameters:
Name Type Description
transactions array

the list of transactions to save

_setTxStatus(txId, status)

Source:
Parameters:
Name Type Description
txId number

the txMeta Id

status string

the status to set on the txMeta

Fires:
  • tx:status-update - passes txId and status
  • ${txMeta.id}:finished - if it is a finished state.event: Passes the txMeta
  • update:badge

addTx(txMeta) → {object}

Source:

Adds the txMeta to the list of transactions in the store. if the list is over txHistoryLimit it will remove a transaction that is in its final state it will allso add the key history to the txMeta with the snap shot of the original object

Parameters:
Name Type Description
txMeta Object
Returns:

the txMeta

Type
object

generateTxMeta(opts) → {txMeta}

Source:
Parameters:
Name Type Description
opts object

the object to use when overwriting defaults

Returns:

the default txMeta object

Type
txMeta

getConfirmedTransactions(addressopt) → {array}

Source:
Parameters:
Name Type Attributes Description
address string <optional>

hex prefixed address to sort the txMetas for [optional]

Returns:

the tx list whos status is confirmed if no address is provide returns all txMetas who's status is confirmed for the current network

Type
array

getFullTxList() → {array}

Source:
Returns:

of all the txMetas in store

Type
array

getPendingTransactions(addressopt) → {array}

Source:
Parameters:
Name Type Attributes Description
address string <optional>

hex prefixed address to sort the txMetas for [optional]

Returns:

the tx list whos status is submitted if no address is provide returns all txMetas who's status is submitted for the current network

Type
array

getTx(txId) → {object}

Source:
Parameters:
Name Type Description
txId number
Returns:

the txMeta who matches the given id if none found for the network returns undefined

Type
object

getTxList() → {array}

Source:
Returns:

of txMetas that have been filtered for only the current network

Type
array

getTxsByMetaData(key, value, txListopt) → {array}

Source:
Parameters:
Name Type Attributes Default Description
key string

the key to check

value

the value your looking for

txList array <optional>
this.getTxList()

the list to search. default is the txList from txStateManager#getTxList

Returns:

a list of txMetas who matches the search params

Type
array

getTxStatus(txId) → {string}

Source:
Parameters:
Name Type Description
txId number

the txMeta Id

Returns:

the status of the tx.

Type
string

getUnapprovedTxList() → {array}

Source:
Returns:

the tx list whos status is unapproved

Type
array

setTxStatusApproved(txId)

Source:

should update the status of the tx to 'approved'.

Parameters:
Name Type Description
txId number

the txMeta Id

setTxStatusConfirmed(txId)

Source:

should update the status of the tx to 'confirmed'.

Parameters:
Name Type Description
txId number

the txMeta Id

setTxStatusDropped(txId)

Source:

should update the status of the tx to 'dropped'.

Parameters:
Name Type Description
txId number

the txMeta Id

setTxStatusFailed(txId, err)

Source:

should update the status of the tx to 'failed'. and put the error on the txMeta

Parameters:
Name Type Description
txId number

the txMeta Id

err erroObject

error object

setTxStatusRejected(txId)

Source:

should update the status of the tx to 'rejected'.

Parameters:
Name Type Description
txId number

the txMeta Id

setTxStatusSigned(txId)

Source:

should update the status of the tx to 'signed'.

Parameters:
Name Type Description
txId number

the txMeta Id

setTxStatusSubmitted(txId)

Source:

should update the status of the tx to 'submitted'. and add a time stamp for when it was called

Parameters:
Name Type Description
txId number

the txMeta Id

setTxStatusUnapproved(txId)

Source:

should update the status of the tx to 'unapproved'.

Parameters:
Name Type Description
txId number

the txMeta Id

updateTx(txMeta, noteopt)

Source:

updates the txMeta in the list and adds a history entry

Parameters:
Name Type Attributes Description
txMeta Object

the txMeta to update

note string <optional>

a note about the update for history

updateTxParams(txId, txParams)

Source:

merges txParams obj onto txMeta.txParams use extend to ensure that all fields are filled

Parameters:
Name Type Description
txId number

the id of the txMeta

txParams object

the updated txParams

validateTxParams(txParams)

Source:

validates txParams members by type

Parameters:
Name Type Description
txParams object

txParams to validate

wipeTransactions(address)

Source:

Removes transaction from the given address for the current network from the txList

Parameters:
Name Type Description
address string

hex string of the from address on the txParams to remove