Skip to content

Commit 704de22

Browse files
achingbrainvmx
authored andcommitted
fix: base encode CIDs before logging or emitting them
BREAKING CHANGE: Emitted events have different bytes The emitted events contain the stringified version of the CID, as we change it to the base encoding the CID has, those bytes may be different to previous versions of this module. Though this shouldn't have any impact on any other modules as the events are only used internally.
1 parent 2cbc1e9 commit 704de22

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/notifications.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Notifications extends EventEmitter {
3434
* @return {void}
3535
*/
3636
hasBlock (block) {
37-
const str = `block:${block.cid.buffer.toString()}`
37+
const str = `block:${block.cid}`
3838
this._log(str)
3939
this.emit(str, block)
4040
}
@@ -49,7 +49,7 @@ class Notifications extends EventEmitter {
4949
* @returns {void}
5050
*/
5151
wantBlock (cid, onBlock, onUnwant) {
52-
const cidStr = cid.buffer.toString()
52+
const cidStr = cid.toString()
5353
this._log(`wantBlock:${cidStr}`)
5454

5555
this._unwantListeners[cidStr] = () => {
@@ -80,7 +80,7 @@ class Notifications extends EventEmitter {
8080
* @returns {void}
8181
*/
8282
unwantBlock (cid) {
83-
const str = `unwant:${cid.buffer.toString()}`
83+
const str = `unwant:${cid}`
8484
this._log(str)
8585
this.emit(str)
8686
}

test/notifications.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Notifications', () => {
3434
it('hasBlock', (done) => {
3535
const n = new Notifications(peerId)
3636
const b = blocks[0]
37-
n.once(`block:${b.cid.buffer.toString()}`, (block) => {
37+
n.once(`block:${b.cid}`, (block) => {
3838
expect(b).to.eql(block)
3939
done()
4040
})

0 commit comments

Comments
 (0)