Skip to content

Commit 2781060

Browse files
authored
fix: can't parse CommitmentTxPayload (#252)
1 parent a187c20 commit 2781060

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lib/transaction/payload/commitmenttxpayload.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var CURRENT_PAYLOAD_VERSION = 1;
1818
* @property {number} qfcVersion uint16_t 2 Version of the final commitment message
1919
* @property {number} llmqtype uint8_t 1 type of the long living masternode quorum
2020
* @property {string} quorumHash uint256 32 The quorum identifier
21+
* @property {number} quorumIndex int16 2 The quorum index
2122
* @property {number} signersSize compactSize uint 1-9 Bit size of the signers bitvector
2223
* @property {string} signers byte[] (bitSize + 7) / 8 Bitset representing the aggregated signers of this final commitment
2324
* @property {number} validMembersSize compactSize uint 1-9 Bit size of the validMembers bitvector
@@ -35,6 +36,7 @@ var CURRENT_PAYLOAD_VERSION = 1;
3536
* @property {number} qfcVersion
3637
* @property {number} llmqtype
3738
* @property {string} quorumHash
39+
* @property {number} quorumIndex
3840
* @property {number} signersSize
3941
* @property {string} signers
4042
* @property {number} validMembersSize
@@ -54,6 +56,7 @@ function CommitmentTxPayload(options) {
5456
this.qfcVersion = options.qfcVersion;
5557
this.llmqtype = options.llmqtype;
5658
this.quorumHash = options.quorumHash;
59+
this.quorumIndex = options.quorumIndex;
5760
this.signers = options.signers;
5861
this.validMembers = options.validMembers;
5962
this.quorumPublicKey = options.quorumPublicKey;
@@ -84,6 +87,10 @@ CommitmentTxPayload.fromBuffer = function fromBuffer(rawPayload) {
8487
.read(constants.SHA256_HASH_SIZE)
8588
.toString('hex');
8689

90+
if (payload.version >= constants.HASH_QUORUM_INDEX_REQUIRED_VERSION) {
91+
payload.quorumIndex = payloadBufferReader.readInt16LE();
92+
}
93+
8794
payload.signersSize = payloadBufferReader.readVarintNum();
8895
var signersBytesToRead = Math.floor((payload.signersSize + 7) / 8) || 1;
8996
payload.signers = payloadBufferReader
@@ -157,6 +164,14 @@ CommitmentTxPayload.prototype.validate = function () {
157164
utils.isHexaString(this.quorumHash),
158165
'Expect quorumHash to be a hex string'
159166
);
167+
168+
if (this.version >= constants.HASH_QUORUM_INDEX_REQUIRED_VERSION) {
169+
Preconditions.checkArgument(
170+
Number.isInteger(this.quorumIndex),
171+
'Expect quorumHash to be an integer'
172+
);
173+
}
174+
160175
Preconditions.checkArgument(
161176
utils.isHexaString(this.signers),
162177
'Expect signers to be a hex string'
@@ -206,6 +221,10 @@ CommitmentTxPayload.prototype.toJSON = function toJSON(options) {
206221
sig: this.sig,
207222
};
208223

224+
if (this.version >= constants.HASH_QUORUM_INDEX_REQUIRED_VERSION) {
225+
payloadJSON.quorumIndex = this.quorumIndex;
226+
}
227+
209228
return payloadJSON;
210229
};
211230

@@ -226,7 +245,13 @@ CommitmentTxPayload.prototype.toBuffer = function toBuffer(options) {
226245
.writeUInt32LE(this.height)
227246
.writeUInt16LE(this.qfcVersion)
228247
.writeUInt8(this.llmqtype)
229-
.write(Buffer.from(this.quorumHash, 'hex'))
248+
.write(Buffer.from(this.quorumHash, 'hex'));
249+
250+
if (this.version >= constants.HASH_QUORUM_INDEX_REQUIRED_VERSION) {
251+
payloadBufferWriter.writeInt16LE(this.quorumIndex);
252+
}
253+
254+
payloadBufferWriter
230255
.writeVarintNum(this.signersSize)
231256
.write(Buffer.from(this.signers, 'hex'))
232257
.writeVarintNum(this.validMembersSize)

0 commit comments

Comments
 (0)