fix(NFT): Prototyping NFT generation

This commit is contained in:
Chris Troutner
2020-06-04 17:33:07 -07:00
parent adf5b60ac7
commit ffedaed08a
2 changed files with 91 additions and 0 deletions
+55
View File
@@ -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
+36
View File
@@ -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)
})
})
})