From 09953d252a816829aa1c3a1464670099826c0efb Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sat, 7 May 2022 01:23:55 +0530 Subject: [PATCH] Optimised blockchainReCheck - Check if a new block has come at start of blockchainReCheck - Checks for confirmation of txns only when a new block in the blockchain --- src/market.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/market.js b/src/market.js index b0144db..41d2cfc 100644 --- a/src/market.js +++ b/src/market.js @@ -689,6 +689,8 @@ periodicProcess.stop = function() { coupling.price.storeHistory.stop(); }; +var lastSyncBlockHeight = 0; + function blockchainReCheck() { if (blockchainReCheck.timeout !== undefined) { clearTimeout(blockchainReCheck.timeout); @@ -697,12 +699,17 @@ function blockchainReCheck() { if (!global.sinkID) return blockchainReCheck.timeout = setTimeout(blockchainReCheck, WAIT_TIME); - confirmDepositFLO(); - confirmDepositToken(); - retryWithdrawalFLO(); - retryWithdrawalToken(); - confirmWithdrawalFLO(); - confirmWithdrawalToken(); + floBlockchainAPI.promisedAPI('api/blocks?limit=1').then(result => { + if (lastSyncBlockHeight < result.blocks[0].height) { + lastSyncBlockHeight = result.blocks[0].height; + confirmDepositFLO(); + confirmDepositToken(); + retryWithdrawalFLO(); + retryWithdrawalToken(); + confirmWithdrawalFLO(); + confirmWithdrawalToken(); + } + }).catch(error => console.error(error)); } module.exports = {