diff --git a/package-lock.json b/package-lock.json index 3c05336d..09502ccb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "hathor-wallet-service-sync_daemon", - "version": "1.3.2-alpha", + "version": "1.4.0-alpha", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 67a7cc67..2d07e294 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.3.2-alpha", + "version": "1.4.0-alpha", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/types.ts b/src/types.ts index f847d0f1..150981d8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -296,6 +296,7 @@ export interface Meta { height: number; validation?: string; first_block?: string | null; + first_block_height?: number | null; } export interface RawTxResponse { diff --git a/src/utils.ts b/src/utils.ts index 1c8daa7d..268d3430 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -136,11 +136,17 @@ export const recursivelyDownloadTx = async ( // Transaction was already confirmed by a different block if (meta.first_block && meta.first_block !== blockId) { - const firstBlockResponse = await downloadTx(meta.first_block); + let firstBlockHeight = meta.first_block_height; + + // This should never happen + // Using == to include `undefined` on this check + if (firstBlockHeight == null) { + throw new Error('Transaction was confirmed by a block but we were unable to detect its height'); + } // If the transaction was confirmed by an older block, ignore it as it was // already sent to the wallet-service - if (firstBlockResponse.tx.height < blockHeight) { + if (firstBlockHeight < blockHeight) { return recursivelyDownloadTx(blockId, blockHeight, txIds, data); } }