ChainService¶
ChainService
does most of the heavy lifting when it comes to receiving and sending transactions.
This service handles processing new transactions and computing the latest state.
getBalances¶
chain.getBalances(address)
Returns a list of balances for a user.
Parameters¶
address
-string
: Address of the user to query.
Returns¶
Promise<Object>
: An object where keys are tokens and values are the balances.
Example¶
const balances = await chain.getBalances(address)
console.log(balances)
> { '0': '1194501', '1': '919ff01' }
getExitsWithStatus¶
chain.getExitsWithStatus(address)
Returns any exits started by a specific user. Identifies exits that are finalized or ready to be finalized.
Parameters¶
address
-string
: Address of the user to query.
addExit¶
chain.addExit(exit)
Applies an exit to the local state. Internally, sends the exited range to the zero address.
pickRanges¶
chain.pickRanges(address, token, amount)
Picks the best ranges to use for a transaction.
Parameters¶
address
-string
: Address sending the transaction.token
-BigNum
: ID of the token being sent.amoun
-BigNum
: Amount of the token being sent.
Returns¶
Array<Range>
: Best ranges for the transaction.
pickTransfers¶
chain.pickTransfers(address, token, amount)
Picks the best Transfers to use for an exit. This is currently necessary because of a quirk in how we’re processing exits.
Parameters¶
address
-string
: Address sending the transaction.token
-BigNum
: ID of the token being sent.amoun
-BigNum
: Amount of the token being sent.
Returns¶
Array<Range>
: Best ranges for the transaction.
startExit¶
chain.startExit(address, token, amount)
Attempts to start an exit for a user. May submit more than one exit if neccessary to withdraw the entire amount.
Parameters¶
address
-string
: Account to withdraw from.token
-BigNum
: ID of the token to exit.amount
-BigNum
: Amount to exit.
Returns¶
Array<String>
: An array of Ethereum transaction hashes.
finalizeExits¶
chain.finalizeExits(address)
Attempts to finalize all pending exits for an account.
Parameters¶
address
-string
: Address to finalize exits for.
Returns¶
Array<String>
: An array of Etheruem transaction hashes.
sendTransaction¶
chain.sendTransaction(transaction)
Sends a transaction to the operator.
Parameters¶
transaction
-Transaction
: Transaction to be sent.
Returns¶
string
: The transaction receipt.
loadState¶
chain.loadState()
Loads the current head state as a SnapshotManager.
Returns¶
SnapshotManager
: The current head state.
saveState¶
chain.saveState(stateManager)
Saves the current head state from a SnapshotManager.
Parameters¶
stateManager
-SnapshotManager
: A SnapshotManager to save.