Skip to content

Commit

Permalink
critical update for NFT child genesis validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcramer committed Jul 29, 2020
1 parent 01335b4 commit 290c20e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
50 changes: 32 additions & 18 deletions lib/localvalidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ export class LocalValidator implements SlpValidator {
if (slpmsg.versionType === 0x41) {
// An NFT1 parent should be provided at input index 0,
// so we check this first before checking the whole parent DAG
let input_txid = txn.inputs[0].prevTxId.toString("hex");
let input_txhex = await this.retrieveRawTransaction(input_txid);
let input_tx: Bitcore.Transaction = new Bitcore.Transaction(input_txhex);
const input_txid = txn.inputs[0].prevTxId.toString("hex");
const input_prevout = txn.inputs[0].outputIndex;
const input_txhex = await this.retrieveRawTransaction(input_txid);
const input_tx: Bitcore.Transaction = new Bitcore.Transaction(input_txhex);
let input_slpmsg;
try {
input_slpmsg = this.slp.parseSlpOutputScript(input_tx.outputs[0]._scriptBuffer);
Expand All @@ -224,21 +225,34 @@ export class LocalValidator implements SlpValidator {
return this.cachedValidations[txid].validity!;
}
// Check that the there is a burned output >0 in the parent txn SLP message
if (input_slpmsg.transactionType === SlpTransactionType.SEND &&
(!input_slpmsg.sendOutputs![1].isGreaterThan(0)))
{
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return this.cachedValidations[txid].validity!;
} else if ((input_slpmsg.transactionType === SlpTransactionType.GENESIS ||
input_slpmsg.transactionType === SlpTransactionType.MINT) &&
!input_slpmsg.genesisOrMintQuantity!.isGreaterThan(0))
{
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return this.cachedValidations[txid].validity!;
if (input_slpmsg.transactionType === SlpTransactionType.SEND) {
if (input_prevout > input_slpmsg.sendOutputs!.length - 1) {
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input.";
return this.cachedValidations[txid].validity!;
} else if (! input_slpmsg.sendOutputs![input_prevout].isGreaterThan(0)) {
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return this.cachedValidations[txid].validity!;
} else {
this.cachedValidations[txid].validity = true;
this.cachedValidations[txid].waiting = false;
}
} else if (input_slpmsg.transactionType === SlpTransactionType.GENESIS ||
input_slpmsg.transactionType === SlpTransactionType.MINT) {
if (input_prevout !== 1) {
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input.";
return this.cachedValidations[txid].validity!;
} else if (!input_slpmsg.genesisOrMintQuantity!.isGreaterThan(0)) {
this.cachedValidations[txid].validity = false;
this.cachedValidations[txid].waiting = false;
this.cachedValidations[txid].invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return this.cachedValidations[txid].validity!;
}
}
// Continue to check the NFT1 parent DAG
let nft_parent_dag_validity = await this.isValidSlpTxid(input_txid, undefined, 0x81);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"mkdirp": "^0.5.5",
"mocha": "^7.2.0",
"nyc": "^15.1.0",
"slp-unit-test-data": "git+https://github.com/simpleledger/slp-unit-test-data.git#a450146e112aee4db5a1b33dc978229fdcfb23a4",
"slp-unit-test-data": "git+https://github.com/simpleledger/slp-unit-test-data.git#8c942eacfae12686dcf1f3366321445a4fba73e7",
"source-map-support": "^0.5.19",
"ts-node": "^7.0.1",
"typescript": "^3.9.5",
Expand Down

0 comments on commit 290c20e

Please sign in to comment.