Skip to content

Commit

Permalink
refactor: sending transactions before blocks (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso authored Jun 17, 2021
1 parent 8be7bb1 commit 333ad21
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,6 @@ export async function* syncToLatestBlock(): AsyncGenerator<StatusEvent> {

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<string, FullTx> = txs.reduce((acc: Record<string, FullTx>, tx: FullTx) => {
if (tx.txId in acc) {
Expand Down Expand Up @@ -373,6 +355,24 @@ export async function* syncToLatestBlock(): AsyncGenerator<StatusEvent> {
}
}

// 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,
Expand Down

0 comments on commit 333ad21

Please sign in to comment.