Skip to content

Commit

Permalink
refactor: returning connected peers (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
freemanzMrojo authored Nov 8, 2024
1 parent 1eb1915 commit 6bee05f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/templates/thor-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The Thor-client allows developers to interact with nodes on the VeChainThor netw

In this example, the code initializes a Thor client for the VeChainThor testnet network and utilizes the `getNodes` method to retrieve information about connected peers.

- `getNodes(): Promise<ConnectedPeer | null>`
- `getNodes(): Promise<ConnectedPeer[]>`

The `getNodes` method simplifies the process of obtaining details about connected peers of a node in the VeChainThor network. The method returns information about the connected peers, allowing developers to monitor and analyze the network's node connectivity.

Expand Down
2 changes: 1 addition & 1 deletion docs/thor-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const peerNodes = await thorClient.nodes.getNodes();

In this example, the code initializes a Thor client for the VeChainThor testnet network and utilizes the `getNodes` method to retrieve information about connected peers.

- `getNodes(): Promise<ConnectedPeer | null>`
- `getNodes(): Promise<ConnectedPeer[]>`

The `getNodes` method simplifies the process of obtaining details about connected peers of a node in the VeChainThor network. The method returns information about the connected peers, allowing developers to monitor and analyze the network's node connectivity.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { JSONRPCInternalError, stringifyData } from '@vechain/sdk-errors';
const netPeerCount = async (thorClient: ThorClient): Promise<number> => {
try {
const peers = await thorClient.nodes.getNodes();
return peers !== null ? peers.length : 0;
return peers.length;
} catch (e) {
throw new JSONRPCInternalError(
'net_peerCount()',
Expand Down
9 changes: 5 additions & 4 deletions packages/network/src/thor-client/nodes/nodes-module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NODE_HEALTHCHECK_TOLERANCE_IN_SECONDS, thorest } from '../../utils';
import { InvalidDataType } from '@vechain/sdk-errors';
import { HttpMethod } from '../../http';
import { NODE_HEALTHCHECK_TOLERANCE_IN_SECONDS, thorest } from '../../utils';
import { type CompressedBlockDetail } from '../blocks';
import { type ThorClient } from '../ThorClient';
import { type ConnectedPeer } from './types';
import { HttpMethod } from '../../http';

/**
* The `NodesModule` class serves as a module for node-related functionality, for example, checking the health of a node.
Expand All @@ -20,11 +20,12 @@ class NodesModule {
*
* @returns A promise that resolves to the list of connected peers.
*/
public async getNodes(): Promise<ConnectedPeer[] | null> {
return (await this.thor.httpClient.http(
public async getNodes(): Promise<ConnectedPeer[]> {
const nodes = (await this.thor.httpClient.http(
HttpMethod.GET,
thorest.nodes.get.NODES()
)) as ConnectedPeer[] | null;
return nodes ?? [];
}

/**
Expand Down

1 comment on commit 6bee05f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
98.99% (4336/4380) 97.61% (1390/1424) 98.99% (890/899)
Title Tests Skipped Failures Errors Time
core 809 0 πŸ’€ 0 ❌ 0 πŸ”₯ 2m 22s ⏱️
network 726 0 πŸ’€ 0 ❌ 0 πŸ”₯ 4m 55s ⏱️
errors 42 0 πŸ’€ 0 ❌ 0 πŸ”₯ 17.776s ⏱️
logging 3 0 πŸ’€ 0 ❌ 0 πŸ”₯ 18.821s ⏱️
hardhat-plugin 19 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 0s ⏱️
aws-kms-adapter 23 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 25s ⏱️
ethers-adapter 5 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 16s ⏱️
rpc-proxy 37 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 8s ⏱️

Please sign in to comment.