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", diff --git a/src/bin/cli/network.js b/src/bin/cli/network.js index 3bd766b..60cd0c3 100644 --- a/src/bin/cli/network.js +++ b/src/bin/cli/network.js @@ -423,16 +423,16 @@ async function supplyInfo(options = {}) { 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], diff --git a/src/bin/helpers.js b/src/bin/helpers.js index 4fcb072..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) => console.debug(" Error:", err)); + kill(child.pid, (err) => { + if (err) console.debug(" Error:", err); + }); }; const timer = @@ -553,25 +555,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 +569,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; } diff --git a/src/lib/rpc/nodes.ts b/src/lib/rpc/nodes.ts index dac4df2..9982861 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,17 @@ 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 3ef7dfb..54f1ade 100644 --- a/src/lib/rpc/types.ts +++ b/src/lib/rpc/types.ts @@ -16,7 +16,8 @@ export enum Methods { GetPkh = "getPkh", GetPublicKey = "getPublicKey", GetSuperblock = "getSuperblock", - GetSupplyInfo = "getSupplyInfo2", + GetSupplyInfo = "getSupplyInfo", + GetSupplyInfo2 = "getSupplyInfo2", GetTransaction = "getTransaction", GetUtxoInfo = "getUtxoInfo", GetValueTransfer = "getValueTransfer", @@ -485,8 +486,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,8 +510,23 @@ 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; +}; + +// Information about the total supply provided by the `getSupplyInfo2` sensitive method +export type SupplyInfo2 = { //Current epoch epoch: u32; //Current time