From fc61296c849605d45b6cd272ac53f835eeae48ed Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Mon, 15 Apr 2024 18:26:38 -0700 Subject: [PATCH] Added reorg flag to RuneUpdater/RuneBlockIndex (#44) --- package.json | 2 +- src/indexer/index.ts | 3 ++- src/indexer/types.ts | 1 + src/indexer/updater.ts | 1 + test/updater.test.ts | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 59d1b70..4018f31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@magiceden-oss/runestone-lib", - "version": "0.7.1-alpha", + "version": "0.7.2-alpha", "description": "", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/indexer/index.ts b/src/indexer/index.ts index 283ff25..2e5a700 100644 --- a/src/indexer/index.ts +++ b/src/indexer/index.ts @@ -183,8 +183,9 @@ export class RunestoneIndexer { throw blockResult.error; } const block = blockResult.result; + const reorg = currentStorageBlock ? currentStorageBlock.height >= block.height : false; - const runeUpdater = new RuneUpdater(this._network, block, this._storage, this._rpc); + const runeUpdater = new RuneUpdater(this._network, block, reorg, this._storage, this._rpc); for (const [txIndex, tx] of block.tx.entries()) { await runeUpdater.indexRunes(tx, txIndex); diff --git a/src/indexer/types.ts b/src/indexer/types.ts index c1b97e5..cc5c5f9 100644 --- a/src/indexer/types.ts +++ b/src/indexer/types.ts @@ -148,6 +148,7 @@ export type RuneEtching = ({ valid: false } | ({ valid: true } & RuneEtchingBase export type RuneBlockIndex = { block: BlockInfo; + reorg: boolean; etchings: RuneEtching[]; mintCounts: RuneMintCount[]; utxoBalances: RuneUtxoBalance[]; diff --git a/src/indexer/updater.ts b/src/indexer/updater.ts index 214829e..83397f8 100644 --- a/src/indexer/updater.ts +++ b/src/indexer/updater.ts @@ -50,6 +50,7 @@ export class RuneUpdater implements RuneBlockIndex { constructor( network: Network, block: BlockInfo, + readonly reorg: boolean, private readonly _storage: RunestoneStorage, private readonly _rpc: BitcoinRpcClient ) { diff --git a/test/updater.test.ts b/test/updater.test.ts index 2272a95..6dc9718 100644 --- a/test/updater.test.ts +++ b/test/updater.test.ts @@ -23,7 +23,7 @@ function getDefaultRuneUpdaterContext() { const rpc = mock(); - const runeUpdater = new RuneUpdater(Network.MAINNET, block, storage, rpc); + const runeUpdater = new RuneUpdater(Network.MAINNET, block, false, storage, rpc); return { runeUpdater, block, storage, rpc }; }