Skip to content

Commit 66186b1

Browse files
authored
feat(sml): version is mandatory for SML entry (#289)
* feat(sml): version is mandatory for sml entry * feat: clone thisˆ
1 parent 3765ab9 commit 66186b1

File tree

3 files changed

+183
-15
lines changed

3 files changed

+183
-15
lines changed

lib/deterministicmnlist/SimplifiedMNListDiff.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ SimplifiedMNListDiff.fromObject = function fromObject(obj, network) {
219219
// Copy array of strings
220220
simplifiedMNListDiff.deletedMNs = obj.deletedMNs.slice();
221221
simplifiedMNListDiff.mnList = obj.mnList.map(
222-
(entry) => new SimplifiedMNListEntry({ ...entry, nVersion: obj.nVersion }, validNetwork)
222+
(entry) => new SimplifiedMNListEntry(entry, validNetwork)
223223
);
224224
simplifiedMNListDiff.deletedQuorums = obj.deletedQuorums.slice();
225225
simplifiedMNListDiff.newQuorums = obj.newQuorums.map(
@@ -296,7 +296,7 @@ SimplifiedMNListDiff.prototype.toObject = function toObject() {
296296
};
297297

298298
SimplifiedMNListDiff.prototype.copy = function copy() {
299-
return SimplifiedMNListDiff.fromObject(_.clone(this.toObject()), this.network);
299+
return _.cloneDeep(this);
300300
};
301301

302302
module.exports = SimplifiedMNListDiff;

lib/deterministicmnlist/SimplifiedMNListEntry.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ SimplifiedMNListEntry.prototype.toBuffer = function toBuffer() {
148148
);
149149
bufferWriter.writeUInt8(Number(this.isValid));
150150

151-
if (typeof this.nType === 'number') {
152-
bufferWriter.writeUInt16LE(this.nType);
153-
154-
if (this.nType === MASTERNODE_TYPE_HP) {
155-
bufferWriter.writeUInt16LE(this.platformHTTPPort);
156-
bufferWriter.write(Buffer.from(this.platformNodeID, 'hex').reverse());
151+
if (this.nVersion === 2) {
152+
if (typeof this.nType === 'number') {
153+
bufferWriter.writeUInt16LE(this.nType);
154+
155+
if (this.nType === MASTERNODE_TYPE_HP) {
156+
bufferWriter.writeUInt16LE(this.platformHTTPPort);
157+
bufferWriter.write(Buffer.from(this.platformNodeID, 'hex').reverse());
158+
}
157159
}
158160
}
159161

@@ -239,9 +241,12 @@ SimplifiedMNListEntry.prototype.toObject = function toObject() {
239241
pubKeyOperator: this.pubKeyOperator,
240242
votingAddress: this.votingAddress,
241243
isValid: this.isValid,
242-
nVersion: this.nVersion,
243244
};
244245

246+
if (typeof this.nVersion === 'number') {
247+
result.nVersion = this.nVersion;
248+
}
249+
245250
if (typeof this.nType === 'number') {
246251
result.nType = this.nType;
247252
}
@@ -262,10 +267,6 @@ SimplifiedMNListEntry.prototype.toObject = function toObject() {
262267
result.platformNodeID = this.platformNodeID;
263268
}
264269

265-
if (typeof this.nVersion === 'number') {
266-
result.nVersion = this.nVersion;
267-
}
268-
269270
return result;
270271
};
271272

@@ -302,7 +303,7 @@ SimplifiedMNListEntry.prototype.confirmedHashWithProRegTxHash =
302303
* @return {SimplifiedMNListEntry}
303304
*/
304305
SimplifiedMNListEntry.prototype.copy = function copy() {
305-
return SimplifiedMNListEntry.fromObject(_.clone(this.toObject()), this.network);
306+
return _.cloneDeep(this);
306307
};
307308

308309
module.exports = SimplifiedMNListEntry;

0 commit comments

Comments
 (0)