feat: added telemetry and version wrappers (#11)

This commit is contained in:
Eulentier
2025-01-21 00:21:46 +01:00
committed by GitHub
parent c9b035b548
commit 89165e3868
2 changed files with 59 additions and 1 deletions

19
rpc.ts
View File

@@ -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<TelemetryRPC | { metrics: TelemetryRawRPC[] } | TelemetryAddressRPC> {
return (await this.call({
action: "telemetry",
raw: raw ? raw : undefined,
address: address ? address : undefined,
port: port ? `${port}` : undefined,
})) as Promise<TelemetryRPC | { metrics: TelemetryRawRPC[] } | TelemetryAddressRPC>;
}
/** https://docs.nano.org/commands/rpc-protocol/#version */
async get_version(): Promise<VersionRPC> {
return (await this.call({
action: "version",
})) as VersionRPC;
}
}
export class RPCWithBackup extends RPC {

View File

@@ -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;
}
//