From 89165e3868a52388fa4532128aa32ef4dad5ec6a Mon Sep 17 00:00:00 2001 From: Eulentier <63156923+Eulentier161@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:21:46 +0100 Subject: [PATCH] feat: added telemetry and version wrappers (#11) --- rpc.ts | 19 ++++++++++++++++++- rpc_types.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/rpc.ts b/rpc.ts index 5ffd59e..00e362e 100644 --- a/rpc.ts +++ b/rpc.ts @@ -1,4 +1,4 @@ -import type { Address, BlockHash, BlockCountRPC, BlockInfoRPC, BlocksRPC, BlocksInfoRPC, RepresentativesRPC, RepresentativesOnlineRPC, RepresentativesOnlineWeightRPC, AccountHistoryRPC, AccountHistoryRawRPC, AccountInfoRPC, AccountBalanceRPC, AccountsBalancesRPC, AccountRepresentativeRPC, AccountsRepresentativesRPC, AccountWeightRPC, AccountReceivableRPC, AccountReceivableThresholdRPC, AccountReceivableSourceRPC, DelegatorsRPC, DelegatorsCountRPC } from "./rpc_types"; +import type { Address, BlockHash, BlockCountRPC, BlockInfoRPC, BlocksRPC, BlocksInfoRPC, RepresentativesRPC, RepresentativesOnlineRPC, RepresentativesOnlineWeightRPC, AccountHistoryRPC, AccountHistoryRawRPC, AccountInfoRPC, AccountBalanceRPC, AccountsBalancesRPC, AccountRepresentativeRPC, AccountsRepresentativesRPC, AccountWeightRPC, AccountReceivableRPC, AccountReceivableThresholdRPC, AccountReceivableSourceRPC, DelegatorsRPC, DelegatorsCountRPC, TelemetryRPC, TelemetryRawRPC, TelemetryAddressRPC, VersionRPC } from "./rpc_types"; import { whole_to_raw } from "./util"; /** Implement this interface if the built-in RPC class does not fit your needs. The easiest way to do this is by just extending the built-in RPC class */ @@ -181,6 +181,23 @@ export class RPC implements RPCInterface { account, })) as DelegatorsCountRPC; } + + /** https://docs.nano.org/commands/rpc-protocol/#telemetry */ + async get_telemetry(raw?: boolean, address?: string, port?: number): Promise { + return (await this.call({ + action: "telemetry", + raw: raw ? raw : undefined, + address: address ? address : undefined, + port: port ? `${port}` : undefined, + })) as Promise; + } + + /** https://docs.nano.org/commands/rpc-protocol/#version */ + async get_version(): Promise { + return (await this.call({ + action: "version", + })) as VersionRPC; + } } export class RPCWithBackup extends RPC { diff --git a/rpc_types.ts b/rpc_types.ts index d3e4b81..666881d 100644 --- a/rpc_types.ts +++ b/rpc_types.ts @@ -177,4 +177,45 @@ export interface DelegatorsCountRPC { count: `${number}`; } +export interface TelemetryRPC { + block_count: `${number}`; + cemented_count: `${number}`; + unchecked_count: `${number}`; + account_count: `${number}`; + bandwidth_cap: `${number}`; + peer_count: `${number}`; + protocol_version: `${number}`; + uptime: `${number}`; + genesis_block: BlockHash; + major_version: `${number}`; + minor_version: `${number}`; + patch_version: `${number}`; + pre_release_version: `${number}`; + maker: string; + timestamp: `${number}`; + active_difficulty: `${number}`; + node_id: string; + signature: string; + network_identifier: string; +} +export interface TelemetryAddressRPC extends TelemetryRPC { + signature: string; + node_id: string; +} +export interface TelemetryRawRPC extends TelemetryAddressRPC { + address: string; + port: `${number}`; +} + +export interface VersionRPC { + rpc_version: `${number}`; + store_version: `${number}`; + protocol_version: `${number}`; + node_vendor: string; + store_vendor: string; + network: string; + network_identifier: string; + build_info: string; +} + //