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 70ec52b commit 3963cf9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
52 changes: 34 additions & 18 deletions lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,13 @@ export class ValidatorType1 {
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
const inputTxid = txn.inputs[0].previousTxHash;
const inputTxHex = await this.retrieveRawTransaction(inputTxid);
const inputTx: Transaction = Transaction.parseFromBuffer(inputTxHex);
const inputPrevTxid = txn.inputs[0].previousTxHash;
const inputPrevOut = txn.inputs[0].previousTxOutIndex;
const inputPrevTxHex = await this.retrieveRawTransaction(inputPrevTxid);
const inputPrevTx: Transaction = Transaction.parseFromBuffer(inputPrevTxHex);
let inputSlpMsg;
try {
inputSlpMsg = Slp.parseSlpOutputScript(inputTx.outputs[0].scriptPubKey);
inputSlpMsg = Slp.parseSlpOutputScript(inputPrevTx.outputs[0].scriptPubKey);
} catch (_) {}
if (!inputSlpMsg || inputSlpMsg.versionType !== 0x81) {
validation.validity = false;
Expand All @@ -360,23 +361,38 @@ export class ValidatorType1 {
return validation.validity!;
}
// Check that the there is a burned output >0 in the parent txn SLP message
if (inputSlpMsg.transactionType === SlpTransactionType.SEND &&
!inputSlpMsg.sendOutputs![1].gt(0)) {
validation.validity = false;
validation.waiting = false;
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return validation.validity!;
} else if ((inputSlpMsg.transactionType === SlpTransactionType.GENESIS ||
inputSlpMsg.transactionType === SlpTransactionType.MINT) &&
!inputSlpMsg.genesisOrMintQuantity!.gt(0)) {
validation.validity = false;
validation.waiting = false;
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return validation.validity!;
if (inputSlpMsg.transactionType === SlpTransactionType.SEND) {
if (inputPrevOut > inputSlpMsg.sendOutputs!.length - 1) {
validation.validity = false;
validation.waiting = false;
validation.invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input.";
return validation.validity!;
}
if (! inputSlpMsg.sendOutputs![inputPrevOut].gt(0)) {
validation.validity = false;
validation.waiting = false;
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return validation.validity!;
}
} else if (inputSlpMsg.transactionType === SlpTransactionType.GENESIS ||
inputSlpMsg.transactionType === SlpTransactionType.MINT) {
if (inputPrevOut !== 1) {
validation.validity = false;
validation.waiting = false;
validation.invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input.";
return validation.validity!;
}
if (!inputSlpMsg.genesisOrMintQuantity!.gt(0)) {
validation.validity = false;
validation.waiting = false;
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
return validation.validity!;
}
}

// Continue to check the NFT1 parent DAG
const nft_parent_dag_validity = await this.isValidSlpTxid({
txid: inputTxid,
txid: inputPrevTxid,
tokenIdFilter: undefined,
tokenTypeFilter: 0x81
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

0 comments on commit 3963cf9

Please # to comment.