Skip to content

Commit

Permalink
chore: bump to 1.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 14, 2023
1 parent 77dbfd6 commit c02b26d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 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.5",
"version": "1.3.6",
"bin": "./server.js",
"description": "",
"main": "proxy.js",
Expand Down
21 changes: 16 additions & 5 deletions tasks/sync-retirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function processResult({
const unit = units[i];
const { unitCount } = unit;

console.log(unitCount, remainingAmountToRetire);
console.log({unitCount, remainingAmountToRetire});

if (unitCount <= remainingAmountToRetire) {
await warehouseApi.retireUnit(
Expand Down Expand Up @@ -131,12 +131,12 @@ async function waitForCadtSync() {
});

if (!onChainRegistryRoot.confirmed) {
console.log('Waiting for Registry root to confirm');
console.log("Waiting for Registry root to confirm");
return waitForCadtSync();
}

if (onChainRegistryRoot.hash !== homeOrg.registryHash) {
console.log('Waiting for CADT to sync with latest regisry root.', {
console.log("Waiting for CADT to sync with latest regisry root.", {
onChainRoot: onChainRegistryRoot.hash,
homeOrgRegistryRoot: homeOrg.registryHash,
});
Expand Down Expand Up @@ -175,7 +175,12 @@ async function getAndProcessActivities(minHeight = 0) {
const resultsLimit = 10;

while (true) {
console.log(`${CONFIG.CLIMATE_EXPLORER_HOST}/v1/activities`);
console.log(`${CONFIG.CLIMATE_EXPLORER_HOST}/v1/activities`, {
page: page,
limit: resultsLimit,
minHeight: Number(minHeight) + 1,
sort: "asc",
});
const response = await superagent
.get(`${CONFIG.CLIMATE_EXPLORER_HOST}/v1/activities`)
.query({
Expand All @@ -192,6 +197,8 @@ async function getAndProcessActivities(minHeight = 0) {
// Assuming your API returns a JSON response
const results = response.body;

console.log(`Retrieved ${results?.activities?.length || 0} records`);

// We only want to process the retirement activities
// Also filter by height so we don't process the same activity twice
// (this was already done by the api so this is just an extra check)
Expand Down Expand Up @@ -226,7 +233,11 @@ async function getAndProcessActivities(minHeight = 0) {

page += 1;
} else {
break;
if (results?.activities?.length > 0) {
page += 1;
} else {
break;
}
}
}
} catch (error) {
Expand Down
39 changes: 21 additions & 18 deletions warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const cleanUnitBeforeUpdating = (unit) => {
Object.keys(unitToBeUpdated).forEach(function (key, index) {
if (this[key] == null) delete this[key];
}, unitToBeUpdated);

return unitToBeUpdated;
};

const retireUnit = async (unit, beneficiaryName, beneficiaryAddress) => {
Expand All @@ -44,7 +46,7 @@ const retireUnit = async (unit, beneficiaryName, beneficiaryAddress) => {

cleanedUnit.unitStatus = "Retired";

console.log("retireing unit", cleanedUnit);
console.log("Retiring Unit", cleanedUnit.warehouseUnitId);
await updateUnit(cleanedUnit);
};

Expand Down Expand Up @@ -97,27 +99,28 @@ const updateUnit = async (unitToBeUpdated) => {
console.log(
"updating unit",
`${CONFIG.CADT_API_SERVER_HOST}/v1/units`,
unitToBeUpdated
unitToBeUpdated.warehouseUnitId
);
try {
delete unitToBeUpdated?.issuance?.orgUid;
delete unitToBeUpdated.issuanceId;
delete unitToBeUpdated.orgUid;
delete unitToBeUpdated.serialNumberBlock;

const request = superagent
.put(`${CONFIG.CADT_API_SERVER_HOST}/v1/units`)
.send(unitToBeUpdated)
.set("Content-Type", "application/json");
// try {
delete unitToBeUpdated?.issuance?.orgUid;
delete unitToBeUpdated.issuanceId;
delete unitToBeUpdated.orgUid;
delete unitToBeUpdated.serialNumberBlock;
delete unitToBeUpdated?.timeStaged;

if (CONFIG.CADT_API_KEY) {
request.set("x-api-key", CONFIG.CADT_API_KEY);
}
const request = superagent
.put(`${CONFIG.CADT_API_SERVER_HOST}/v1/units`)
.send(unitToBeUpdated)
.set("Content-Type", "application/json");

await request;
} catch (error) {
throw new Error(`Warehouse unit could not be updated: ${error}`);
if (CONFIG.CADT_API_KEY) {
request.set("x-api-key", CONFIG.CADT_API_KEY);
}

await request;
// } catch (error) {
// throw new Error(`Warehouse unit could not be updated: ${error}`);
// }
};

const parseSerialNumber = (serialNumberBlock) => {
Expand Down

0 comments on commit c02b26d

Please sign in to comment.