diff --git a/src/types.ts b/src/types.ts index 6fe36a48..ff503ad9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -159,6 +159,7 @@ export interface PreparedDecodedScript { } export interface PreparedInput { + tx_id: string; value: number; token_data: number; script: string; diff --git a/src/utils.ts b/src/utils.ts index 9acc799c..4260274f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -69,10 +69,12 @@ export const recursivelyDownloadTx = async (blockId: string, txIds: string[] = [ } const txId: string = txIds.pop() as string; - const network = process.env.NETWORK || 'mainnet'; + const network: string = process.env.NETWORK || 'mainnet'; if (network in IGNORE_TXS) { - if (IGNORE_TXS[network].includes(txId)) { + const networkTxs: string[] = IGNORE_TXS[network]; + + if (networkTxs.includes(txId)) { // Skip return recursivelyDownloadTx(blockId, txIds, data); } @@ -120,6 +122,7 @@ export const prepareTx = (tx: FullTx | FullBlock): PreparedTx => { height: tx.height, inputs: tx.inputs.map((input) => { const baseInput: PreparedInput = { + tx_id: input.txId, value: input.value, token_data: input.tokenData, script: input.script, @@ -303,7 +306,9 @@ export async function* syncToLatestBlock(): AsyncGenerator { ]; // Download block transactions - const txs: FullTx[] = await recursivelyDownloadTx(block.txId, blockTxs); + let txs: FullTx[] = await recursivelyDownloadTx(block.txId, blockTxs); + + txs = txs.sort((x, y) => x.timestamp - y.timestamp); // We will send the block only after all transactions were downloaded // to be sure that all downloads were succesfull since there is no diff --git a/test/utils.ts b/test/utils.ts index 910769bb..cb1b1308 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -172,7 +172,6 @@ export const BLOCK_BY_HEIGHT: FullBlock = { timelock: null }, token: '00', - spentBy: null } ], parents: [