Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: support name.resolve of peerid as cid #1145

Merged
merged 2 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"browser-process-platform": "~0.1.1",
"cross-env": "^6.0.0",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.117.2",
"interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#feat/peerid-as-cid",
"ipfsd-ctl": "^0.47.1",
"nock": "^11.4.0",
"stream-equal": "^1.1.1"
Expand Down
15 changes: 15 additions & 0 deletions src/name/resolve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const promisify = require('promisify-es6')
const CID = require('cids')
const multihash = require('multihashes')

const transform = function (res, callback) {
callback(null, res.Path)
Expand All @@ -13,6 +15,19 @@ module.exports = (send) => {
opts = {}
}

// normalize PeerIDs to Base58btc, so it works with go-ipfs <=0.4.22
if (typeof (args) === 'string') {
try {
const path = args.split('/')
if (path.length > 2) {
path[2] = multihash.toB58String(new CID(path[2]).multihash)
args = path.join('/')
}
} catch (err) {
// noop
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better way? :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All we need to do is stringify args if it is a CID. We will skip the interface-ipfs-core test here until go-ipfs supports it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't stringify CIDs anywhere else, removed this hack and added TODO to unskip mentioned test when go-ipfs implements this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, I guess the querystring module calls toString on the CID then...


send.andTransform({
path: 'name/resolve',
args: args,
Expand Down