diff --git a/package.json b/package.json index 216fc76085..f84edf26a2 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "ipfs-http-response": "~0.3.1", "ipfs-mfs": "^0.13.0", "ipfs-multipart": "^0.2.0", - "ipfs-repo": "^0.28.0", + "ipfs-repo": "github:ipfs/js-ipfs-repo#auhau/feat/multihash_keys_in_datastore", "ipfs-unixfs": "~0.1.16", "ipfs-unixfs-exporter": "^0.38.0", "ipfs-unixfs-importer": "^0.40.0", @@ -203,7 +203,7 @@ "execa": "^2.0.4", "form-data": "^2.5.1", "hat": "0.0.3", - "interface-ipfs-core": "^0.117.2", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#auhau/feat/multihash_keys_in_datastore", "ipfs-interop": "^0.1.1", "ipfsd-ctl": "^0.47.2", "libp2p-websocket-star": "~0.10.2", diff --git a/src/cli/commands/refs-local.js b/src/cli/commands/refs-local.js index c0ce2a894a..6320b59974 100644 --- a/src/cli/commands/refs-local.js +++ b/src/cli/commands/refs-local.js @@ -5,6 +5,10 @@ module.exports = { describe: 'List all local references.', + builder (yargs) { + return yargs.epilog('CIDs are reconstructed therefore they might differ from those under which the blocks were originally stored.') + }, + handler ({ getIpfs, print, resolve }) { resolve((async () => { const ipfs = await getIpfs() diff --git a/src/core/components/files-regular/refs-local-pull-stream.js b/src/core/components/files-regular/refs-local-pull-stream.js index 77c396f58f..093d5c46e6 100644 --- a/src/core/components/files-regular/refs-local-pull-stream.js +++ b/src/core/components/files-regular/refs-local-pull-stream.js @@ -1,26 +1,18 @@ 'use strict' -const CID = require('cids') -const base32 = require('base32.js') +const { keyToCid } = require('ipfs-repo/src/blockstore-utils') const itToPull = require('async-iterator-to-pull-stream') module.exports = function (self) { return () => { return itToPull((async function * () { - for await (const result of self._repo.blocks.query({ keysOnly: true })) { - yield dsKeyToRef(result.key) + for await (const { key: k } of self._repo.blocks.query({ keysOnly: true })) { + try { + yield { ref: keyToCid(k).toString() } + } catch (err) { + yield { err: `Could not convert block with key '${k.toString()}' to CID: ${err.message}` } + } } })()) } } - -function dsKeyToRef (key) { - try { - // Block key is of the form / - const decoder = new base32.Decoder() - const buff = Buffer.from(decoder.write(key.toString().slice(1)).finalize()) - return { ref: new CID(buff).toString() } - } catch (err) { - return { err: `Could not convert block with key '${key}' to CID: ${err.message}` } - } -} diff --git a/test/cli/refs-local.js b/test/cli/refs-local.js index 6b1e5fc872..cb0d8dce48 100644 --- a/test/cli/refs-local.js +++ b/test/cli/refs-local.js @@ -18,7 +18,7 @@ describe('refs-local', () => runOnAndOff((thing) => { const out = await ipfs('refs-local') const lines = out.split('\n') - expect(lines.includes('QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN')).to.eql(true) - expect(lines.includes('QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU')).to.eql(true) + expect(lines.includes('bafkreicjl7v3vyyv4zlryihez5xhunqmriry6styhil7z5lhd3r4prnz6y')).to.eql(true) + expect(lines.includes('bafkreidj5bovvm25wszvajfshj7m7m2efpswcs6dsz7giz52ovlquxc4o4')).to.eql(true) }) })) diff --git a/test/fixtures/go-ipfs-repo/version b/test/fixtures/go-ipfs-repo/version index c7930257df..301160a930 100644 --- a/test/fixtures/go-ipfs-repo/version +++ b/test/fixtures/go-ipfs-repo/version @@ -1 +1 @@ -7 \ No newline at end of file +8 \ No newline at end of file