diff --git a/src/slp/tokentype1.js b/src/slp/tokentype1.js index f2a6ce9..969b7c9 100644 --- a/src/slp/tokentype1.js +++ b/src/slp/tokentype1.js @@ -361,6 +361,61 @@ class TokenType1 { throw err } } + + // Parent NFT + generateNFTGenesisOpReturn(configObj) { + try { + // TODO: Add input validation. + + // Prevent error if user fails to add the document hash. + if (!configObj.documentHash) configObj.documentHash = "" + + // If mint baton is not specified, then replace it with null. + if (!configObj.mintBatonVout) configObj.mintBatonVout = null + + const script = slpMdm.NFT1.Group.genesis( + configObj.ticker, + configObj.name, + configObj.documentUrl, + configObj.documentHash, + 0, + configObj.mintBatonVout, + new slpMdm.BN("1") + ) + + return script + } catch (err) { + console.log(`Error in generateNFTGenesisOpReturn()`) + throw err + } + } + + generateNFTChildOpReturn(configObj) { + try { + // TODO: Add input validation. + + // Prevent error if user fails to add the document hash. + if (!configObj.documentHash) configObj.documentHash = "" + + // If mint baton is not specified, then replace it with null. + if (!configObj.mintBatonVout) configObj.mintBatonVout = null + + const script = slpMdm.NFT1.Group.genesis( + configObj.ticker, + configObj.name, + configObj.documentUrl, + configObj.documentHash, + 0, + configObj.mintBatonVout, + new slpMdm.BN("1") + ) + + return script + } catch (err) { + console.log(`Error in generateNFTChildOpReturn()`) + throw err + } + } } module.exports = TokenType1 diff --git a/test/unit/slp-tokentype1.js b/test/unit/slp-tokentype1.js index 626bc52..b7f150d 100644 --- a/test/unit/slp-tokentype1.js +++ b/test/unit/slp-tokentype1.js @@ -413,4 +413,40 @@ describe("#SLP TokenType1", () => { assert.equal(Buffer.isBuffer(result), true) }) }) + + describe("#generateNFTOpReturn", () => { + it("should generate NFT Genesis OP_RETURN code", async () => { + const configObj = { + name: "SLP Test Token", + ticker: "SLPTEST", + documentUrl: "https://bchjs.cash", + documentHash: "" + } + + const result = await bchjs.SLP.TokenType1.generateNFTGenesisOpReturn( + configObj + ) + // console.log(`result: `, result) + + assert.equal(Buffer.isBuffer(result), true) + }) + }) + + describe("#generateNFTChildOpReturn", () => { + it("should generate NFT Genesis OP_RETURN code", async () => { + const configObj = { + name: "SLP Test Token", + ticker: "SLPTEST", + documentUrl: "https://bchjs.cash", + documentHash: "" + } + + const result = await bchjs.SLP.TokenType1.generateNFTChildOpReturn( + configObj + ) + // console.log(`result: `, result) + + assert.equal(Buffer.isBuffer(result), true) + }) + }) })