Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sml): version is mandatory for SML entry #289

Merged
merged 2 commits into from
Jun 22, 2023
Merged
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
4 changes: 2 additions & 2 deletions lib/deterministicmnlist/SimplifiedMNListDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ SimplifiedMNListDiff.fromObject = function fromObject(obj, network) {
// Copy array of strings
simplifiedMNListDiff.deletedMNs = obj.deletedMNs.slice();
simplifiedMNListDiff.mnList = obj.mnList.map(
(entry) => new SimplifiedMNListEntry({ ...entry, nVersion: obj.nVersion }, validNetwork)
(entry) => new SimplifiedMNListEntry(entry, validNetwork)
);
simplifiedMNListDiff.deletedQuorums = obj.deletedQuorums.slice();
simplifiedMNListDiff.newQuorums = obj.newQuorums.map(
Expand Down Expand Up @@ -296,7 +296,7 @@ SimplifiedMNListDiff.prototype.toObject = function toObject() {
};

SimplifiedMNListDiff.prototype.copy = function copy() {
return SimplifiedMNListDiff.fromObject(_.clone(this.toObject()), this.network);
return _.cloneDeep(this);
};

module.exports = SimplifiedMNListDiff;
25 changes: 13 additions & 12 deletions lib/deterministicmnlist/SimplifiedMNListEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ SimplifiedMNListEntry.prototype.toBuffer = function toBuffer() {
);
bufferWriter.writeUInt8(Number(this.isValid));

if (typeof this.nType === 'number') {
bufferWriter.writeUInt16LE(this.nType);

if (this.nType === MASTERNODE_TYPE_HP) {
bufferWriter.writeUInt16LE(this.platformHTTPPort);
bufferWriter.write(Buffer.from(this.platformNodeID, 'hex').reverse());
if (this.nVersion === 2) {
if (typeof this.nType === 'number') {
bufferWriter.writeUInt16LE(this.nType);

if (this.nType === MASTERNODE_TYPE_HP) {
bufferWriter.writeUInt16LE(this.platformHTTPPort);
bufferWriter.write(Buffer.from(this.platformNodeID, 'hex').reverse());
}
}
}

Expand Down Expand Up @@ -239,9 +241,12 @@ SimplifiedMNListEntry.prototype.toObject = function toObject() {
pubKeyOperator: this.pubKeyOperator,
votingAddress: this.votingAddress,
isValid: this.isValid,
nVersion: this.nVersion,
};

if (typeof this.nVersion === 'number') {
result.nVersion = this.nVersion;
}

if (typeof this.nType === 'number') {
result.nType = this.nType;
}
Expand All @@ -262,10 +267,6 @@ SimplifiedMNListEntry.prototype.toObject = function toObject() {
result.platformNodeID = this.platformNodeID;
}

if (typeof this.nVersion === 'number') {
result.nVersion = this.nVersion;
}

return result;
};

Expand Down Expand Up @@ -302,7 +303,7 @@ SimplifiedMNListEntry.prototype.confirmedHashWithProRegTxHash =
* @return {SimplifiedMNListEntry}
*/
SimplifiedMNListEntry.prototype.copy = function copy() {
return SimplifiedMNListEntry.fromObject(_.clone(this.toObject()), this.network);
return _.cloneDeep(this);
};

module.exports = SimplifiedMNListEntry;
Loading