Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/bin/cli/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
19 changes: 3 additions & 16 deletions src/bin/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
});

Expand All @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions src/lib/rpc/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type PeerAddr,
type StakeAuthorization,
type StakeEntry,
type SupplyInfo2,
type SyncStatus,
} from "./types.js";

Expand All @@ -29,6 +30,7 @@ export interface IJsonRpcNodeFarm extends IJsonRpcProvider {
clearPeers(): Promise<Record<string, boolean>>;
initializePeers(): Promise<Record<string, boolean>>;
rewind(epoch: Epoch): Promise<Record<string, boolean>>;
supplyInfo2(): Promise<SupplyInfo2 | undefined>;
}

function isPrivateURL(url: string): boolean {
Expand Down Expand Up @@ -323,4 +325,17 @@ export class JsonRpcNodeFarm extends JsonRpcProvider implements IJsonRpcNodeFarm
public async rewind(epoch: Epoch): Promise<Record<string, boolean>> {
return this.batchApiMethod<boolean>(Methods.Rewind, [epoch]);
}

/// Get supply info
public async supplyInfo2(): Promise<SupplyInfo2 | undefined> {
return this.addresses().then(async (addresses: Record<string, Error | string>) => {
return Promise.all(
Object.entries(addresses).map(async ([url]) => {
return this.callApiMethod<SupplyInfo2>(url, Methods.GetSupplyInfo2);
}),
).then((supplies: Array<SupplyInfo2>) => {
return supplies.find((result) => !(result instanceof Error));
});
});
}
}
24 changes: 20 additions & 4 deletions src/lib/rpc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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: {
Expand All @@ -509,8 +510,23 @@ export type SuperblockReport = {
consolidated_block_hashes: Array<Hash>;
};

// 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
Expand Down