Skip to content

Commit 2b912d3

Browse files
committed
Added nodePeers endpoint
1 parent bd88dc6 commit 2b912d3

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

e2e/infrastructure/NodeHttp.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ describe('NodeHttp', () => {
4141
});
4242
});
4343

44+
describe('getNodePeers', () => {
45+
it('should return node peers', async () => {
46+
const nodeInfo = await nodeRepository.getNodePeers().toPromise();
47+
expect(nodeInfo[0].friendlyName).not.to.be.undefined;
48+
expect(nodeInfo[0].host).not.to.be.undefined;
49+
expect(nodeInfo[0].networkIdentifier).not.to.be.undefined;
50+
expect(nodeInfo[0].port).not.to.be.undefined;
51+
expect(nodeInfo[0].publicKey).not.to.be.undefined;
52+
expect(nodeInfo[0].roles).not.to.be.undefined;
53+
expect(nodeInfo[0].version).not.to.be.undefined;
54+
});
55+
});
56+
4457
describe('getNodeTime', () => {
4558
it('should return node time', async () => {
4659
const nodeTime = await nodeRepository.getNodeTime().toPromise();

src/infrastructure/NodeHttp.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ export class NodeHttp extends Http implements NodeRepository {
6868
);
6969
}
7070

71+
/**
72+
* Gets the list of peers visible by the node,
73+
* @summary Gets the list of peers visible by the node
74+
*/
75+
public getNodePeers(): Observable<NodeInfo[]> {
76+
return observableFrom(this.nodeRoutesApi.getNodePeers()).pipe(
77+
map(({body}) => body.map((nodeInfo) =>
78+
new NodeInfo(
79+
nodeInfo.publicKey,
80+
nodeInfo.networkGenerationHash,
81+
nodeInfo.port,
82+
nodeInfo.networkIdentifier,
83+
nodeInfo.version,
84+
nodeInfo.roles as number,
85+
nodeInfo.host,
86+
nodeInfo.friendlyName,
87+
))),
88+
catchError((error) => throwError(this.errorHandling(error))),
89+
);
90+
}
91+
7192
/**
7293
* Gets the node time at the moment the reply was sent and received.
7394
* @summary Get the node time

src/infrastructure/NodeRepository.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export interface NodeRepository {
3434
*/
3535
getNodeInfo(): Observable<NodeInfo>;
3636

37+
/**
38+
* Gets the list of peers visible by the node,
39+
* @summary Gets the list of peers visible by the node
40+
*/
41+
getNodePeers(): Observable<NodeInfo[]>;
42+
3743
/**
3844
* Gets the node time at the moment the reply was sent and received.
3945
* @summary Get the node time

0 commit comments

Comments
 (0)