File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments