mirror of
https://github.com/stjet/banani.git
synced 2025-12-29 09:39:23 +00:00
feat: added telemetry and version wrappers (#11)
This commit is contained in:
19
rpc.ts
19
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<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 {
|
||||
|
||||
41
rpc_types.ts
41
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;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user