From 3be15166eaf56b69d9e9095a6bedcb4cdac13c10 Mon Sep 17 00:00:00 2001 From: Eulentier161 Date: Sun, 7 Apr 2024 23:55:02 +0200 Subject: [PATCH 1/2] added telemetry --- src/client/nano-client.ts | 21 +++++++++++++++++++++ src/types/rpc-response.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/client/nano-client.ts b/src/client/nano-client.ts index a0b2873..20c3712 100644 --- a/src/client/nano-client.ts +++ b/src/client/nano-client.ts @@ -486,6 +486,27 @@ export class NanoClient { }); } + /** + * Return metrics from other nodes on the network. By default, + * returns a summarized view of the whole network.\ + * Networking - node telemetry contains more detailed information on the protocol implementation of telemetry. + * * @param {body} TelemetryBody - https://docs.nano.org/commands/rpc-protocol/#telemetry + */ + telemetry< + T extends + | { raw: boolean; address?: never; port?: never } + | { address: string; port: number; raw?: never } + | never + >( + body?: T + ): T extends { address: string; port: number } + ? Promise + : T extends { raw: true } + ? Promise + : Promise { + return this._send('telemetry', body) as any; + } + /** * Check whether account is a valid account number using checksum. * @param {string} account - The NANO account address. diff --git a/src/types/rpc-response.ts b/src/types/rpc-response.ts index 910e73b..ac2257a 100644 --- a/src/types/rpc-response.ts +++ b/src/types/rpc-response.ts @@ -242,3 +242,36 @@ export type WorkGenerateResponse = { multiplier: string; hash: string; }; + +export type TelemetryResponse = { + block_count: string; + cemented_count: string; + unchecked_count: string; + account_count: string; + bandwidth_cap: string; + peer_count: string; + protocol_version: string; + uptime: string; + genesis_block: string; + major_version: string; + minor_version: string; + patch_version: string; + pre_release_version: string; + maker: string; + timestamp: string; + active_difficulty: string; +}; + +export type TelemetryRawResponse = { + metrics: (TelemetryResponse & { + signature: string; + node_id: string; + address: string; + port: string; + })[]; +}; + +export type TelemetryAddressPortResponse = TelemetryResponse & { + node_id: string; + signature: string; +}; From 7e134f68fdede07e08c289bcc818aed097c8d37c Mon Sep 17 00:00:00 2001 From: Eulentier161 Date: Wed, 10 Apr 2024 16:11:14 +0200 Subject: [PATCH 2/2] arguably better declaration --- src/client/nano-client.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/client/nano-client.ts b/src/client/nano-client.ts index 20c3712..ce31713 100644 --- a/src/client/nano-client.ts +++ b/src/client/nano-client.ts @@ -492,19 +492,13 @@ export class NanoClient { * Networking - node telemetry contains more detailed information on the protocol implementation of telemetry. * * @param {body} TelemetryBody - https://docs.nano.org/commands/rpc-protocol/#telemetry */ - telemetry< - T extends - | { raw: boolean; address?: never; port?: never } - | { address: string; port: number; raw?: never } - | never - >( - body?: T - ): T extends { address: string; port: number } - ? Promise - : T extends { raw: true } - ? Promise - : Promise { - return this._send('telemetry', body) as any; + telemetry(body?: { raw: false }): Promise; + telemetry(body: { raw: true }): Promise; + telemetry(body: { address: string; port: number; raw?: boolean }): Promise; + telemetry( + body? + ): Promise { + return this._send('telemetry', body ?? {}) as any; } /**