@@ -207,6 +207,10 @@ export class MainAPI {
207
207
await ResponseError . assertStatus ( response , 200 )
208
208
return response . json ( )
209
209
}
210
+
211
+ public peers ( ) : Promise < PeerJson [ ] > {
212
+ return getPeers ( this . http )
213
+ }
210
214
}
211
215
212
216
async function handleQueryResponse ( resp : Response ) : Promise < dm . QueryResponse > {
@@ -248,21 +252,11 @@ export class TelemetryAPI {
248
252
return response . arrayBuffer ( ) . then ( ( buffer ) => getCodec ( dm . Status ) . decode ( new Uint8Array ( buffer ) ) )
249
253
}
250
254
251
- // TODO: move once metrics are updated
252
- public async peers ( ) : Promise < PeerJson [ ] > {
253
- const response = await this . http . getFetch ( ) ( urlJoinPath ( this . http . toriiBaseURL , ENDPOINT_PEERS ) )
254
- await ResponseError . assertStatus ( response , 200 )
255
- return response . json ( ) . then (
256
- // array of strings in format `<pub key multihash>@<socket addr>`
257
- ( ids : string [ ] ) => {
258
- assert ( Array . isArray ( ids ) )
259
- return ids . map ( ( id ) => {
260
- assert ( typeof id === 'string' )
261
- const [ pubkey , address ] = id . split ( '@' )
262
- return { id : dm . PublicKey . fromMultihash ( pubkey ) , address }
263
- } )
264
- } ,
265
- )
255
+ /**
256
+ * @deprecated use {@linkcode MainAPI#peers}
257
+ */
258
+ public peers ( ) : Promise < PeerJson [ ] > {
259
+ return getPeers ( this . http )
266
260
}
267
261
268
262
public async metrics ( ) : Promise < string > {
@@ -271,3 +265,19 @@ export class TelemetryAPI {
271
265
return response . text ( )
272
266
}
273
267
}
268
+
269
+ async function getPeers ( http : HttpTransport ) {
270
+ const response = await http . getFetch ( ) ( urlJoinPath ( http . toriiBaseURL , ENDPOINT_PEERS ) )
271
+ await ResponseError . assertStatus ( response , 200 )
272
+ return response . json ( ) . then (
273
+ // array of strings in format `<pub key multihash>@<socket addr>`
274
+ ( ids : string [ ] ) => {
275
+ assert ( Array . isArray ( ids ) )
276
+ return ids . map ( ( id ) => {
277
+ assert ( typeof id === 'string' )
278
+ const [ pubkey , address ] = id . split ( '@' )
279
+ return { id : dm . PublicKey . fromMultihash ( pubkey ) , address }
280
+ } )
281
+ } ,
282
+ )
283
+ }
0 commit comments