From 5e3ceac8974ac540c70ef5fda45bc226d24ee065 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 18 Oct 2023 11:31:53 -0400 Subject: [PATCH] fix: dont process unit retirements when unit count is nan --- package.json | 2 +- src/api/registry.js | 30 +++++++++++++----------------- src/tasks/sync-retirements.js | 13 +++++++++++++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index faedc87..3f6cd02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "climate-tokenization-engine", - "version": "1.3.12", + "version": "1.3.13", "bin": "./src/server.js", "description": "", "main": "proxy.js", diff --git a/src/api/registry.js b/src/api/registry.js index c84dae0..f5cacdb 100644 --- a/src/api/registry.js +++ b/src/api/registry.js @@ -135,6 +135,8 @@ const retireUnit = async (unit, beneficiaryName, beneficiaryAddress) => { cleanedUnit.unitStatusReason = beneficiaryAddress; } cleanedUnit.unitStatus = "Retired"; + + logger.info(`Retiring whole unit ${unit.warehouseUnitId}`); return await updateUnit(cleanedUnit); }; @@ -593,10 +595,14 @@ const waitForRegistryDataSync = async (options = {}) => { if (onChainRegistryRoot.hash !== homeOrg.registryHash) { logger.debug( `Waiting for Registry to sync with latest registry root. - ${JSON.stringify({ - onChainRoot: onChainRegistryRoot.hash, - homeOrgRegistryRoot: homeOrg.registryHash, - }, null, 2)}` + ${JSON.stringify( + { + onChainRoot: onChainRegistryRoot.hash, + homeOrgRegistryRoot: homeOrg.registryHash, + }, + null, + 2 + )}` ); isFirstSyncAfterFailure = true; continue; @@ -703,11 +709,8 @@ const getProjectByWarehouseProjectId = async (warehouseProjectId) => { } }; -/** - * Placeholder function for deleting staging data. - */ -const deleteStagingData = async () => { - console.log("Not implemented"); +const deleteStagingData = () => { + return superagent.delete(`${registryUri}/v1/staging/clean`); }; const splitUnit = async ({ @@ -716,14 +719,7 @@ const splitUnit = async ({ beneficiaryName, beneficiaryAddress, }) => { - console.log( - "Splitting unit", - JSON.stringify({ - amount, - beneficiaryName, - beneficiaryAddress, - }) - ); + logger.info(`Splitting unit ${unit.warehouseUnitId} by ${amount}`) // Parse the serialNumberBlock const { unitBlockStart, unitBlockEnd } = utils.parseSerialNumber( diff --git a/src/tasks/sync-retirements.js b/src/tasks/sync-retirements.js index bba6688..bfad645 100644 --- a/src/tasks/sync-retirements.js +++ b/src/tasks/sync-retirements.js @@ -188,6 +188,18 @@ const processUnits = async ( break; } const { unitCount } = unit; + + if (isNaN(unitCount)) { + logger.error( + `unitCount for unit ${unit.warehouseUnitId} is not a number. Skipping this unit.` + ); + break; + } else { + logger.task( + `Retiring ${unitCount} units for ${unit.warehouseUnitId} with ${remainingAmountToRetire} remaining` + ); + } + if (unitCount <= remainingAmountToRetire) { await registry.retireUnit(unit, beneficiaryName, beneficiaryAddress); remainingAmountToRetire -= unitCount; @@ -202,6 +214,7 @@ const processUnits = async ( } await wallet.waitForAllTransactionsToConfirm(); } + return remainingAmountToRetire; };