diff --git a/src/common/utxobased/engine/UtxoEngine.ts b/src/common/utxobased/engine/UtxoEngine.ts index 2140382e..b68f8400 100644 --- a/src/common/utxobased/engine/UtxoEngine.ts +++ b/src/common/utxobased/engine/UtxoEngine.ts @@ -128,8 +128,15 @@ export async function makeUtxoEngine( // private keys. let nonceDataLayer: DataLayer | undefined - // This cached value allows the engine to resync using the same checkpoint as - // what the core gave the plugin when the core started plugin. + /** + * This is a stateful function, which means it is both a setter and a getter. + * The state is the cached seenTxCheckpoint for the engine during runtime. + * It is initialized with the seenTxCheckpoint state from the core via + * `EdgeCurrencyEngineOptions`. + * It is updated by the engine's processor as the wallet syncs. + * Once the wallet fully syncs, the seenTxCheckpoint value is emitted to the + * `onSeenTxCheckpoint` callback so the core can persist this state to disk. + */ const seenTxCheckpoint = ((state?: string) => ( value?: string ): string | undefined => { @@ -137,6 +144,9 @@ export async function makeUtxoEngine( return state })() + // Initialize the seenTxCheckpoint with the value from the core. + seenTxCheckpoint(config.engineOptions.seenTxCheckpoint) + emitter.on(EngineEvent.SEEN_TX_CHECKPOINT, checkpoint => { seenTxCheckpoint(checkpoint) }) @@ -364,9 +374,7 @@ export async function makeUtxoEngine( } }, - async startEngine(opts): Promise { - seenTxCheckpoint(opts?.seenTxCheckpoint) - + async startEngine(): Promise { emitter.emit( EngineEvent.WALLET_BALANCE_CHANGED, currencyInfo.currencyCode, @@ -739,7 +747,7 @@ export async function makeUtxoEngine( await pluginState.refreshServers() // Restart the engine - await engine.startEngine({ seenTxCheckpoint: seenTxCheckpoint() }) + await engine.startEngine() }, async saveTx(edgeTx: EdgeTransaction): Promise { diff --git a/src/common/utxobased/engine/UtxoEngineProcessor.ts b/src/common/utxobased/engine/UtxoEngineProcessor.ts index 7b5c1cd6..804d0f03 100644 --- a/src/common/utxobased/engine/UtxoEngineProcessor.ts +++ b/src/common/utxobased/engine/UtxoEngineProcessor.ts @@ -646,7 +646,7 @@ interface TaskCache { readonly blockbookUtxoCache: BlockbookUtxoCache readonly dataLayerUtxoCache: DataLayerUtxoCache readonly transactionSpecificUpdateCache: TransactionSpecificUpdateCache - readonly transactionUpdateCache: transactionUpdateCache + readonly transactionUpdateCache: TransactionUpdateCache } interface AddressForTransactionsCache { @@ -683,7 +683,7 @@ interface BlockbookUtxoCache { interface TransactionSpecificUpdateCache { [key: string]: { processing: boolean } } -interface transactionUpdateCache { +interface TransactionUpdateCache { [key: string]: { processing: boolean } } diff --git a/test/common/utxobased/engine/engine.spec.ts b/test/common/utxobased/engine/engine.spec.ts index e8a094c4..f10d0f19 100644 --- a/test/common/utxobased/engine/engine.spec.ts +++ b/test/common/utxobased/engine/engine.spec.ts @@ -340,7 +340,7 @@ describe('engine.spec', function () { done() // Can be "done" since the promise resolves before the event fires but just be on the safe side } }) - engine.startEngine({ seenTxCheckpoint: '' }).catch(e => { + engine.startEngine().catch(e => { fakeLogger.info('startEngine error', e, e.message) }) }