Skip to content

Commit

Permalink
Merge pull request #42 from christroutner/unstable
Browse files Browse the repository at this point in the history
fix(documentation): Adding documentation for NFT tokens
  • Loading branch information
christroutner authored Jun 6, 2020
2 parents 7339383 + c05699d commit 5d29c65
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 2 deletions.
192 changes: 191 additions & 1 deletion src/slp/nft1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,37 @@ class TokenType1 {
TransactionBuilder.setAddress(addy)
}

// New NFT Group 'Parent'
/**
* @api SLP.NFT1.newNFTGroupOpReturn() newNFTGroupOpReturn()
* @apiName newNFTGroupOpReturn
* @apiGroup SLP NFT1
* @apiDescription Generate the OP_RETURN value needed to create an SLP
* NFT Group token.
* It's assumed all elements in the tokenUtxos array belong to the same token.
*
* Returns a Buffer representing a transaction output, ready to be added to
* the Transaction Builder.
*
* @apiExample Example usage:
*
* const configObj = {
* name: "SLP Test Token",
* ticker: "SLPTEST",
* documentUrl: "https://FullStack.cash",
* }
*
* const result = await bchjs.SLP.NFT1.newNFTGroupOpReturn(
* configObj
* )
*
* ...
* // Add OP_RETURN as first output.
* transactionBuilder.addOutput(slpData, 0);
*
* // See additional code here:
* // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft
*
*/
newNFTGroupOpReturn(configObj) {
try {
// TODO: Add input validation.
Expand Down Expand Up @@ -56,6 +86,49 @@ class TokenType1 {
}

// Mint additional NFT Group 'Parent' tokens.
/**
* @api SLP.NFT1.mintNFTGroupOpReturn() mintNFTGroupOpReturn()
* @apiName mintNFTGroupOpReturn
* @apiGroup SLP NFT1
* @apiDescription Generate the OP_RETURN value needed to create an SLP Mint
* transaction for an NFT Group token.
* It's assumed all elements in the tokenUtxos array belong to the same token.
*
* Returns a Buffer representing a transaction output, ready to be added to
* the Transaction Builder.
*
* @apiExample Example usage:
*
* const addr = "bitcoincash:qq6xz6wwcy78uh79vgjvfyahj4arq269w5an8pcjak"
* const utxos = await bchjs.Blockbook.utxos(addr)
*
* // Identify the SLP token UTXOs.
* let tokenUtxos = await bchjs.SLP.Utils.tokenUtxoDetails(utxos);
*
* // Filter out the minting baton.
* tokenUtxos = tokenUtxos.filter((utxo, index) => {
* if (
* utxo && // UTXO is associated with a token.
* utxo.tokenId === TOKENID && // UTXO matches the token ID.
* utxo.utxoType === "minting-baton" && // UTXO is not a minting baton.
* utxo.tokenType === 129 // UTXO is for NFT Group
* )
* return true;
* });
*
* // Generate the SLP OP_RETURN
* const slpData = bchjs.SLP.NFT1.mintNFTGroupOpReturn(
* tokenUtxos,
* 1 // Mint 1 new token.
* );
*
* ...
* // Add OP_RETURN as first output.
* transactionBuilder.addOutput(slpData, 0);
*
* // See additional code here:
* // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft
*/
mintNFTGroupOpReturn(tokenUtxos, mintQty, destroyBaton = false) {
try {
// Throw error if input is not an array.
Expand Down Expand Up @@ -95,6 +168,37 @@ class TokenType1 {
}
}

/**
* @api SLP.NFT1.generateNFTChildGenesisOpReturn() generateNFTChildGenesisOpReturn()
* @apiName generateNFTChildGenesisOpReturn
* @apiGroup SLP NFT1
* @apiDescription Generate the OP_RETURN value needed to create an SLP
* NFT Child token.
* It's assumed all elements in the tokenUtxos array belong to the same token.
*
* Returns a Buffer representing a transaction output, ready to be added to
* the Transaction Builder.
*
* @apiExample Example usage:
*
* const configObj = {
* name: "NFT Child",
* ticker: "NFTC",
* documentUrl: "https://FullStack.cash",
* }
*
* const result = await bchjs.SLP.NFT1.generateNFTChildGenesisOpReturn(
* configObj
* )
*
* ...
* // Add OP_RETURN as first output.
* transactionBuilder.addOutput(slpData, 0);
*
* // See additional code here:
* // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft
*
*/
generateNFTChildGenesisOpReturn(configObj) {
try {
// TODO: Add input validation.
Expand Down Expand Up @@ -125,6 +229,49 @@ class TokenType1 {
// Generate the OP_RETURN for sending an NFT Child token.
// Assumes all tokenUtxos have the same tokenId in common. It does not filter
// the input.
/**
* @api SLP.NFT1.generateNFTChildSendOpReturn() generateNFTChildSendOpReturn()
* @apiName generateNFTChildSendOpReturn
* @apiGroup SLP NFT1
* @apiDescription Generate the OP_RETURN value needed to send an SLP NFT
* Child token to another address.
* It's assumed all elements in the tokenUtxos array belong to the same token.
*
* Returns a Buffer representing a transaction output, ready to be added to
* the Transaction Builder.
*
* @apiExample Example usage:
*
* const addr = "bitcoincash:qq6xz6wwcy78uh79vgjvfyahj4arq269w5an8pcjak"
* const utxos = await bchjs.Blockbook.utxos(addr)
*
* // Identify the SLP token UTXOs.
* let tokenUtxos = await bchjs.SLP.Utils.tokenUtxoDetails(utxos);
*
* // Filter out the token UTXOs that match the user-provided token ID.
* tokenUtxos = tokenUtxos.filter((utxo, index) => {
* if (
* utxo && // UTXO is associated with a token.
* utxo.tokenId === TOKENID && // UTXO matches the token ID.
* utxo.tokenType === "token" && // UTXO is not a minting baton.
* utxo.tokenType === 65 // UTXO is for an NFT Child
* )
* return true;
* });
*
* // Generate the SEND OP_RETURN
* const slpData = bchjs.SLP.NFT1.generateNFTChildSendOpReturn(
* tokenUtxos,
* TOKENQTY
* );
*
* ...
* // Add OP_RETURN as first output.
* transactionBuilder.addOutput(slpData, 0);
*
* // See additional code here:
* // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft
*/
generateNFTChildSendOpReturn(tokenUtxos, sendQty) {
try {
// TODO: Add input validation.
Expand Down Expand Up @@ -175,6 +322,49 @@ class TokenType1 {
// Generate the OP_RETURN for sending an NFT Group token.
// Assumes all tokenUtxos have the same tokenId in common, it does not filter
// the input.
/**
* @api SLP.NFT1.generateNFTGroupSendOpReturn() generateNFTGroupSendOpReturn()
* @apiName generateNFTGroupSendOpReturn
* @apiGroup SLP NFT1
* @apiDescription Generate the OP_RETURN value needed to send an SLP NFT
* Group token to another address.
* It's assumed all elements in the tokenUtxos array belong to the same token.
*
* Returns a Buffer representing a transaction output, ready to be added to
* the Transaction Builder.
*
* @apiExample Example usage:
*
* const addr = "bitcoincash:qq6xz6wwcy78uh79vgjvfyahj4arq269w5an8pcjak"
* const utxos = await bchjs.Blockbook.utxos(addr)
*
* // Identify the SLP token UTXOs.
* let tokenUtxos = await bchjs.SLP.Utils.tokenUtxoDetails(utxos);
*
* // Filter out the token UTXOs that match the user-provided token ID.
* tokenUtxos = tokenUtxos.filter((utxo, index) => {
* if (
* utxo && // UTXO is associated with a token.
* utxo.tokenId === TOKENID && // UTXO matches the token ID.
* utxo.tokenType === "token" && // UTXO is not a minting baton.
* utxo.tokenType === 129 // UTXO is for an NFT Group
* )
* return true;
* });
*
* // Generate the SEND OP_RETURN
* const slpData = bchjs.SLP.NFT1.generateNFTGroupSendOpReturn(
* tokenUtxos,
* TOKENQTY
* );
*
* ...
* // Add OP_RETURN as first output.
* transactionBuilder.addOutput(slpData, 0);
*
* // See additional code here:
* // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft
*/
generateNFTGroupSendOpReturn(tokenUtxos, sendQty) {
try {
// TODO: Add input validation.
Expand Down
2 changes: 1 addition & 1 deletion src/slp/tokentype1.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class TokenType1 {
* const configObj = {
* name: "SLP Test Token",
* ticker: "SLPTEST",
* documentUrl: "https://bchjs.cash",
* documentUrl: "https://FullStack.cash",
* documentHash: "",
* decimals: 8,
* initialQty: 10
Expand Down

0 comments on commit 5d29c65

Please sign in to comment.