Skip to content

@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 ​

ts
new NoteCache(store, initial): NoteCache;

Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:51

Parameters ​

ParameterType
storeNoteStore
initialNotesFile

Returns ​

NoteCache

Properties ​

store ​

ts
readonly store: NoteStore;

Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:36

Accessors ​

file ​

Get Signature ​

ts
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 ​

NotesFile

The live notes file. Read for the resume cursor; never replaced.

Implementation of ​

NoteSink.file


notes ​

Get Signature ​

ts
get notes(): readonly StoredNote[];

Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:62

Returns ​

readonly StoredNote[]

Methods ​

addHits() ​

ts
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 ​

ParameterType
hitsScanHit[]

Returns ​

object

added ​
ts
added: StoredNote[];
skipped ​
ts
skipped: number;

Implementation of ​

NoteSink.addHits


checkpoint() ​

ts
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 ​

ParameterType
cursornumber

Returns ​

Promise<void>

Implementation of ​

NoteSink.checkpoint


compact() ​

ts
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() ​

ts
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 ​

ParameterType
idsIterable<string>

Returns ​

Promise<void>


markSpent() ​

ts
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 ​

ParameterType
idsIterable<string>

Returns ​

Promise<void>


onChange() ​

ts
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 ​

ParameterType
listener(() => void) | undefined

Returns ​

void


open() ​

ts
static open(store): Promise<NoteCache>;

Defined in: @lelantos-org/sdk/dist/wallet/notes/note-cache.d.ts:53

Parameters ​

ParameterType
storeNoteStore

Returns ​

Promise<NoteCache>

Throws ​

when the store holds another notes-file schema version.


reconcile() ​

ts
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 ​

ParameterType
rules{ release: (note) => boolean; spent: (note) => boolean; }
rules.release(note) => boolean
rules.spent(note) => boolean

Returns ​

Promise<void>


refresh() ​

ts
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.