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

refactor: convert id API to async/await #2665

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/core/components/id.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
'use strict'

const callbackify = require('callbackify')
const pkgversion = require('../../../package.json').version

module.exports = function id (self) {
return callbackify(async () => { // eslint-disable-line require-await
module.exports = ({ peerInfo }) => {
return async function id () { // eslint-disable-line require-await
return {
id: self._peerInfo.id.toB58String(),
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
addresses: self._peerInfo.multiaddrs
id: peerInfo.id.toB58String(),
publicKey: peerInfo.id.pubKey.bytes.toString('base64'),
addresses: peerInfo.multiaddrs
.toArray()
.map((ma) => ma.toString())
.filter((ma) => ma.indexOf('ipfs') >= 0)
.sort(),
agentVersion: `js-ipfs/${pkgversion}`,
protocolVersion: '9000'
}
})
}
}
1 change: 1 addition & 0 deletions src/core/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports.add = require('./add')
exports.config = require('./config')
exports.id = require('./id')
exports.init = require('./init')
exports.start = require('./start')
exports.stop = require('./stop')
Expand Down
1 change: 1 addition & 0 deletions src/core/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function createApi ({
const api = {
add,
config: Commands.config({ repo }),
id: Commands.id({ peerInfo }),
init: () => { throw new AlreadyInitializedError() },
start
}
Expand Down
1 change: 1 addition & 0 deletions src/core/components/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function createApi ({
const api = {
add,
config: Commands.config({ repo }),
id: Commands.id({ peerInfo }),
init: () => { throw new AlreadyInitializedError() },
start: () => apiManager.api,
stop
Expand Down
1 change: 1 addition & 0 deletions src/core/components/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function createApi ({
const api = {
add,
config: Commands.config({ repo }),
id: Commands.id({ peerInfo }),
init: () => { throw new AlreadyInitializedError() },
start,
stop: () => apiManager.api
Expand Down