Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 20cbd6d

Browse files
author
Alan Shaw
authored
refactor: convert id API to async/await (#2665)
1 parent 1449103 commit 20cbd6d

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

Diff for: src/core/components/id.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
'use strict'
22

3-
const callbackify = require('callbackify')
43
const pkgversion = require('../../../package.json').version
54

6-
module.exports = function id (self) {
7-
return callbackify(async () => { // eslint-disable-line require-await
5+
module.exports = ({ peerInfo }) => {
6+
return async function id () { // eslint-disable-line require-await
87
return {
9-
id: self._peerInfo.id.toB58String(),
10-
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
11-
addresses: self._peerInfo.multiaddrs
8+
id: peerInfo.id.toB58String(),
9+
publicKey: peerInfo.id.pubKey.bytes.toString('base64'),
10+
addresses: peerInfo.multiaddrs
1211
.toArray()
1312
.map((ma) => ma.toString())
1413
.filter((ma) => ma.indexOf('ipfs') >= 0)
1514
.sort(),
1615
agentVersion: `js-ipfs/${pkgversion}`,
1716
protocolVersion: '9000'
1817
}
19-
})
18+
}
2019
}

Diff for: src/core/components/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports.bitswap = {
77
wantlist: require('./bitswap/wantlist')
88
}
99
exports.config = require('./config')
10+
exports.id = require('./id')
1011
exports.init = require('./init')
1112
exports.ping = require('./ping')
1213
exports.start = require('./start')

Diff for: src/core/components/init.js

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ function createApi ({
300300
const api = {
301301
add,
302302
config: Commands.config({ repo }),
303+
id: Commands.id({ peerInfo }),
303304
init: () => { throw new AlreadyInitializedError() },
304305
start
305306
}

Diff for: src/core/components/start.js

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function createApi ({
137137
wantlist: Commands.bitswap.wantlist({ bitswap })
138138
},
139139
config: Commands.config({ repo }),
140+
id: Commands.id({ peerInfo }),
140141
init: () => { throw new AlreadyInitializedError() },
141142
ping: Commands.ping({ libp2p }),
142143
pubsub: libp2p.pubsub

Diff for: src/core/components/stop.js

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function createApi ({
9999
const api = {
100100
add,
101101
config: Commands.config({ repo }),
102+
id: Commands.id({ peerInfo }),
102103
init: () => { throw new AlreadyInitializedError() },
103104
start,
104105
stop: () => apiManager.api

0 commit comments

Comments
 (0)