Account State
Low-level routines to interact with the a local Merkle tree
Sync the Local State
To update the account balance local state should be periodically synced with the relayer. Most routines (which are state dependent) have an associated parameter for updating state, but you may want to force update the account state (e.g. using a timer) to reduce sync delays and get balance updates in time.
Returns
Promise
returns boolean indicating whether your local state has pending outgoing transactions
You cannot send a new transaction while there is an outgoing one from your account queued by the relayer but not yet mined.
Example
Check Transaction Sending Ability
You cannot send a new transaction while there is an outgoing one from your account queued by the relayer but not yet mined. Use the following function to check whether you can send a new transaction.
The routine is currently identical to updateState()
but other conditions can be introduced here in the future
Invoking this function causes a local state update
Returns
Promise
returns boolean indicating whether you can send a new transaction
Example
Wait for Transaction Sending Ability
When the isReadyToTransact()
method returns false you can wait for the appropriate conditions to send a new transaction using the following method:
The routine attempts to update the local state periodically within a limited time interval (about 5 minutes). When all of attempts are exhausted the method returns false.
Returns
Promise
returns boolean indicating whether you can send a new transaction
Example
Get the Local State
Get the local Merkle tree index and root at the desired index
Parameters
index
- the index for which the root should be retrieved (use the latest index if undefined, should be multiple of 128)
Returns
Promise
returns TreeState
Example
Clean the Local State
Remove all local Merkle tree nodes. After the state is cleared a full sync must be performed for the state to be ready.
Example
Rollback the Local State
Use the following method in to remove all state data after the desired index
Parameters
index
- the index after which the state should be cleared (should be multiple of 128)
Returns
Promise
returns new local Merkle tree index
In some cases the new Merkle tree index may not match the desired rollback index (e.g. in the case of a partial tree)
Example
Last updated