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 {