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

feat(bitswap.unwatch) expose bitswap.unwatch to cli and http api #1305

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions src/cli/commands/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'unwant <key>',

describe: 'Remove a given block from your wantlist.',
describe: 'Removes a given block from your wantlist.',

builder: {
key: {
alias: 'k',
describe: 'Key to remove from your wantlist',
type: 'string'
}
},
handler (argv) {
throw new Error('Not implemented yet')
argv.ipfs.bitswap.unwant(argv.key, (err, res) => {
if (err) {
throw err
}
print(`Key ${argv.key} removed from wantlist`)
})
}
}
13 changes: 11 additions & 2 deletions src/http/api/resources/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ exports.stat = (request, reply) => {
}

exports.unwant = {
// uses common parseKey method that returns a `key`
// uses common parseKey method that assigns a `key` to request.pre.args
parseArgs: parseKey,

// main route handler which is called after the above `parseArgs`, but only if the args were valid
handler: (request, reply) => {
reply(boom.badRequest(new Error('Not implemented yet')))
const key = request.pre.args.key
const ipfs = request.server.app.ipfs
try {
ipfs.bitswap.unwant(key)
} catch(err) {
return reply(boom.badRequest(err))
}

reply({ Key: key })
}
}
9 changes: 7 additions & 2 deletions test/cli/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ describe('bitswap', () => runOn((thing) => {
})
})

// TODO @hacdias fix this with https://github.com/ipfs/js-ipfs/pull/1198
it.skip('stat', function () {
it('stat', function () {
this.timeout(20 * 1000)

return ipfs('bitswap stat').then((out) => {
Expand All @@ -40,4 +39,10 @@ describe('bitswap', () => runOn((thing) => {
].join('\n') + '\n')
})
})

it('unwant', function () {
return ipfs('bitswap unwant ' + key).then((out) => {
expect(out).to.eql(`Key ${key} removed from wantlist\n`)
});
})
}))