mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(tokenUtxoDetails): Catching and invalidating malformed SLP OP_RETURNs
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@
|
||||
"test:temp": "RESTURL=https://bchn.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/",
|
||||
"test:temp2": "RESTURL=https://abc.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/",
|
||||
"test:temp3": "ISBCHN=true RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/",
|
||||
"test:temp4": "mocha --trace-warnings --unhandled-rejections=strict -g '#SLP Utils' test/unit/",
|
||||
"test:temp4": "mocha --timeout=30000 -g '#tokenUtxoDetails' test/unit/",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/ -o docs"
|
||||
|
||||
+12
-4
@@ -1111,9 +1111,9 @@ class Utils {
|
||||
let slpData = false
|
||||
try {
|
||||
slpData = await this.decodeOpReturn(utxo.txid, decodeOpReturnCache)
|
||||
// console.log(`slpData: ${JSON.stringify(slpData, null, 2)}`)
|
||||
console.log(`slpData: ${JSON.stringify(slpData, null, 2)}`)
|
||||
} catch (err) {
|
||||
// console.log(`error from decodeOpReturn(${utxo.txid}): `, err)
|
||||
console.log(`error from decodeOpReturn(${utxo.txid}): `, err)
|
||||
|
||||
// An error will be thrown if the txid is not SLP.
|
||||
// If error is for some other reason, like a 429 error, mark utxo as 'null'
|
||||
@@ -1121,9 +1121,13 @@ class Utils {
|
||||
if (
|
||||
!err.message ||
|
||||
(err.message.indexOf("scriptpubkey not op_return") === -1 &&
|
||||
err.message.indexOf("lokad id") === -1)
|
||||
err.message.indexOf("lokad id") === -1 &&
|
||||
err.message.indexOf("trailing data") === -1)
|
||||
) {
|
||||
// console.log(`error from decodeOpReturn(${utxo.txid}): `, err)
|
||||
console.log(
|
||||
`unknown error from decodeOpReturn(). Marking as 'null'`,
|
||||
err
|
||||
)
|
||||
|
||||
utxo.isValid = null
|
||||
outAry.push(utxo)
|
||||
@@ -1132,8 +1136,10 @@ class Utils {
|
||||
// an SLP UTXO.
|
||||
// Mark as false and continue the loop.
|
||||
} else {
|
||||
console.log("marking as invalid")
|
||||
utxo.isValid = false
|
||||
outAry.push(utxo)
|
||||
console.log(`outAry: ${JSON.stringify(outAry, null, 2)}`)
|
||||
}
|
||||
|
||||
// Halt the execution of the loop and increase to the next index.
|
||||
@@ -1336,6 +1342,8 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`pt2 outAry: ${JSON.stringify(outAry, null, 2)}`)
|
||||
|
||||
return outAry
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
|
||||
@@ -1673,7 +1673,43 @@ describe("#SLP Utils", () => {
|
||||
assert.equal(data[0].isValid, false)
|
||||
})
|
||||
|
||||
it("should invalidate a malformed SLP OP_RETURN", async () => {
|
||||
sandbox
|
||||
.stub(uut.Utils, "decodeOpReturn")
|
||||
.rejects(new Error("trailing data"))
|
||||
|
||||
const utxos = [
|
||||
// Malformed SLP tx
|
||||
{
|
||||
note: "Malformed SLP tx",
|
||||
tx_hash:
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
}
|
||||
]
|
||||
|
||||
const data = await uut.Utils.tokenUtxoDetails(utxos)
|
||||
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
|
||||
assert.equal(data[0].isValid, false)
|
||||
})
|
||||
|
||||
// it("should validate against the whitelist SLPDB when regular SLPDB returns null", async () => {
|
||||
// const utxos = [
|
||||
// // Malformed SLP tx
|
||||
// {
|
||||
// note: "Malformed SLP tx",
|
||||
// tx_hash:
|
||||
// "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
// tx_pos: 1,
|
||||
// value: 546
|
||||
// }
|
||||
// ]
|
||||
//
|
||||
// const data = await uut.Utils.tokenUtxoDetails(utxos)
|
||||
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
// })
|
||||
})
|
||||
|
||||
describe("#txDetails", () => {
|
||||
|
||||
Reference in New Issue
Block a user