Skip to content

Commit

Permalink
fix false negative case for MINT transactions
Browse files Browse the repository at this point in the history
See the newly added unit test case for this issue.
Currently there are 151 unit tests.
  • Loading branch information
jcramer committed Apr 29, 2020
1 parent 2653647 commit 3671be2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/localvalidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ export class LocalValidator implements SlpValidator {
}
} catch (_) {}
}
if (this.cachedValidations[txid].parents.length !== 1) {
if (this.cachedValidations[txid].parents.length < 1) {
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "MINT transaction must have 1 valid baton parent.";
this.cachedValidations[txid].invalidReason = "MINT transaction must have at least 1 candidate baton parent input.";
return this.cachedValidations[txid].validity!;
}
}
Expand Down Expand Up @@ -342,10 +342,14 @@ export class LocalValidator implements SlpValidator {
// Set validity validation-cache for parents, and handle MINT condition with no valid input
// we don't need to check proper token id since we only added parents with same ID in above steps.
const parentTxids = [...new Set(this.cachedValidations[txid].parents.map(p => p.txid))];
for (let i = 0; i < parentTxids.length; i++) {
const valid = await this.isValidSlpTxid(parentTxids[i]);
this.cachedValidations[txid].parents.filter(p => p.txid === parentTxids[i]).map(p => p.valid = valid);
if (this.cachedValidations[txid].details!.transactionType === SlpTransactionType.MINT && !valid) {
for (const id of parentTxids) {
const valid = await this.isValidSlpTxid(id);
this.cachedValidations[txid].parents.filter(p => p.txid === id).map(p => p.valid = valid);
}

// Check MINT for exactly 1 valid MINT baton
if (this.cachedValidations[txid].details!.transactionType === SlpTransactionType.MINT) {
if (this.cachedValidations[txid].parents.filter(p => p.valid && p.inputQty === null).length !== 1) {
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "MINT transaction with invalid baton parent.";
Expand Down

0 comments on commit 3671be2

Please sign in to comment.