Skip to content

Commit

Permalink
fix(SLP Genesis and Burn): Using slp-mdm for Genesis and Burn OP_RETURNS
Browse files Browse the repository at this point in the history
  • Loading branch information
christroutner committed Jun 1, 2020
1 parent 119ef1b commit a1b1a19
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
81 changes: 46 additions & 35 deletions src/slp/tokentype1.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,26 @@ class TokenType1 {
let baseQty = new BigNumber(remainder).times(10 ** decimals)
baseQty = baseQty.absoluteValue()
baseQty = Math.floor(baseQty)
let baseQtyHex = baseQty.toString(16)
baseQtyHex = baseQtyHex.padStart(16, "0")
baseQty = baseQty.toString()

// console.log(`baseQty: ${baseQty.toString()}`)

const script = [
this.Script.opcodes.OP_RETURN,
Buffer.from("534c5000", "hex"),
//BITBOX.Script.opcodes.OP_1,
Buffer.from("01", "hex"),
Buffer.from(`SEND`),
Buffer.from(tokenId, "hex"),
Buffer.from(baseQtyHex, "hex")
]
// const script = [
// this.Script.opcodes.OP_RETURN,
// Buffer.from("534c5000", "hex"),
// //BITBOX.Script.opcodes.OP_1,
// Buffer.from("01", "hex"),
// Buffer.from(`SEND`),
// Buffer.from(tokenId, "hex"),
// Buffer.from(baseQtyHex, "hex")
// ]

// Generate the OP_RETURN as a Buffer.
const script = slpMdm.TokenType1.send(tokenId, [new slpMdm.BN(baseQty)])

return script
} catch (err) {
console.log(`Error in generateSendOpReturn()`)
console.log(`Error in generateBurnOpReturn()`)
throw err
}
}
Expand All @@ -268,6 +270,7 @@ class TokenType1 {
* ticker: (string) ticker symbol for the new token class.
* name: (string) name of the token.
* documentUrl: (string) a website url that you'd like to attach to the token.
* documentHash: (string) optional.
* }
*
* Note: document hash is currently not supported.
Expand All @@ -276,34 +279,42 @@ class TokenType1 {
try {
// TODO: Add input validation.

let decimals = configObj.decimals.toString(16)
decimals = decimals.padStart(2, "0")

let baseQty = new BigNumber(configObj.initialQty).times(
10 ** configObj.decimals
)
baseQty = baseQty.absoluteValue()
baseQty = Math.floor(baseQty)
let baseQtyHex = baseQty.toString(16)
baseQtyHex = baseQtyHex.padStart(16, "0")

const script = [
this.Script.opcodes.OP_RETURN,
Buffer.from("534c5000", "hex"), // Lokad ID
Buffer.from("01", "hex"), // Token Type 1
Buffer.from(`GENESIS`),
Buffer.from(configObj.ticker),
Buffer.from(configObj.name),
Buffer.from(configObj.documentUrl),

// Create an empty document hash.
this.Script.opcodes.OP_PUSHDATA1, // Hex 4c
this.Script.opcodes.OP_0, // Hex 00

Buffer.from(decimals, "hex"),
Buffer.from("02", "hex"), // Mint baton vout
Buffer.from(baseQtyHex, "hex")
]
baseQty = baseQty.toString()
// let baseQtyHex = baseQty.toString(16)
// baseQtyHex = baseQtyHex.padStart(16, "0")

const script = slpMdm.TokenType1.genesis(
configObj.ticker,
configObj.name,
configObj.documentUrl,
configObj.documentHash,
configObj.decimals,
null,
new slpMdm.BN(baseQty)
)

// const script = [
// this.Script.opcodes.OP_RETURN,
// Buffer.from("534c5000", "hex"), // Lokad ID
// Buffer.from("01", "hex"), // Token Type 1
// Buffer.from(`GENESIS`),
// Buffer.from(configObj.ticker),
// Buffer.from(configObj.name),
// Buffer.from(configObj.documentUrl),
//
// // Create an empty document hash.
// this.Script.opcodes.OP_PUSHDATA1, // Hex 4c
// this.Script.opcodes.OP_0, // Hex 00
//
// Buffer.from(decimals, "hex"),
// Buffer.from("02", "hex"), // Mint baton vout
// Buffer.from(baseQtyHex, "hex")
// ]

return script
} catch (err) {
Expand Down
8 changes: 5 additions & 3 deletions test/unit/slp-tokentype1.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ describe("#SLP TokenType1", () => {
1
)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
// console.log(`result: `, result)

assert.isArray(result)
assert.equal(Buffer.isBuffer(result), true)
})
})

Expand All @@ -232,16 +233,17 @@ describe("#SLP TokenType1", () => {
name: "SLP Test Token",
ticker: "SLPTEST",
documentUrl: "https://bchjs.cash",
documentHash: "",
decimals: 8,
initialQty: 10
}

const result = await bchjs.SLP.TokenType1.generateGenesisOpReturn(
configObj
)
// console.log(`result: `, result)

assert.isArray(result)
assert.equal(Buffer.isBuffer(result[1]), true)
assert.equal(Buffer.isBuffer(result), true)
})
})
})

0 comments on commit a1b1a19

Please sign in to comment.