diff --git a/lib/transport/messages.js b/lib/transport/messages.js index 8a55a8d..5b0fb19 100644 --- a/lib/transport/messages.js +++ b/lib/transport/messages.js @@ -1,4 +1,5 @@ 'use strict'; +/* jshint curly: false */ var Buffers = require('buffers'); var Put = require('bufferput'); @@ -85,7 +86,7 @@ function discardUntilNextMessage(network, dataBuffer) { * Abstract Message that knows how to parse and serialize itself. * Concret subclases should implement {fromBuffer} and {getPayload} methods. */ -function Message() {}; +function Message() {} Message.COMMANDS = {}; @@ -95,7 +96,6 @@ Message.buildMessage = function(command, payload) { return new CommandClass().fromBuffer(payload); } catch (err) { console.log('Error while parsing message', err); - throw err; } }; @@ -106,6 +106,7 @@ Message.buildMessage = function(command, payload) { * @returns{Message} The same message instance */ Message.prototype.fromBuffer = function(payload) { + /* jshint unused: false */ return this; }; @@ -188,7 +189,7 @@ Version.prototype.getPayload = function() { return put.buffer(); }; -module.exports.Version = Message.COMMANDS['version'] = Version; +module.exports.Version = Message.COMMANDS.version = Version; /** * Inv Message @@ -226,7 +227,7 @@ Inventory.prototype.getPayload = function() { return put.buffer(); }; -module.exports.Inventory = Message.COMMANDS['inv'] = Inventory; +module.exports.Inventory = Message.COMMANDS.inv = Inventory; /** * Getdata Message @@ -261,7 +262,7 @@ Ping.prototype.getPayload = function() { return this.nonce; }; -module.exports.Ping = Message.COMMANDS['ping'] = Ping; +module.exports.Ping = Message.COMMANDS.ping = Ping; /** * Pong Message @@ -274,7 +275,7 @@ function Pong(nonce) { } util.inherits(Pong, Ping); -module.exports.Pong = Message.COMMANDS['pong'] = Pong; +module.exports.Pong = Message.COMMANDS.pong = Pong; /** * Addr Message @@ -319,7 +320,7 @@ Addresses.prototype.getPayload = function() { return put.buffer(); }; -module.exports.Addresses = Message.COMMANDS['addr'] = Addresses; +module.exports.Addresses = Message.COMMANDS.addr = Addresses; /** * GetAddr Message @@ -330,7 +331,7 @@ function GetAddresses() { } util.inherits(GetAddresses, Message); -module.exports.GetAddresses = Message.COMMANDS['getaddr'] = GetAddresses; +module.exports.GetAddresses = Message.COMMANDS.getaddr = GetAddresses; /** * Verack Message @@ -341,7 +342,7 @@ function VerAck() { } util.inherits(VerAck, Message); -module.exports.VerAck = Message.COMMANDS['verack'] = VerAck; +module.exports.VerAck = Message.COMMANDS.verack = VerAck; /** * Reject Message @@ -354,7 +355,7 @@ util.inherits(Reject, Message); // TODO: Parse REJECT message -module.exports.Reject = Message.COMMANDS['reject'] = Reject; +module.exports.Reject = Message.COMMANDS.reject = Reject; /** * Alert Message @@ -385,7 +386,7 @@ Alert.prototype.getPayload = function() { return put.buffer(); }; -module.exports.Alert = Message.COMMANDS['alert'] = Alert; +module.exports.Alert = Message.COMMANDS.alert = Alert; /** * Headers Message @@ -423,7 +424,7 @@ Headers.prototype.getPayload = function() { return put.buffer(); }; -module.exports.Headers = Message.COMMANDS['headers'] = Headers; +module.exports.Headers = Message.COMMANDS.headers = Headers; /** * Block Message @@ -445,7 +446,7 @@ Block.prototype.getPayload = function() { return this.block.toBuffer(); }; -module.exports.Block = Message.COMMANDS['block'] = Block; +module.exports.Block = Message.COMMANDS.block = Block; /** * Tx Message @@ -467,7 +468,7 @@ Transaction.prototype.getPayload = function() { return this.transaction.toBuffer(); }; -module.exports.Transaction = Message.COMMANDS['tx'] = Transaction; +module.exports.Transaction = Message.COMMANDS.tx = Transaction; /** * Getblocks Message @@ -503,13 +504,13 @@ GetBlocks.prototype.getPayload = function() { put.varint(this.starts.length); for (var i = 0; i < this.starts.length; i++) { - if (this.starts[i].length != 32) { + if (this.starts[i].length !== 32) { throw new Error('Invalid hash length'); } put.put(this.starts[i]); } - if (this.stop.length != 32) { + if (this.stop.length !== 32) { throw new Error('Invalid hash length'); } put.put(this.stop); @@ -517,7 +518,7 @@ GetBlocks.prototype.getPayload = function() { return put.buffer(); }; -module.exports.GetBlocks = Message.COMMANDS['getblocks'] = GetBlocks; +module.exports.GetBlocks = Message.COMMANDS.getblocks = GetBlocks; /** * Getheaders Message @@ -533,14 +534,14 @@ function GetHeaders(starts, stop) { } util.inherits(GetHeaders, GetBlocks); -module.exports.GetHeaders = Message.COMMANDS['getheaders'] = GetHeaders; +module.exports.GetHeaders = Message.COMMANDS.getheaders = GetHeaders; // TODO: Remove this PATCH (yemel) Buffers.prototype.skip = function (i) { - if (i == 0) return; + if (i === 0) return; - if (i == this.length) { + if (i === this.length) { this.buffers = []; this.length = 0; return; diff --git a/test/transport/messages.js b/test/transport/messages.js index 9e7c851..15325b3 100644 --- a/test/transport/messages.js +++ b/test/transport/messages.js @@ -1,11 +1,8 @@ 'use strict'; var chai = require('chai'); -var Net = require('net'); -var Socks5Client = require('socks5-client'); var should = chai.should(); -var expect = chai.expect; var bitcore = require('../..'); var Data = require('../data/messages'); @@ -37,7 +34,7 @@ describe('Messages', function() { it('should be able to parse payload', function() { var payload = new Buffer(Data.VERSION.payload, 'hex'); - var message = new Messages.Version().fromBuffer(payload); + new Messages.Version().fromBuffer(payload); }); }); @@ -61,7 +58,7 @@ describe('Messages', function() { it('should be able to parse payload', function() { var payload = new Buffer(Data.VERACK.payload, 'hex'); - var message = new Messages.VerAck().fromBuffer(payload); + new Messages.VerAck().fromBuffer(payload); }); }); @@ -85,7 +82,7 @@ describe('Messages', function() { it('should be able to parse payload', function() { var payload = new Buffer(Data.INV.payload, 'hex'); - var message = new Messages.Inventory().fromBuffer(payload); + new Messages.Inventory().fromBuffer(payload); }); }); @@ -109,7 +106,7 @@ describe('Messages', function() { it('should be able to parse payload', function() { var payload = new Buffer(Data.ADDR.payload, 'hex'); - var message = new Messages.Addresses().fromBuffer(payload); + new Messages.Addresses().fromBuffer(payload); }); }); @@ -133,7 +130,7 @@ describe('Messages', function() { it('should be able to parse payload', function() { var payload = new Buffer(Data.PING.payload, 'hex'); - var message = new Messages.Ping().fromBuffer(payload); + new Messages.Ping().fromBuffer(payload); }); }); @@ -157,7 +154,7 @@ describe('Messages', function() { it('should be able to parse payload', function() { var payload = new Buffer(Data.PING.payload, 'hex'); - var message = new Messages.Pong().fromBuffer(payload); + new Messages.Pong().fromBuffer(payload); }); }); diff --git a/test/transport/peer.js b/test/transport/peer.js index 8a832c0..f0e25c2 100644 --- a/test/transport/peer.js +++ b/test/transport/peer.js @@ -4,6 +4,7 @@ var chai = require('chai'); var Net = require('net'); var Socks5Client = require('socks5-client'); +/* jshint unused: false */ var should = chai.should(); var expect = chai.expect; @@ -52,7 +53,7 @@ describe('Peer', function() { var peer, peer2, socket; peer = new Peer('localhost'); - expect(peer.proxy).to.be.undefined; + expect(peer.proxy).to.be.undefined(); socket = peer._getSocket(); socket.should.be.instanceof(Net.Socket);