@@ -207,6 +207,10 @@ export class MainAPI {
207207 await ResponseError . assertStatus ( response , 200 )
208208 return response . json ( )
209209 }
210+
211+ public peers ( ) : Promise < PeerJson [ ] > {
212+ return getPeers ( this . http )
213+ }
210214}
211215
212216async function handleQueryResponse ( resp : Response ) : Promise < dm . QueryResponse > {
@@ -248,21 +252,11 @@ export class TelemetryAPI {
248252 return response . arrayBuffer ( ) . then ( ( buffer ) => getCodec ( dm . Status ) . decode ( new Uint8Array ( buffer ) ) )
249253 }
250254
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 )
266260 }
267261
268262 public async metrics ( ) : Promise < string > {
@@ -271,3 +265,19 @@ export class TelemetryAPI {
271265 return response . text ( )
272266 }
273267}
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