@lelantos-org/sdk / internal / NoteCache
Class: NoteCache
Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:35
Destination for sync results, implemented by NoteCache.
Exposes the live NotesFile rather than a NoteStore, whose load() returns a fresh copy: syncing into a second copy would let one save overwrite the other's changes.
Implements
Constructors
Constructor
new NoteCache(store, initial): NoteCache;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:51
Parameters
| Parameter | Type |
|---|---|
store | NoteStore |
initial | NotesFile |
Returns
NoteCache
Properties
store
readonly store: NoteStore;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:36
Accessors
file
Get Signature
get file(): NotesFile;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:54
The live notes file. Read for the resume cursor; never replaced.
Returns
The live notes file. Read for the resume cursor; never replaced.
Implementation of
notes
Get Signature
get notes(): readonly StoredNote[];Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:62
Returns
readonly StoredNote[]
Methods
addHits()
addHits(hits): object;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:80
Append scan hits to the live file. Synchronous, so it cannot interleave with a queued write; persistence is deferred to checkpoint so a sync batches its store writes.
Parameters
| Parameter | Type |
|---|---|
hits | ScanHit[] |
Returns
object
added
added: StoredNote[];skipped
skipped: number;Implementation of
checkpoint()
checkpoint(cursor): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:85
Persist the current notes together with the sync resume cursor.
Parameters
| Parameter | Type |
|---|---|
cursor | number |
Returns
Promise<void>
Implementation of
compact()
compact(): Promise<{
removed: number;
}>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:73
Drop notes flagged spent: true. Returns removed count.
Returns
Promise<{ removed: number; }>
markPendingSpend()
markPendingSpend(ids): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:92
Reserve every note whose id is in ids against a spend of unknown outcome, then persist. See StoredNote.pendingSpendAt.
Parameters
| Parameter | Type |
|---|---|
ids | Iterable<string> |
Returns
Promise<void>
markSpent()
markSpent(ids): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:87
Flip spent for every note whose id is in ids, then persist.
Parameters
| Parameter | Type |
|---|---|
ids | Iterable<string> |
Returns
Promise<void>
onChange()
onChange(listener): void;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:60
Register the one listener told after a change to the note set commits: notes added, spent, reserved, released, compacted or reloaded. A cursor-only checkpoint is not a change. A throwing listener is swallowed. Replaces any previous listener.
Parameters
| Parameter | Type |
|---|---|
listener | (() => void) | undefined |
Returns
void
open()
static open(store): Promise<NoteCache>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:53
Parameters
| Parameter | Type |
|---|---|
store | NoteStore |
Returns
Promise<NoteCache>
Throws
when the store holds another notes-file schema version.
reconcile()
reconcile(rules): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:101
Apply spent-set reconciliation. spent(note) returns true when the note's nullifier is observed on-chain; release(note) returns true when its reservation should be cleared (on that observation or on expiry).
Both rules run in one pass, so a sync writes the notes file once and never leaves a spent note carrying a reservation.
Parameters
| Parameter | Type |
|---|---|
rules | { release: (note) => boolean; spent: (note) => boolean; } |
rules.release | (note) => boolean |
rules.spent | (note) => boolean |
Returns
Promise<void>
refresh()
refresh(): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:71
Replace the in-memory snapshot with the store's current state.
Needed only after external mutation of the store. syncWallet writes through this cache via NoteSink, so the snapshot is current after a sync.
Returns
Promise<void>
Throws
when the store holds another notes-file schema version.