From c4da502fa28e202c336cd9e1df31d0da635f6ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Abadesso?= Date: Thu, 17 Jun 2021 14:14:23 -0300 Subject: [PATCH] refactor: sending transactions before blocks --- src/utils.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index a6c9e279..73c73125 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -320,24 +320,6 @@ export async function* syncToLatestBlock(): AsyncGenerator { const txs: FullTx[] = Array.from(txList.values()).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 - // ROLLBACK yet on the wallet-service. - const sendBlockResponse: ApiResponse = await sendTx(preparedBlock); - - if (!sendBlockResponse.success) { - logger.debug(sendBlockResponse); - yield { - type: 'error', - success: false, - message: `Failure on block ${preparedBlock.tx_id}`, - }; - - success = false; - - break; - } - // Exclude duplicates: const uniqueTxs: Record = txs.reduce((acc: Record, tx: FullTx) => { if (tx.txId in acc) { @@ -373,6 +355,24 @@ export async function* syncToLatestBlock(): AsyncGenerator { } } + // We will send the block only after all transactions were sent + // to be sure that all downloads were succesfull since there is no + // ROLLBACK yet on the wallet-service. + const sendBlockResponse: ApiResponse = await sendTx(preparedBlock); + + if (!sendBlockResponse.success) { + logger.debug(sendBlockResponse); + yield { + type: 'error', + success: false, + message: `Failure on block ${preparedBlock.tx_id}`, + }; + + success = false; + + break; + } + yield { type: 'block_success', success: true,