Skip to content

Commit

Permalink
Fix version message (#14)
Browse files Browse the repository at this point in the history
* update dependencies

* fix version message parser

* add mew protocol messages to unsupportedCommands

* bump version

* add .idea to .gitignore

* update package lock

* set default to most current version

* rename mnauthChallenge to mnAuthChallenge
  • Loading branch information
Cofresi authored Jul 1, 2019
1 parent 1c6f4af commit 7d252d7
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 592 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
# ignore generated code coverage output
coverage
.nyc_output
.idea

# ignore build artifacts
dist
5 changes: 4 additions & 1 deletion lib/messages/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function builder(options) {
options.Transaction = options.Transaction || dashcore.Transaction;
options.MerkleBlock = options.MerkleBlock || dashcore.MerkleBlock;
options.MnListDiff = options.MnListDiff || dashcore.MnListDiff;
options.protocolVersion = options.protocolVersion || 130000;
options.protocolVersion = options.protocolVersion || 70215;

var exported = {
constructors: {
Expand Down Expand Up @@ -68,6 +68,9 @@ function builder(options) {
ix: 'TXLockRequest'
},
unsupportedCommands: [
'qsendrecsigs',
'senddsq',
'sendcmpct',
'sendheaders',
'txlvote',
'spork',
Expand Down
13 changes: 12 additions & 1 deletion lib/messages/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var packageInfo = require('../../../package.json');
* @param {BN=} arg.services
* @param {Date=} arg.timestamp
* @param {Number=} arg.startHeight
* @param {boolean} [arg.relay]
* @param {string} [arg.mnAuthChallenge]
* @param {Object} options
* @extends Message
* @constructor
Expand All @@ -39,7 +41,8 @@ function VersionMessage(arg, options) {
this.timestamp = arg.timestamp || new Date();
this.subversion = arg.subversion || '/dashcore:' + packageInfo.version + '/';
this.startHeight = arg.startHeight || 0;
this.relay = arg.relay === false ? false : true;
this.relay = arg.relay !== false;
this.mnAuthChallenge = arg.mnAuthChallenge ? arg.mnAuthChallenge : null;
}
inherits(VersionMessage, Message);

Expand Down Expand Up @@ -68,6 +71,11 @@ VersionMessage.prototype.setPayload = function(payload) {
} else {
this.relay = !!parser.readUInt8();
}
if(parser.finished()) {
this.mnAuthChallenge = null;
} else if (this.version >= 70214) {
this.mnAuthChallenge = parser.read(32).toString('hex');
}
utils.checkFinished(parser);
};

Expand All @@ -87,6 +95,9 @@ VersionMessage.prototype.getPayload = function() {
bw.write(new Buffer(this.subversion, 'ascii'));
bw.writeUInt32LE(this.startHeight);
bw.writeUInt8(this.relay);
if (this.mnAuthChallenge) {
bw.write(Buffer.from(this.mnAuthChallenge, 'hex'));
}

return bw.concat();
};
Expand Down
Loading

0 comments on commit 7d252d7

Please sign in to comment.