Skip to content

Commit

Permalink
fix: dont process unit retirements when unit count is nan
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Oct 18, 2023
1 parent 5d14895 commit 5e3ceac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "climate-tokenization-engine",
"version": "1.3.12",
"version": "1.3.13",
"bin": "./src/server.js",
"description": "",
"main": "proxy.js",
Expand Down
30 changes: 13 additions & 17 deletions src/api/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ({
Expand All @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions src/tasks/sync-retirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -202,6 +214,7 @@ const processUnits = async (
}
await wallet.waitForAllTransactionsToConfirm();
}

return remainingAmountToRetire;
};

Expand Down

0 comments on commit 5e3ceac

Please sign in to comment.