Skip to content

Commit a09d015

Browse files
authored
Implement 5 Network API Methods (Issue #24) (#33)
* Implement 5 network API methods matching node implementation New methods: - getNetworkPeers() - Get connected peers list - getNetworkStats() - Get network statistics - getGasInfo() - Get gas pricing - addNetworkPeer() - Add peer to network - removeNetworkPeer() - Remove peer from network Fixed paths to match node (network/mod.rs): - /api/v1/blockchain/network/peers - /api/v1/blockchain/network/stats - /api/v1/network/gas - /api/v1/blockchain/network/peer/add - /api/v1/blockchain/network/peer/{peer_id} Added types: NetworkPeersResponse, NetworkStatsResponse, GasInfoResponse, AddPeerRequest, AddPeerResponse, PeerInfo, MeshStatusInfo, TrafficStats, PeerDistribution Removed duplicate methods, kept legacy methods as deprecated wrappers. * Add 5 protocol API methods to network implementation Added protocol methods: - getProtocolInfo() - Protocol info with version and features - getProtocolHealth() - Health check status - getProtocolVersion() - Version and build information - getProtocolCapabilities() - Available capabilities - getProtocolStats() - Protocol statistics Paths match node (protocol/mod.rs): - /api/v1/protocol/info - /api/v1/protocol/health - /api/v1/protocol/version - /api/v1/protocol/capabilities - /api/v1/protocol/stats Added types: ProtocolInfoResponse, HealthCheckResponse, VersionResponse, CapabilitiesResponse, ProtocolStatsResponse, HealthCheck, BuildInfo, Capability Replaced old getProtocolInfo implementation with 5 new methods matching node.
1 parent 798d20a commit a09d015

File tree

8 files changed

+510
-193
lines changed

8 files changed

+510
-193
lines changed

dist/core/types.d.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,112 @@ export interface TransactionHistoryResponse {
414414
total_transactions: number;
415415
transactions: TransactionRecord[];
416416
}
417+
export interface PeerInfo {
418+
peer_id: string;
419+
peer_type: string;
420+
status: string;
421+
connection_time: number | null;
422+
}
423+
export interface NetworkPeersResponse {
424+
status: string;
425+
peer_count: number;
426+
peers: PeerInfo[];
427+
}
428+
export interface AddPeerRequest {
429+
peer_address: string;
430+
peer_type?: string;
431+
}
432+
export interface AddPeerResponse {
433+
status: string;
434+
peer_id: string;
435+
message: string;
436+
connected: boolean;
437+
}
438+
export interface MeshStatusInfo {
439+
internet_connected: boolean;
440+
mesh_connected: boolean;
441+
connectivity_percentage: number;
442+
coverage: number;
443+
stability: number;
444+
}
445+
export interface TrafficStats {
446+
bytes_sent: number;
447+
bytes_received: number;
448+
packets_sent: number;
449+
packets_received: number;
450+
connection_count: number;
451+
}
452+
export interface PeerDistribution {
453+
active_peers: number;
454+
local_peers: number;
455+
regional_peers: number;
456+
global_peers: number;
457+
relay_peers: number;
458+
}
459+
export interface NetworkStatsResponse {
460+
status: string;
461+
mesh_status: MeshStatusInfo;
462+
traffic_stats: TrafficStats;
463+
peer_distribution: PeerDistribution;
464+
}
465+
export interface GasInfoResponse {
466+
status: string;
467+
gas_price: number;
468+
estimated_cost: number;
469+
base_fee: number;
470+
priority_fee: number;
471+
}
472+
export interface ProtocolInfoResponse {
473+
status: string;
474+
protocol: string;
475+
version: string;
476+
node_id: string;
477+
uptime: number;
478+
supported_methods: string[];
479+
supported_features: string[];
480+
}
481+
export interface HealthCheck {
482+
name: string;
483+
status: string;
484+
message: string;
485+
}
486+
export interface HealthCheckResponse {
487+
status: string;
488+
healthy: boolean;
489+
uptime: number;
490+
timestamp: number;
491+
checks: HealthCheck[];
492+
}
493+
export interface BuildInfo {
494+
commit: string;
495+
build_date: string;
496+
rust_version: string;
497+
}
498+
export interface VersionResponse {
499+
status: string;
500+
server_version: string;
501+
protocol_version: string;
502+
api_version: string;
503+
build_info: BuildInfo;
504+
}
505+
export interface Capability {
506+
name: string;
507+
version: string;
508+
description: string;
509+
enabled: boolean;
510+
}
511+
export interface CapabilitiesResponse {
512+
status: string;
513+
capabilities: Capability[];
514+
extensions: string[];
515+
}
516+
export interface ProtocolStatsResponse {
517+
status: string;
518+
requests_handled: number;
519+
active_connections: number;
520+
total_bytes_sent: number;
521+
total_bytes_received: number;
522+
average_response_time: number;
523+
error_rate: number;
524+
}
417525
//# sourceMappingURL=types.d.ts.map

dist/core/types.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core/zhtp-api-methods.d.ts

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* All API method implementations for various operations
44
*/
55
import { ZhtpApiCore } from './zhtp-api-core';
6-
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, GasInfo, SignupRequest, LoginRequest, BackupData, BackupVerification, BackupStatus, ImportBackupResponse, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult, ProofData, GenerateProofRequest, VerifyProofResponse, WalletListResponse, WalletBalanceResponse, SimpleSendRequest, CrossWalletTransferRequest, TransactionHistoryResponse } from './types';
6+
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, SignupRequest, LoginRequest, BackupData, BackupVerification, BackupStatus, ImportBackupResponse, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult, ProofData, GenerateProofRequest, VerifyProofResponse, WalletListResponse, WalletBalanceResponse, SimpleSendRequest, CrossWalletTransferRequest, TransactionHistoryResponse, NetworkPeersResponse, NetworkStatsResponse, GasInfoResponse, AddPeerRequest, AddPeerResponse, ProtocolInfoResponse, HealthCheckResponse, VersionResponse, CapabilitiesResponse, ProtocolStatsResponse } from './types';
77
export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
88
signIn(did: string, passphrase: string): Promise<Identity>;
99
createIdentity(data: any): Promise<Identity>;
@@ -116,6 +116,36 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
116116
token: string;
117117
identity: Identity;
118118
}>;
119+
/**
120+
* Get list of connected network peers
121+
* @returns Peer information including peer IDs, types, and connection status
122+
*/
123+
getNetworkPeers(): Promise<NetworkPeersResponse>;
124+
/**
125+
* Get comprehensive network statistics including mesh status and traffic
126+
* @returns Network stats with mesh status, traffic, and peer distribution
127+
*/
128+
getNetworkStats(): Promise<NetworkStatsResponse>;
129+
/**
130+
* Get current gas pricing information for transaction cost estimation
131+
* @returns Gas prices including base fee, priority fee, and estimated costs
132+
*/
133+
getGasInfo(): Promise<GasInfoResponse>;
134+
/**
135+
* Add a peer to the network by address
136+
* @param request - Peer address and optional peer type
137+
* @returns Connection result with peer ID and status
138+
*/
139+
addNetworkPeer(request: AddPeerRequest): Promise<AddPeerResponse>;
140+
/**
141+
* Remove a peer from the network
142+
* @param peerId - ID of the peer to remove
143+
* @returns Removal result with status
144+
*/
145+
removeNetworkPeer(peerId: string): Promise<any>;
146+
/**
147+
* @deprecated Use getNetworkPeers() instead
148+
*/
119149
getNetworkInfo(): Promise<NetworkStatus>;
120150
/**
121151
* List all wallets for an identity
@@ -223,18 +253,14 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
223253
*/
224254
getContractFromDht(contractId: string): Promise<SmartContract>;
225255
getBlockchainInfo(): Promise<any>;
226-
getGasInfo(): Promise<GasInfo>;
227256
getNodeStatus(): Promise<NodeStatus>;
257+
/**
258+
* @deprecated Use getNetworkPeers() instead
259+
*/
228260
getMeshPeers(): Promise<{
229261
peers: string[];
230262
count: number;
231263
}>;
232-
getNetworkStats(): Promise<{
233-
blockchain: Record<string, any>;
234-
gas: Record<string, any>;
235-
mesh: Record<string, any>;
236-
timestamp: string;
237-
}>;
238264
deployContract(contractData: SmartContract, options?: Record<string, any>): Promise<ContractDeploymentResult>;
239265
executeContract(contractId: string, functionName: string, args?: any[]): Promise<ContractExecutionResult>;
240266
queryContract(contractId: string, functionName?: string, args?: any[]): Promise<Record<string, any>>;
@@ -278,45 +304,30 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
278304
*/
279305
verifyZkProof(proof: ProofData): Promise<VerifyProofResponse>;
280306
testConnection(): Promise<boolean>;
281-
getProtocolInfo(): Promise<{
282-
success: boolean;
283-
protocol: string;
284-
version: any;
285-
features: {
286-
quantum_resistant: any;
287-
zk_privacy_enabled: any;
288-
mesh_networking: any;
289-
dao_fees_enabled: any;
290-
pure_tcp: boolean;
291-
};
292-
network: {
293-
id: any;
294-
consensus: any;
295-
block_height: any;
296-
peer_count: any;
297-
healthy: any;
298-
};
299-
node: {
300-
status: any;
301-
uptime: any;
302-
latency: any;
303-
synced: any;
304-
};
305-
error?: undefined;
306-
} | {
307-
success: boolean;
308-
error: string;
309-
protocol: string;
310-
features: {
311-
quantum_resistant: boolean;
312-
zk_privacy_enabled: boolean;
313-
mesh_networking: boolean;
314-
dao_fees_enabled: boolean;
315-
pure_tcp: boolean;
316-
};
317-
version?: undefined;
318-
network?: undefined;
319-
node?: undefined;
320-
}>;
307+
/**
308+
* Get protocol information including version, node ID, and supported features
309+
* @returns Protocol information with capabilities and uptime
310+
*/
311+
getProtocolInfo(): Promise<ProtocolInfoResponse>;
312+
/**
313+
* Get health check status for the node
314+
* @returns Health status with checks for server, handlers, and memory
315+
*/
316+
getProtocolHealth(): Promise<HealthCheckResponse>;
317+
/**
318+
* Get version information for server, protocol, and API
319+
* @returns Version details including build information
320+
*/
321+
getProtocolVersion(): Promise<VersionResponse>;
322+
/**
323+
* Get list of protocol capabilities and extensions
324+
* @returns Available capabilities with enabled status and descriptions
325+
*/
326+
getProtocolCapabilities(): Promise<CapabilitiesResponse>;
327+
/**
328+
* Get protocol statistics including request counts and bandwidth
329+
* @returns Protocol metrics with request handling and performance stats
330+
*/
331+
getProtocolStats(): Promise<ProtocolStatsResponse>;
321332
}
322333
//# sourceMappingURL=zhtp-api-methods.d.ts.map

0 commit comments

Comments
 (0)