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

Commit 6d46e2e

Browse files
author
Alan Shaw
authoredDec 17, 2018
feat: cid base option (#1552)
Implements an option for the CLI, HTTP API and core (where appropriate) that will allow the user to pick the multibase encoding for any CIDs that are returned as strings. **NOTE** Using the CID base option in `bitswap`, `dag` and `object` APIs **WILL NOT** auto upgrade your CID to v1 if it is a v0 CID and **WILL NOT** apply the encoding you specified. This is because these APIs return IPLD objects with links and changing the version of the links would result in a different hash for the node if you were to re-add it. Also, the CID you used to retrieve the node wouldn't actually refer to the node you got back any longer. [Read this](ipfs/kubo#5349 (comment)) for further context. This PR adds a `--cid-base` option to the following **CLI commands**: * `jsipfs bitswap stat` * `jsipfs bitswap unwant` * `jsipfs bitswap wantlist` * `jsipfs block put` * `jsipfs block stat` * `jsipfs add` * `jsipfs ls` * `jsipfs object get` * `jsipfs object links` * `jsipfs object new` * `jsipfs object patch add-link` * `jsipfs object patch append-data` * `jsipfs object patch rm-link` * `jsipfs object patch set-data` * `jsipfs object put` * `jsipfs object stat` * `jsipfs pin add` * `jsipfs pin ls` * `jsipfs pin rm` * `jsipfs resolve` Note: these two MFS commands _already_ implement the `--cid-base` option: * `jsipfs files ls` * `jsipfs files stat` It also adds `?cid-base=` query option to the following **HTTP endpoints**: * `/api/v0/bitswap/wantlist` * `/api/v0/bitswap/stat` * `/api/v0/bitswap/unwant` * `/api/v0/block/put` * `/api/v0/block/stat` * `/api/v0/add` * `/api/v0/ls` * `/api/v0/object/new` * `/api/v0/object/get` * `/api/v0/object/put` * `/api/v0/object/stat` * `/api/v0/object/links` * `/api/v0/object/patch/append-data` * `/api/v0/object/patch/set-data` * `/api/v0/object/patch/add-link` * `/api/v0/object/patch/rm-link` * `/api/v0/pin/ls` * `/api/v0/pin/add` * `/api/v0/pin/rm` * `/api/v0/resolve` It adds a `cidBase` option to the following **core functions**: * `resolve` License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 3659d7e commit 6d46e2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1784
-347
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"ipfs-bitswap": "~0.21.0",
109109
"ipfs-block": "~0.8.0",
110110
"ipfs-block-service": "~0.15.1",
111-
"ipfs-http-client": "^28.0.1",
111+
"ipfs-http-client": "^28.1.0",
112112
"ipfs-http-response": "~0.2.1",
113113
"ipfs-mfs": "~0.8.0",
114114
"ipfs-multipart": "~0.1.0",
@@ -122,7 +122,7 @@
122122
"ipld-git": "~0.2.2",
123123
"ipld-zcash": "~0.1.6",
124124
"ipns": "~0.4.3",
125-
"is-ipfs": "~0.4.7",
125+
"is-ipfs": "~0.4.8",
126126
"is-pull-stream": "~0.0.0",
127127
"is-stream": "^1.1.0",
128128
"joi": "^14.3.0",

‎src/cli/commands/add.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const getFolderSize = require('get-folder-size')
1111
const byteman = require('byteman')
1212
const waterfall = require('async/waterfall')
1313
const mh = require('multihashes')
14-
const utils = require('../utils')
15-
const print = require('../utils').print
16-
const createProgressBar = require('../utils').createProgressBar
14+
const multibase = require('multibase')
15+
const { print, isDaemonOn, createProgressBar } = require('../utils')
16+
const { cidToString } = require('../../utils/cid')
1717

1818
function checkPath (inPath, recursive) {
1919
// This function is to check for the following possible inputs
@@ -90,7 +90,7 @@ function addPipeline (index, addStream, list, argv) {
9090
sortBy(added, 'path')
9191
.reverse()
9292
.map((file) => {
93-
const log = [ 'added', file.hash ]
93+
const log = [ 'added', cidToString(file.hash, { base: argv.cidBase }) ]
9494

9595
if (!quiet && file.path.length > 0) log.push(file.path)
9696

@@ -156,10 +156,15 @@ module.exports = {
156156
describe: 'CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)',
157157
default: 0
158158
},
159+
'cid-base': {
160+
describe: 'Number base to display CIDs in.',
161+
type: 'string',
162+
choices: multibase.names
163+
},
159164
hash: {
160165
type: 'string',
161166
choices: Object.keys(mh.names),
162-
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental)'
167+
describe: 'Hash function to use. Will set CID version to 1 if used. (experimental)'
163168
},
164169
quiet: {
165170
alias: 'q',
@@ -202,7 +207,7 @@ module.exports = {
202207
chunker: argv.chunker
203208
}
204209

205-
if (options.enableShardingExperiment && utils.isDaemonOn()) {
210+
if (options.enableShardingExperiment && isDaemonOn()) {
206211
throw new Error('Error: Enabling the sharding experiment should be done on the daemon')
207212
}
208213
const ipfs = argv.ipfs

0 commit comments

Comments
 (0)