From d308b0bd78816a17cae88f5ea7cd3331dfac6c7d Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 17 Oct 2023 14:07:37 -0400 Subject: [PATCH 1/4] refactor: formatting --- src/api/registry.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/api/registry.js b/src/api/registry.js index 9085d10..b9e6669 100644 --- a/src/api/registry.js +++ b/src/api/registry.js @@ -555,26 +555,38 @@ const waitForRegistryDataSync = async (options = {}) => { const homeOrg = await getHomeOrg(); if (!homeOrg) { - logger.warn("Cannot find the home org from the Registry. Please verify your Registry is running and you have created a Home Organization."); + logger.warn( + "Cannot find the home org from the Registry. Please verify your Registry is running and you have created a Home Organization." + ); continue; } - const onChainRegistryRoot = await datalayer.getRoot({ id: homeOrg.registryId }); + const onChainRegistryRoot = await datalayer.getRoot({ + id: homeOrg.registryId, + }); if (!onChainRegistryRoot.confirmed) { console.log("Waiting for Registry root to confirm"); continue; } - if (onChainRegistryRoot.hash === constants.emptySingletonHash && opts.throwOnEmptyRegistry) { - throw new Error("Registry is empty. Please add some data to run auto retirement task."); + if ( + onChainRegistryRoot.hash === constants.emptySingletonHash && + opts.throwOnEmptyRegistry + ) { + throw new Error( + "Registry is empty. Please add some data to run auto retirement task." + ); } if (onChainRegistryRoot.hash !== homeOrg.registryHash) { - console.log("Waiting for Registry to sync with latest registry root.", { - onChainRoot: onChainRegistryRoot.hash, - homeOrgRegistryRoot: homeOrg.registryHash, - }); + console.log( + "Waiting for Registry to sync with latest registry root.", + { + onChainRoot: onChainRegistryRoot.hash, + homeOrgRegistryRoot: homeOrg.registryHash, + } + ); continue; } @@ -586,10 +598,13 @@ const waitForRegistryDataSync = async (options = {}) => { } if (onChainOrgRoot.hash !== homeOrg.orgHash) { - console.log("Waiting for Registry to sync with latest organization root.", { - onChainRoot: onChainOrgRoot.hash, - homeOrgRoot: homeOrg.orgHash, - }); + console.log( + "Waiting for Registry to sync with latest organization root.", + { + onChainRoot: onChainOrgRoot.hash, + homeOrgRoot: homeOrg.orgHash, + } + ); continue; } From b52b906a3b079f8b5f95e4212d6f75d0e2be213b Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 17 Oct 2023 18:45:33 -0400 Subject: [PATCH 2/4] feat: logging for zach --- src/api/registry.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/api/registry.js b/src/api/registry.js index 9deaf09..c84dae0 100644 --- a/src/api/registry.js +++ b/src/api/registry.js @@ -538,6 +538,8 @@ const getOrgMetaData = async (orgUid) => { const waitForRegistryDataSync = async (options = {}) => { await mutex.waitForUnlock(); + let isFirstSyncAfterFailure = false; + if (!mutex.isLocked()) { const releaseMutex = await mutex.acquire(); try { @@ -565,6 +567,7 @@ const waitForRegistryDataSync = async (options = {}) => { logger.warn( "Cannot find the home org from the Registry. Please verify your Registry is running and you have created a Home Organization." ); + isFirstSyncAfterFailure = true; continue; } @@ -573,7 +576,8 @@ const waitForRegistryDataSync = async (options = {}) => { }); if (!onChainRegistryRoot.confirmed) { - console.log("Waiting for Registry root to confirm"); + logger.debug("Waiting for Registry root to confirm"); + isFirstSyncAfterFailure = true; continue; } @@ -587,34 +591,45 @@ const waitForRegistryDataSync = async (options = {}) => { } if (onChainRegistryRoot.hash !== homeOrg.registryHash) { - console.log( - "Waiting for Registry to sync with latest registry root.", - { + logger.debug( + `Waiting for Registry to sync with latest registry root. + ${JSON.stringify({ onChainRoot: onChainRegistryRoot.hash, homeOrgRegistryRoot: homeOrg.registryHash, - } + }, null, 2)}` ); + isFirstSyncAfterFailure = true; continue; } const onChainOrgRoot = await datalayer.getRoot({ id: homeOrg.orgUid }); if (!onChainOrgRoot.confirmed) { - console.log("Waiting for Organization root to confirm"); + logger.debug("Waiting for Organization root to confirm"); continue; } if (onChainOrgRoot.hash !== homeOrg.orgHash) { - console.log( - "Waiting for Registry to sync with latest organization root.", - { - onChainRoot: onChainOrgRoot.hash, - homeOrgRoot: homeOrg.orgHash, - } + logger.debug( + `Waiting for Registry to sync with latest organization root. , + ${JSON.stringify( + { + onChainRoot: onChainOrgRoot.hash, + homeOrgRoot: homeOrg.orgHash, + }, + null, + 2 + )}` ); + isFirstSyncAfterFailure = true; continue; } + // Log the message if conditions are met for the first time after failure + if (isFirstSyncAfterFailure) { + logger.info("CADT is SYNCED! Proceeding with the task."); + } + // Exit the loop if all conditions are met break; } From 5d14895e1d44423b0be7806434da46f0f716aa52 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 18 Oct 2023 09:42:02 -0400 Subject: [PATCH 3/4] chore: update npm packages --- package-lock.json | 180 +++++++++++++++++++++++----------------------- package.json | 2 +- 2 files changed, 90 insertions(+), 92 deletions(-) diff --git a/package-lock.json b/package-lock.json index b8ef86e..3b40af1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "climate-tokenization-engine", - "version": "1.3.11", + "version": "1.3.12", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "climate-tokenization-engine", - "version": "1.3.11", + "version": "1.3.12", "license": "Apache-2.0", "dependencies": { "@chia-carbon/core-registry-config": "^1.0.2", @@ -23,7 +23,7 @@ "joi": "^17.9.2", "js-yaml": "^4.1.0", "lodash": "^4.17.21", - "superagent": "^8.0.9", + "superagent": "^8.1.2", "supertest": "^6.3.3", "toad-scheduler": "^3.0.0", "unzipper": "^0.10.14", @@ -142,18 +142,18 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.22.20.tgz", - "integrity": "sha512-BQYjKbpXjoXwFW5jGqiizJQQT/aC7pFm9Ok1OWssonuguICi264lbgMzRp2ZMmRSlfkX6DsWDDcsrctK8Rwfiw==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.23.2.tgz", + "integrity": "sha512-0S9TQMmDHlqAZ2ITT95irXKfxN9bncq8ZCoJhun3nHL/lLUxd2NKBJYoNGWH7S0hz6fRQwWlAWn/ILM0C70KZQ==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.0.tgz", - "integrity": "sha512-97z/ju/Jy1rZmDxybphrBuI+jtJjFVoz7Mr9yUQVVVi+DNZE333uFQeMOqcCIy1x3WYBIbWftUSLmbNXNT7qFQ==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.2.tgz", + "integrity": "sha512-n7s51eWdaWZ3vGT2tD4T7J6eJs3QoBXydv7vkUM06Bf1cbVD2Kc2UrkzhiQwobfV7NwOnQXYL7UBJ5VPU+RGoQ==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", @@ -161,10 +161,10 @@ "@babel/generator": "^7.23.0", "@babel/helper-compilation-targets": "^7.22.15", "@babel/helper-module-transforms": "^7.23.0", - "@babel/helpers": "^7.23.0", + "@babel/helpers": "^7.23.2", "@babel/parser": "^7.23.0", "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.0", + "@babel/traverse": "^7.23.2", "@babel/types": "^7.23.0", "convert-source-map": "^2.0.0", "debug": "^4.1.0", @@ -366,13 +366,13 @@ } }, "node_modules/@babel/helpers": { - "version": "7.23.1", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.1.tgz", - "integrity": "sha512-chNpneuK18yW5Oxsr+t553UZzzAs3aZnFm4bxhebsNTeshrC95yA7l5yl7GBAG+JG1rF0F7zzD2EixK9mWSDoA==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.2.tgz", + "integrity": "sha512-lzchcp8SjTSVe/fPmLwtWVBFC7+Tbn8LGHDVfDp9JGxpAY5opSaEFgt8UQvrnECWOTdji2mOWMz1rOhkHscmGQ==", "dev": true, "dependencies": { "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.0", + "@babel/traverse": "^7.23.2", "@babel/types": "^7.23.0" }, "engines": { @@ -653,9 +653,9 @@ } }, "node_modules/@babel/traverse": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz", - "integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", + "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", "dev": true, "dependencies": { "@babel/code-frame": "^7.22.13", @@ -1093,9 +1093,9 @@ "dev": true }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.19", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", - "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", + "version": "0.3.20", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz", + "integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==", "dev": true, "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", @@ -1200,9 +1200,9 @@ } }, "node_modules/@types/babel__core": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.2.tgz", - "integrity": "sha512-pNpr1T1xLUc2l3xJKuPtsEky3ybxN3m4fJkknfIpTCTfIZCDW57oAg+EfCgIIp2rvCe0Wn++/FfodDS4YXxBwA==", + "version": "7.20.3", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.3.tgz", + "integrity": "sha512-54fjTSeSHwfan8AyHWrKbfBWiEUrNTZsUwPTDSNaaP1QDQIZbeNUg3a59E9D+375MzUw/x1vx2/0F5LBz+AeYA==", "dev": true, "dependencies": { "@babel/parser": "^7.20.7", @@ -1213,18 +1213,18 @@ } }, "node_modules/@types/babel__generator": { - "version": "7.6.5", - "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.5.tgz", - "integrity": "sha512-h9yIuWbJKdOPLJTbmSpPzkF67e659PbQDba7ifWm5BJ8xTv+sDmS7rFmywkWOvXedGTivCdeGSIIX8WLcRTz8w==", + "version": "7.6.6", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.6.tgz", + "integrity": "sha512-66BXMKb/sUWbMdBNdMvajU7i/44RkrA3z/Yt1c7R5xejt8qh84iU54yUWCtm0QwGJlDcf/gg4zd/x4mpLAlb/w==", "dev": true, "dependencies": { "@babel/types": "^7.0.0" } }, "node_modules/@types/babel__template": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.2.tgz", - "integrity": "sha512-/AVzPICMhMOMYoSx9MoKpGDKdBRsIXMNByh1PXSZoa+v6ZoLa8xxtsT/uLQ/NJm0XVAWl/BvId4MlDeXJaeIZQ==", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.3.tgz", + "integrity": "sha512-ciwyCLeuRfxboZ4isgdNZi/tkt06m8Tw6uGbBSBgWrnnZGNXiEyM27xc/PjXGQLqlZ6ylbgHMnm7ccF9tCkOeQ==", "dev": true, "dependencies": { "@babel/parser": "^7.1.0", @@ -1232,59 +1232,59 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.2.tgz", - "integrity": "sha512-ojlGK1Hsfce93J0+kn3H5R73elidKUaZonirN33GSmgTUMpzI/MIFfSpF3haANe3G1bEBS9/9/QEqwTzwqFsKw==", + "version": "7.20.3", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.3.tgz", + "integrity": "sha512-Lsh766rGEFbaxMIDH7Qa+Yha8cMVI3qAK6CHt3OR0YfxOIn5Z54iHiyDRycHrBqeIiqGa20Kpsv1cavfBKkRSw==", "dev": true, "dependencies": { "@babel/types": "^7.20.7" } }, "node_modules/@types/graceful-fs": { - "version": "4.1.7", - "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.7.tgz", - "integrity": "sha512-MhzcwU8aUygZroVwL2jeYk6JisJrPl/oov/gsgGCue9mkgl9wjGbzReYQClxiUgFDnib9FuHqTndccKeZKxTRw==", + "version": "4.1.8", + "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.8.tgz", + "integrity": "sha512-NhRH7YzWq8WiNKVavKPBmtLYZHxNY19Hh+az28O/phfp68CF45pMFud+ZzJ8ewnxnC5smIdF3dqFeiSUQ5I+pw==", "dev": true, "dependencies": { "@types/node": "*" } }, "node_modules/@types/http-proxy": { - "version": "1.17.12", - "resolved": "https://registry.npmjs.org/@types/http-proxy/-/http-proxy-1.17.12.tgz", - "integrity": "sha512-kQtujO08dVtQ2wXAuSFfk9ASy3sug4+ogFR8Kd8UgP8PEuc1/G/8yjYRmp//PcDNJEUKOza/MrQu15bouEUCiw==", + "version": "1.17.13", + "resolved": "https://registry.npmjs.org/@types/http-proxy/-/http-proxy-1.17.13.tgz", + "integrity": "sha512-GkhdWcMNiR5QSQRYnJ+/oXzu0+7JJEPC8vkWXK351BkhjraZF+1W13CUYARUvX9+NqIU2n6YHA4iwywsc/M6Sw==", "dependencies": { "@types/node": "*" } }, "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", + "integrity": "sha512-zONci81DZYCZjiLe0r6equvZut0b+dBRPBN5kBDjsONnutYNtJMoWQ9uR2RkL1gLG9NMTzvf+29e5RFfPbeKhQ==", "dev": true }, "node_modules/@types/istanbul-lib-report": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", - "integrity": "sha512-gPQuzaPR5h/djlAv2apEG1HVOyj1IUs7GpfMZixU0/0KXT3pm64ylHuMUI1/Akh+sq/iikxg6Z2j+fcMDXaaTQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.2.tgz", + "integrity": "sha512-8toY6FgdltSdONav1XtUHl4LN1yTmLza+EuDazb/fEmRNCwjyqNVIQWs2IfC74IqjHkREs/nQ2FWq5kZU9IC0w==", "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "*" } }, "node_modules/@types/istanbul-reports": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.2.tgz", - "integrity": "sha512-kv43F9eb3Lhj+lr/Hn6OcLCs/sSM8bt+fIaP11rCYngfV6NVjzWXJ17owQtDQTL9tQ8WSLUrGsSJ6rJz0F1w1A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.3.tgz", + "integrity": "sha512-1nESsePMBlf0RPRffLZi5ujYh7IH1BWL4y9pr+Bn3cJBdxz+RTP8bUFljLz9HvzhhOSWKdyBZ4DIivdL6rvgZg==", "dev": true, "dependencies": { "@types/istanbul-lib-report": "*" } }, "node_modules/@types/node": { - "version": "20.8.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.4.tgz", - "integrity": "sha512-ZVPnqU58giiCjSxjVUESDtdPk4QR5WQhhINbc9UBrKLU68MX5BF6kbQzTrkwbolyr0X8ChBpXfavr5mZFKZQ5A==", + "version": "20.8.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.7.tgz", + "integrity": "sha512-21TKHHh3eUHIi2MloeptJWALuCu5H7HQTdTrWIFReA8ad+aggoX+lRes3ex7/FtpC+sVUpFMQ+QTfYr74mruiQ==", "dependencies": { "undici-types": "~5.25.1" } @@ -1870,9 +1870,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001547", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001547.tgz", - "integrity": "sha512-W7CrtIModMAxobGhz8iXmDfuJiiKg1WADMO/9x7/CLNin5cpSbuBjooyoIUVB5eyCc36QuTVlkVa1iB2S5+/eA==", + "version": "1.0.30001550", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001550.tgz", + "integrity": "sha512-p82WjBYIypO0ukTsd/FG3Xxs+4tFeaY9pfT4amQL8KWtYH7H9nYwReGAbMTJ0hsmRO8IfDtsS6p3ZWj8+1c2RQ==", "dev": true, "funding": [ { @@ -2494,9 +2494,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.548", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.548.tgz", - "integrity": "sha512-R77KD6mXv37DOyKLN/eW1rGS61N6yHOfapNSX9w+y9DdPG83l9Gkuv7qkCFZ4Ta4JPhrjgQfYbv4Y3TnM1Hi2Q==", + "version": "1.4.557", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.557.tgz", + "integrity": "sha512-6x0zsxyMXpnMJnHrondrD3SuAeKcwij9S+83j2qHAQPXbGTDDfgImzzwgGlzrIcXbHQ42tkG4qA6U860cImNhw==", "dev": true }, "node_modules/emittery": { @@ -3049,9 +3049,12 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/gensync": { "version": "1.0.0-beta.2", @@ -4534,24 +4537,19 @@ "dev": true }, "node_modules/logform": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.5.1.tgz", - "integrity": "sha512-9FyqAm9o9NKKfiAKfZoYo9bGXXuwMkxQiQttkT4YjjVtQVIQtK6LmVtlxmCaFswo6N4AfEkHqZTV0taDtPotNg==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.0.tgz", + "integrity": "sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==", "dependencies": { - "@colors/colors": "1.5.0", + "@colors/colors": "1.6.0", "@types/triple-beam": "^1.3.2", "fecha": "^4.2.0", "ms": "^2.1.1", "safe-stable-stringify": "^2.3.1", "triple-beam": "^1.3.0" - } - }, - "node_modules/logform/node_modules/@colors/colors": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", - "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + }, "engines": { - "node": ">=0.1.90" + "node": ">= 12.0.0" } }, "node_modules/logform/node_modules/ms": { @@ -4560,12 +4558,12 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "node_modules/loupe": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", - "integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", + "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", "dev": true, "dependencies": { - "get-func-name": "^2.0.0" + "get-func-name": "^2.0.1" } }, "node_modules/lru-cache": { @@ -4946,9 +4944,9 @@ } }, "node_modules/nock": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.3.3.tgz", - "integrity": "sha512-z+KUlILy9SK/RjpeXDiDUEAq4T94ADPHE3qaRkf66mpEhzc/ytOMm3Bwdrbq6k1tMWkbdujiKim3G2tfQARuJw==", + "version": "13.3.4", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.3.4.tgz", + "integrity": "sha512-DDpmn5oLEdCTclEqweOT4U7bEpuoifBMFUXem9sA4turDAZ5tlbrEoWqCorwXey8CaAw44mst5JOQeVNiwtkhw==", "dev": true, "dependencies": { "debug": "^4.1.0", @@ -4984,9 +4982,9 @@ "dev": true }, "node_modules/node-abi": { - "version": "3.48.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.48.0.tgz", - "integrity": "sha512-uWR/uwQyVV2iN5+Wkf1/oQxOR9YjU7gBclJLg2qK7GDvVohcnY6LaBXKV89N79EQFyN4/e43O32yQYE5QdFYTA==", + "version": "3.51.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.51.0.tgz", + "integrity": "sha512-SQkEP4hmNWjlniS5zdnfIXTk1x7Ome85RDzHlTbBtzE97Gfwz/Ipw4v/Ryk20DWIy3yCNVLVlGKApCnmvYoJbA==", "dev": true, "dependencies": { "semver": "^7.3.5" @@ -5127,9 +5125,9 @@ } }, "node_modules/object-inspect": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.0.tgz", + "integrity": "sha512-HQ4J+ic8hKrgIt3mqk6cVOVrW2ozL4KdvHlqpBv9vDYWx9ysAgENAdvy4FoGF+KFdhR7nQTNm5J0ctAeOwn+3g==", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -5741,9 +5739,9 @@ "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" }, "node_modules/resolve": { - "version": "1.22.6", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.6.tgz", - "integrity": "sha512-njhxM7mV12JfufShqGy3Rz8j11RPdLy4xi15UurGJeoHLfJpVXKdh3ueuOqbYUcDZnffr6X739JBo5LzyahEsw==", + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", "dev": true, "dependencies": { "is-core-module": "^2.13.0", @@ -6884,16 +6882,16 @@ } }, "node_modules/winston-transport": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.5.0.tgz", - "integrity": "sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==", + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.6.0.tgz", + "integrity": "sha512-wbBA9PbPAHxKiygo7ub7BYRiKxms0tpfU2ljtWzb3SjRjv5yl6Ozuy/TkXf00HTAt+Uylo3gSkNwzc4ME0wiIg==", "dependencies": { "logform": "^2.3.2", "readable-stream": "^3.6.0", "triple-beam": "^1.3.0" }, "engines": { - "node": ">= 6.4.0" + "node": ">= 12.0.0" } }, "node_modules/winston-transport/node_modules/readable-stream": { diff --git a/package.json b/package.json index a64cc7a..faedc87 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "joi": "^17.9.2", "js-yaml": "^4.1.0", "lodash": "^4.17.21", - "superagent": "^8.0.9", + "superagent": "^8.1.2", "supertest": "^6.3.3", "toad-scheduler": "^3.0.0", "unzipper": "^0.10.14", From 5e3ceac8974ac540c70ef5fda45bc226d24ee065 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 18 Oct 2023 11:31:53 -0400 Subject: [PATCH 4/4] 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; };