From 173388e4472df960248dc65f3076a4a5ec0cf16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 30 Dec 2025 09:13:16 +0100 Subject: [PATCH 1/6] chore(rpc): adapt JsonRpcProvider.supplyInfo to non-sensitive getSupplyInfo --- src/lib/rpc/types.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/lib/rpc/types.ts b/src/lib/rpc/types.ts index 3ef7dfb..88894a4 100644 --- a/src/lib/rpc/types.ts +++ b/src/lib/rpc/types.ts @@ -16,7 +16,7 @@ export enum Methods { GetPkh = "getPkh", GetPublicKey = "getPublicKey", GetSuperblock = "getSuperblock", - GetSupplyInfo = "getSupplyInfo2", + GetSupplyInfo = "getSupplyInfo", GetTransaction = "getTransaction", GetUtxoInfo = "getUtxoInfo", GetValueTransfer = "getValueTransfer", @@ -485,8 +485,8 @@ export type StakingPower = { }; // Superblock consolidating metadata -//As per current consensus algorithm, "consolidated blocks" implies that there exists at least one -//superblock in the chain that builds upon the superblock where those blocks were anchored. +// As per current consensus algorithm, "consolidated blocks" implies that there exists at least one +// superblock in the chain that builds upon the superblock where those blocks were anchored. export type SuperblockReport = { //The superblock that we are signaling as consolidated. superblock: { @@ -509,9 +509,21 @@ export type SuperblockReport = { consolidated_block_hashes: Array; }; -// Information about the total supply export type SupplyInfo = { //Current epoch + epoch: u32, + //Current time + current_time: u64, + //Number of blocks minted + blocks_minted: u32, + //WIT minted through block creation + blocks_minted_reward: u64, + //Current staked supply + current_staked_supply: u64, + //Genesis supply + genesis_supply: u64, +} + //Current epoch epoch: u32; //Current time current_time: u64; From 484174bfa52fea4b9da88194a18fea1bd28430a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 30 Dec 2025 09:14:02 +0100 Subject: [PATCH 2/6] feat(rpc): JsonRpcNodeFarm.supplyInfo2 --- src/lib/rpc/nodes.ts | 16 ++++++++++++++++ src/lib/rpc/types.ts | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/lib/rpc/nodes.ts b/src/lib/rpc/nodes.ts index dac4df2..8adc59f 100644 --- a/src/lib/rpc/nodes.ts +++ b/src/lib/rpc/nodes.ts @@ -10,6 +10,7 @@ import { type PeerAddr, type StakeAuthorization, type StakeEntry, + type SupplyInfo2, type SyncStatus, } from "./types.js"; @@ -29,6 +30,7 @@ export interface IJsonRpcNodeFarm extends IJsonRpcProvider { clearPeers(): Promise>; initializePeers(): Promise>; rewind(epoch: Epoch): Promise>; + supplyInfo2(): Promise; } function isPrivateURL(url: string): boolean { @@ -323,4 +325,18 @@ export class JsonRpcNodeFarm extends JsonRpcProvider implements IJsonRpcNodeFarm public async rewind(epoch: Epoch): Promise> { return this.batchApiMethod(Methods.Rewind, [epoch]); } + + /// Get supply info + public async supplyInfo2(): Promise { + return this.addresses() + .then(async (addresses: Record) => { + return Promise.all( + Object.entries(addresses).map(async ([url,]) => { + return this.callApiMethod(url, Methods.GetSupplyInfo2) + }) + ).then((supplies: Array) => { + return supplies.find(result => !(result instanceof Error)) + }) + }) + } } diff --git a/src/lib/rpc/types.ts b/src/lib/rpc/types.ts index 88894a4..77656f7 100644 --- a/src/lib/rpc/types.ts +++ b/src/lib/rpc/types.ts @@ -17,6 +17,7 @@ export enum Methods { GetPublicKey = "getPublicKey", GetSuperblock = "getSuperblock", GetSupplyInfo = "getSupplyInfo", + GetSupplyInfo2 = "getSupplyInfo2", GetTransaction = "getTransaction", GetUtxoInfo = "getUtxoInfo", GetValueTransfer = "getValueTransfer", @@ -523,6 +524,9 @@ export type SupplyInfo = { //Genesis supply genesis_supply: u64, } + +// Information about the total supply provided by the `getSupplyInfo2` sensitive method +export type SupplyInfo2 = { //Current epoch epoch: u32; //Current time From 14cbb14c31285f6472104afdf1a23c321ef06df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 30 Dec 2025 09:17:54 +0100 Subject: [PATCH 3/6] chore(bin): polish runtime logs in dry runs --- src/bin/helpers.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/bin/helpers.js b/src/bin/helpers.js index 4fcb072..03630f5 100644 --- a/src/bin/helpers.js +++ b/src/bin/helpers.js @@ -141,7 +141,7 @@ export function cmd(timeout, ...commands) { console.debug("=> Killing process tree with PID:", child.pid); console.debug(" Command:", `${bin} ${args.join(" ")}`); if (!child.pid) return; - kill(child.pid, (err) => console.debug(" Error:", err)); + kill(child.pid, (err) => { if (err) console.debug(" Error:", err) }); }; const timer = @@ -553,25 +553,12 @@ export async function toolkitRun(settings, args) { let stderr = ""; let finished = false; - // const killTree = () => { - // if (!child.pid) return; - // try { - // if (process.platform === "win32") { - // spawn("taskkill", ["/PID", child.pid.toString(), "/T", "/F"]); - // } else { - // // kill entire process group - // process.kill(child.pid, "SIGKILL"); - // } - // } catch {} - // }; - child.stdout.on("data", (d) => (stdout += d.toString())); child.stderr.on("data", (d) => (stderr += d.toString())); child.on("error", (err) => { if (finished) return; finished = true; - // killTree(); reject(err); }); @@ -580,13 +567,11 @@ export async function toolkitRun(settings, args) { finished = true; if (signal) { - // killTree(); reject(new Error(`witnet_toolkit binary terminated by signal ${signal}`)); return; } if (code !== 0) { - // killTree(); reject(new Error(`witnet_toolkit binary failed with exit code ${code}\n${stderr}`)); return; } From d41afde478e7925e27704785af0ff97a39a3170e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 30 Dec 2025 09:33:52 +0100 Subject: [PATCH 4/6] chore(cli): adapt to new non-sensitive getSupplyInfo method --- src/bin/cli/network.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/bin/cli/network.js b/src/bin/cli/network.js index 3bd766b..9af0f7d 100644 --- a/src/bin/cli/network.js +++ b/src/bin/cli/network.js @@ -419,20 +419,19 @@ async function stakes(options = {}) { async function supplyInfo(options = {}) { const reporter = new Witnet.JsonRpcProvider(options?.provider || process.env.WITNET_SDK_PROVIDER_URL); const data = await reporter.supplyInfo(); - console.info(`> Supply info at epoch ${helpers.colors.white(helpers.commas(data.epoch))}:`); + console.info(`> Supply info at epoch ${ + helpers.colors.white(helpers.commas(data.epoch)) + }:`); const records = []; records.push(["Minted blocks", `${helpers.toFixedTrunc((100 * data.blocks_minted) / (data.epoch - 1), 1)} %`]); records.push(["Minted rewards", helpers.whole_wits(data.blocks_minted_reward, 2)]); - if (data.burnt_supply) { - records.push(["Burnt supply", helpers.whole_wits(data.burnt_supply, 2)]); - } - if (data.current_locked_supply) { - records.push(["Locked supply", helpers.whole_wits(data.current_locked_supply, 2)]); - } if (data.current_staked_supply) { records.push(["Staked supply", helpers.whole_wits(data.current_staked_supply, 2)]); } - records.push(["Circulating supply", helpers.whole_wits(data.current_unlocked_supply, 2)]); + records.push(["Circulating supply", helpers.whole_wits( + BigInt(data.genesis_supply) + BigInt(data.blocks_minted_reward) - BigInt(data.current_staked_supply), + 2 + )]); helpers.traceTable(records, { headlines: [":KPI", "VALUE"], colors: [helpers.colors.mgreen, helpers.colors.myellow], From 46f93b64c0d16fc586ed46a0c9fd86d21b2c48a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 30 Dec 2025 09:35:01 +0100 Subject: [PATCH 5/6] chore: this is 3.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba98fce..cba2597 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@witnet/sdk", - "version": "3.1.8", + "version": "3.2.0", "description": "Typescript library and CLI tooling for Web3 buidlers willing to interact with the Witnet blockchain.", "repository": { "type": "git", From f2a07f5dc1c79f84342d099b202dfda9d82c1ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 30 Dec 2025 10:16:10 +0100 Subject: [PATCH 6/6] chore: fmt! --- src/bin/cli/network.js | 15 ++++++++------- src/bin/helpers.js | 4 +++- src/lib/rpc/nodes.ts | 19 +++++++++---------- src/lib/rpc/types.ts | 24 ++++++++++++------------ 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/bin/cli/network.js b/src/bin/cli/network.js index 9af0f7d..60cd0c3 100644 --- a/src/bin/cli/network.js +++ b/src/bin/cli/network.js @@ -419,19 +419,20 @@ async function stakes(options = {}) { async function supplyInfo(options = {}) { const reporter = new Witnet.JsonRpcProvider(options?.provider || process.env.WITNET_SDK_PROVIDER_URL); const data = await reporter.supplyInfo(); - console.info(`> Supply info at epoch ${ - helpers.colors.white(helpers.commas(data.epoch)) - }:`); + console.info(`> Supply info at epoch ${helpers.colors.white(helpers.commas(data.epoch))}:`); const records = []; records.push(["Minted blocks", `${helpers.toFixedTrunc((100 * data.blocks_minted) / (data.epoch - 1), 1)} %`]); records.push(["Minted rewards", helpers.whole_wits(data.blocks_minted_reward, 2)]); if (data.current_staked_supply) { records.push(["Staked supply", helpers.whole_wits(data.current_staked_supply, 2)]); } - records.push(["Circulating supply", helpers.whole_wits( - BigInt(data.genesis_supply) + BigInt(data.blocks_minted_reward) - BigInt(data.current_staked_supply), - 2 - )]); + records.push([ + "Circulating supply", + helpers.whole_wits( + BigInt(data.genesis_supply) + BigInt(data.blocks_minted_reward) - BigInt(data.current_staked_supply), + 2, + ), + ]); helpers.traceTable(records, { headlines: [":KPI", "VALUE"], colors: [helpers.colors.mgreen, helpers.colors.myellow], diff --git a/src/bin/helpers.js b/src/bin/helpers.js index 03630f5..d723e08 100644 --- a/src/bin/helpers.js +++ b/src/bin/helpers.js @@ -141,7 +141,9 @@ export function cmd(timeout, ...commands) { console.debug("=> Killing process tree with PID:", child.pid); console.debug(" Command:", `${bin} ${args.join(" ")}`); if (!child.pid) return; - kill(child.pid, (err) => { if (err) console.debug(" Error:", err) }); + kill(child.pid, (err) => { + if (err) console.debug(" Error:", err); + }); }; const timer = diff --git a/src/lib/rpc/nodes.ts b/src/lib/rpc/nodes.ts index 8adc59f..9982861 100644 --- a/src/lib/rpc/nodes.ts +++ b/src/lib/rpc/nodes.ts @@ -328,15 +328,14 @@ export class JsonRpcNodeFarm extends JsonRpcProvider implements IJsonRpcNodeFarm /// Get supply info public async supplyInfo2(): Promise { - return this.addresses() - .then(async (addresses: Record) => { - return Promise.all( - Object.entries(addresses).map(async ([url,]) => { - return this.callApiMethod(url, Methods.GetSupplyInfo2) - }) - ).then((supplies: Array) => { - return supplies.find(result => !(result instanceof Error)) - }) - }) + return this.addresses().then(async (addresses: Record) => { + return Promise.all( + Object.entries(addresses).map(async ([url]) => { + return this.callApiMethod(url, Methods.GetSupplyInfo2); + }), + ).then((supplies: Array) => { + return supplies.find((result) => !(result instanceof Error)); + }); + }); } } diff --git a/src/lib/rpc/types.ts b/src/lib/rpc/types.ts index 77656f7..54f1ade 100644 --- a/src/lib/rpc/types.ts +++ b/src/lib/rpc/types.ts @@ -512,18 +512,18 @@ export type SuperblockReport = { export type SupplyInfo = { //Current epoch - epoch: u32, - //Current time - current_time: u64, - //Number of blocks minted - blocks_minted: u32, - //WIT minted through block creation - blocks_minted_reward: u64, - //Current staked supply - current_staked_supply: u64, - //Genesis supply - genesis_supply: u64, -} + epoch: u32; + //Current time + current_time: u64; + //Number of blocks minted + blocks_minted: u32; + //WIT minted through block creation + blocks_minted_reward: u64; + //Current staked supply + current_staked_supply: u64; + //Genesis supply + genesis_supply: u64; +}; // Information about the total supply provided by the `getSupplyInfo2` sensitive method export type SupplyInfo2 = {