WalletRuntime
A wallet following a chain (the devnet, or a network through its indexer): shielded and DUST state kept in step with the chain, with checkpoints so a transaction that does not land can be rolled back and the blocks since replayed. Used by the solvers, the treasury and the demo wallet.
Properties
Section titled “Properties”client
Section titled “client”
readonlyclient:ChainClient
networkId
Section titled “networkId”
readonlynetworkId:string
params
Section titled “params”
readonlyparams:LedgerParameters
shielded
Section titled “shielded”
readonlyshielded:ShieldedWallet
readonlydust:DustWallet
cursor
Section titled “cursor”cursor:
number
lastBlock?
Section titled “lastBlock?”
optionallastBlock?:ChainBlock
lastError?
Section titled “lastError?”
optionallastError?:Error
The last sync failure (a chain that does not answer, or a diverged state).
Methods
Section titled “Methods”save()
Section titled “save()”save():
void
Writes the state now (atomically; readable by this user only). Called as blocks are applied and on stop.
Returns
Section titled “Returns”void
onBlock()
Section titled “onBlock()”onBlock(
fn): () =>void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fn |
(b) => void |
Returns
Section titled “Returns”() => void
sync()
Section titled “sync()”sync(
waitMs?):Promise<number>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
waitMs? |
number |
Returns
Section titled “Returns”Promise<number>
start()
Section titled “start()”start(
intervalMs?):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
intervalMs? |
number |
Returns
Section titled “Returns”void
stop()
Section titled “stop()”stop():
void
Returns
Section titled “Returns”void
exclusive()
Section titled “exclusive()”exclusive<
T>(fn):Promise<T>
Runs fn with sync paused; fn may build transactions against a stable state.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fn |
() => T | Promise<T> |
Returns
Section titled “Returns”Promise<T>
checkpoint()
Section titled “checkpoint()”checkpoint():
Checkpoint
Returns
Section titled “Returns”Checkpoint
rollback()
Section titled “rollback()”rollback(
cp):Promise<void>
Restores a checkpoint and replays every block since it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cp |
Checkpoint |
Returns
Section titled “Returns”Promise<void>
waitForHeight()
Section titled “waitForHeight()”waitForHeight(
height,timeoutMs?):Promise<void>
Blocks until the chain is past height and this wallet has applied it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
height |
number |
timeoutMs? |
number |
Returns
Section titled “Returns”Promise<void>
chainHeight()
Section titled “chainHeight()”chainHeight():
Promise<number>
Returns
Section titled “Returns”Promise<number>
isRegistered()
Section titled “isRegistered()”isRegistered(
u):boolean
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
u |
NightUtxo |
Returns
Section titled “Returns”boolean
nightUtxos()
Section titled “nightUtxos()”nightUtxos():
Promise<NightUtxo[]>
This wallet's NIGHT, each with whether it generates DUST for it.
Returns
Section titled “Returns”Promise<NightUtxo[]>
unshieldedUtxos()
Section titled “unshieldedUtxos()”unshieldedUtxos(
token?):Promise<NightUtxo[]>
This wallet's unshielded outputs of token, or of every token (NIGHT among them).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
token? |
string |
Returns
Section titled “Returns”Promise<NightUtxo[]>
dustTime()
Section titled “dustTime()”dustTime(
fallback?):Date
The time a DUST spend declares: the last block this wallet applied, in whole seconds
(fallback, the wall clock, before any). A node checks the spend against its DUST
trees as they were at that time, and this wallet's trees are those after that block;
a later time fails (InvalidDustSpendProof) once anyone's DUST changes in between, and
on a network the indexer serves only finalized blocks, some behind the node. Times
back to the ledger's grace period (3 h on Preprod) are accepted.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fallback? |
Date |
Returns
Section titled “Returns”Date
ensureDust()
Section titled “ensureDust()”ensureDust(
nightAmount?,opts?):Promise<void>
DUST for fees: NIGHT registered for DUST generation, if the wallet has no DUST. On the
devnet the NIGHT comes from the faucet and is claimed; on a network it must already be
there (the tNIGHT faucet), and the registration is proven by seal (bytes as the chain
takes them).
Only the largest unregistered UTXO is registered. A registration re-outputs its inputs as one UTXO, so registering all of a wallet's would undo a maker's lots; and under ledger 9's costs a registration of two inputs already takes the node longer to check than its size allows (17.9 ms in 644 bytes against Preprod's 15 ms: FeeCalculation, 231). A wallet whose registrations a fork cleared has several, its lots among them.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
nightAmount? |
bigint |
opts? |
{ seal?: (tx) => Promise<Uint8Array<ArrayBufferLike>>; } |
opts.seal? |
(tx) => Promise<Uint8Array<ArrayBufferLike>> |
Returns
Section titled “Returns”Promise<void>