Skip to content

Commit

Permalink
fix(tokenUtxoDetails2()): Now handles Genesis transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
christroutner committed Jun 1, 2020
1 parent 7cd23ca commit 5fc0d4b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/slp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,12 @@ class Utils {

// If this is a valid SLP UTXO, then return the decoded OP_RETURN data.
else {
utxo.tokenType = "minting-baton"
// Minting Baton
if (utxo.vout === slpData.mintBatonVout)
utxo.tokenType = "minting-baton"
// Tokens
else utxo.tokenType = "token"

utxo.tokenId = utxo.txid
utxo.tokenTicker = slpData.ticker
utxo.tokenName = slpData.name
Expand Down
73 changes: 68 additions & 5 deletions test/unit/slp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1958,11 +1958,10 @@ describe("#SLP Utils", () => {

it("should return false for BCH-only UTXOs", async () => {
// Mock live network calls
if (process.env.TEST === "unit") {
sandbox
.stub(slp.Utils, "decodeOpReturn2")
.throws(new Error("scriptpubkey not op_return"))
}

sandbox
.stub(slp.Utils, "decodeOpReturn2")
.throws(new Error("scriptpubkey not op_return"))

const utxos = [
{
Expand Down Expand Up @@ -1992,6 +1991,70 @@ describe("#SLP Utils", () => {
assert2.equal(false, data[0])
assert2.equal(false, data[1])
})

it("should decode a Genesis transaction", async () => {
const slpData = {
tokenType: 1,
txType: "GENESIS",
ticker: "SLPTEST",
name: "SLP Test Token",
tokenId:
"d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954",
documentUri: "https://FullStack.cash",
documentHash: "",
decimals: 8,
mintBatonVout: 2,
qty: "10000000000"
}

// Mock external dependencies.
// Stub the calls to decodeOpReturn.
sandbox.stub(slp.Utils, "decodeOpReturn2").resolves(slpData)

// Stub the call to validateTxid
sandbox.stub(slp.Utils, "validateTxid").resolves([
{
txid:
"d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954",
valid: true
}
])

const utxos = [
{
txid:
"d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954",
vout: 1,
value: "546",
confirmations: 0,
satoshis: 546
},
{
txid:
"d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954",
vout: 2,
value: "546",
confirmations: 0,
satoshis: 546
},
{
txid:
"d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954",
vout: 3,
value: "12178",
confirmations: 0,
satoshis: 12178
}
]

const data = await slp.Utils.tokenUtxoDetails2(utxos)
// console.log(`data: ${JSON.stringify(data, null, 2)}`)

assert2.isArray(data)
assert2.equal(data[0].tokenType, "token")
assert2.equal(data[1].tokenType, "minting-baton")
assert2.equal(false, data[2])
})
})

describe("#txDetails", () => {
Expand Down

0 comments on commit 5fc0d4b

Please sign in to comment.