mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
fix(nock): Fixed failing tests mocked with nock
This commit is contained in:
Generated
+2
-202
@@ -731,15 +731,6 @@
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
|
||||
},
|
||||
"abstract-leveldown": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.0.3.tgz",
|
||||
"integrity": "sha512-jzewKKpZbaYUa6HTThnrl+GrJhzjEAeuc7hTVpZdzg7kupXZFoqQDFwyOwLNbmJKJlmzw8yiipMPkDiuKkT06Q==",
|
||||
"requires": {
|
||||
"level-concat-iterator": "~2.0.0",
|
||||
"xtend": "~4.0.0"
|
||||
}
|
||||
},
|
||||
"accepts": {
|
||||
"version": "1.3.7",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
|
||||
@@ -3172,27 +3163,6 @@
|
||||
"strip-bom": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"deferred-leveldown": {
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-5.3.0.tgz",
|
||||
"integrity": "sha512-a59VOT+oDy7vtAbLRCZwWgxu2BaCfd5Hk7wxJd48ei7I+nsg8Orlb9CLG0PMZienk9BSUKgeAqkO2+Lw+1+Ukw==",
|
||||
"requires": {
|
||||
"abstract-leveldown": "~6.2.1",
|
||||
"inherits": "^2.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"abstract-leveldown": {
|
||||
"version": "6.2.2",
|
||||
"resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.2.tgz",
|
||||
"integrity": "sha512-/a+Iwj0rn//CX0EJOasNyZJd2o8xur8Ce9C57Sznti/Ilt/cb6Qd8/k98A4ZOklXgTG+iAYYUs1OTG0s1eH+zQ==",
|
||||
"requires": {
|
||||
"level-concat-iterator": "~2.0.0",
|
||||
"level-supports": "~1.0.0",
|
||||
"xtend": "~4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"define-properties": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
|
||||
@@ -3512,29 +3482,6 @@
|
||||
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
|
||||
},
|
||||
"encoding-down": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-6.3.0.tgz",
|
||||
"integrity": "sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==",
|
||||
"requires": {
|
||||
"abstract-leveldown": "^6.2.1",
|
||||
"inherits": "^2.0.3",
|
||||
"level-codec": "^9.0.0",
|
||||
"level-errors": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"abstract-leveldown": {
|
||||
"version": "6.2.2",
|
||||
"resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.2.tgz",
|
||||
"integrity": "sha512-/a+Iwj0rn//CX0EJOasNyZJd2o8xur8Ce9C57Sznti/Ilt/cb6Qd8/k98A4ZOklXgTG+iAYYUs1OTG0s1eH+zQ==",
|
||||
"requires": {
|
||||
"level-concat-iterator": "~2.0.0",
|
||||
"level-supports": "~1.0.0",
|
||||
"xtend": "~4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"end-of-stream": {
|
||||
"version": "1.4.4",
|
||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
|
||||
@@ -3722,14 +3669,6 @@
|
||||
"resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz",
|
||||
"integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA=="
|
||||
},
|
||||
"errno": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz",
|
||||
"integrity": "sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg==",
|
||||
"requires": {
|
||||
"prr": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"error-ex": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz",
|
||||
@@ -6449,11 +6388,6 @@
|
||||
"integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=",
|
||||
"dev": true
|
||||
},
|
||||
"immediate": {
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.2.3.tgz",
|
||||
"integrity": "sha1-0UD6j2FGWb1lQSMwl92qwlzdmRw="
|
||||
},
|
||||
"import-fresh": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.1.0.tgz",
|
||||
@@ -6910,7 +6844,8 @@
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=",
|
||||
"dev": true
|
||||
},
|
||||
"is-unc-path": {
|
||||
"version": "1.0.0",
|
||||
@@ -7198,108 +7133,6 @@
|
||||
"integrity": "sha1-GwuP+ayceIklBYK3C3ExXZ2m2aM=",
|
||||
"dev": true
|
||||
},
|
||||
"level": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level/-/level-5.0.1.tgz",
|
||||
"integrity": "sha512-wcak5OQeA4rURGacqS62R/xNHjCYnJSQDBOlm4KNUGJVE9bWv2B04TclqReYejN+oD65PzD4FsqeWoI5wNC5Lg==",
|
||||
"requires": {
|
||||
"level-js": "^4.0.0",
|
||||
"level-packager": "^5.0.0",
|
||||
"leveldown": "^5.0.0",
|
||||
"opencollective-postinstall": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"level-codec": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-codec/-/level-codec-9.0.1.tgz",
|
||||
"integrity": "sha512-ajFP0kJ+nyq4i6kptSM+mAvJKLOg1X5FiFPtLG9M5gCEZyBmgDi3FkDrvlMkEzrUn1cWxtvVmrvoS4ASyO/q+Q=="
|
||||
},
|
||||
"level-concat-iterator": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz",
|
||||
"integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw=="
|
||||
},
|
||||
"level-errors": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-errors/-/level-errors-2.0.1.tgz",
|
||||
"integrity": "sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==",
|
||||
"requires": {
|
||||
"errno": "~0.1.1"
|
||||
}
|
||||
},
|
||||
"level-iterator-stream": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-4.0.2.tgz",
|
||||
"integrity": "sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==",
|
||||
"requires": {
|
||||
"inherits": "^2.0.4",
|
||||
"readable-stream": "^3.4.0",
|
||||
"xtend": "^4.0.2"
|
||||
}
|
||||
},
|
||||
"level-js": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-js/-/level-js-4.0.1.tgz",
|
||||
"integrity": "sha512-m5JRIyHZn5VnCCFeRegJkn5bQd3MJK5qZX12zg3Oivc8+BUIS2yFS6ANMMeHX2ieGxucNvEn6/ZnyjmZQLLUWw==",
|
||||
"requires": {
|
||||
"abstract-leveldown": "~6.0.1",
|
||||
"immediate": "~3.2.3",
|
||||
"inherits": "^2.0.3",
|
||||
"ltgt": "^2.1.2",
|
||||
"typedarray-to-buffer": "~3.1.5"
|
||||
}
|
||||
},
|
||||
"level-packager": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/level-packager/-/level-packager-5.1.0.tgz",
|
||||
"integrity": "sha512-3pbJmDgGvp/lUQNULPoYQZtUbhMI8KoViYDw7Sa0kWl1mPeHWWJF7T/9upWI/NTMuEikkEE/cd6wBvmrW1+ZnQ==",
|
||||
"requires": {
|
||||
"encoding-down": "^6.3.0",
|
||||
"levelup": "^4.3.2"
|
||||
}
|
||||
},
|
||||
"level-supports": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz",
|
||||
"integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==",
|
||||
"requires": {
|
||||
"xtend": "^4.0.2"
|
||||
}
|
||||
},
|
||||
"leveldown": {
|
||||
"version": "5.4.1",
|
||||
"resolved": "https://registry.npmjs.org/leveldown/-/leveldown-5.4.1.tgz",
|
||||
"integrity": "sha512-3lMPc7eU3yj5g+qF1qlALInzIYnkySIosR1AsUKFjL9D8fYbTLuENBAeDRZXIG4qeWOAyqRItOoLu2v2avWiMA==",
|
||||
"requires": {
|
||||
"abstract-leveldown": "~6.2.1",
|
||||
"napi-macros": "~2.0.0",
|
||||
"node-gyp-build": "~4.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"abstract-leveldown": {
|
||||
"version": "6.2.2",
|
||||
"resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.2.tgz",
|
||||
"integrity": "sha512-/a+Iwj0rn//CX0EJOasNyZJd2o8xur8Ce9C57Sznti/Ilt/cb6Qd8/k98A4ZOklXgTG+iAYYUs1OTG0s1eH+zQ==",
|
||||
"requires": {
|
||||
"level-concat-iterator": "~2.0.0",
|
||||
"level-supports": "~1.0.0",
|
||||
"xtend": "~4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"levelup": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/levelup/-/levelup-4.3.2.tgz",
|
||||
"integrity": "sha512-cRTjU4ktWo59wf13PHEiOayHC3n0dOh4i5+FHr4tv4MX9+l7mqETicNq3Aj07HKlLdk0z5muVoDL2RD+ovgiyA==",
|
||||
"requires": {
|
||||
"deferred-leveldown": "~5.3.0",
|
||||
"level-errors": "~2.0.0",
|
||||
"level-iterator-stream": "~4.0.0",
|
||||
"level-supports": "~1.0.0",
|
||||
"xtend": "~4.0.0"
|
||||
}
|
||||
},
|
||||
"leven": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/leven/-/leven-2.1.0.tgz",
|
||||
@@ -7489,11 +7322,6 @@
|
||||
"yallist": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"ltgt": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz",
|
||||
"integrity": "sha1-81ypHEk/e3PaDgdJUwTxezH4fuU="
|
||||
},
|
||||
"macos-release": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.3.0.tgz",
|
||||
@@ -8033,11 +7861,6 @@
|
||||
"to-regex": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"napi-macros": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.0.0.tgz",
|
||||
"integrity": "sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg=="
|
||||
},
|
||||
"natural-compare": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
|
||||
@@ -8159,11 +7982,6 @@
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==",
|
||||
"dev": true
|
||||
},
|
||||
"node-gyp-build": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz",
|
||||
"integrity": "sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ=="
|
||||
},
|
||||
"node-mocks-http": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/node-mocks-http/-/node-mocks-http-1.8.0.tgz",
|
||||
@@ -11951,11 +11769,6 @@
|
||||
"mimic-fn": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"opencollective-postinstall": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz",
|
||||
"integrity": "sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw=="
|
||||
},
|
||||
"optimist": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
|
||||
@@ -12578,11 +12391,6 @@
|
||||
"resolve": "^1.11.1"
|
||||
}
|
||||
},
|
||||
"prr": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
|
||||
"integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY="
|
||||
},
|
||||
"pseudomap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||
@@ -14827,14 +14635,6 @@
|
||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
||||
},
|
||||
"typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"requires": {
|
||||
"is-typedarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"typeforce": {
|
||||
"version": "1.18.0",
|
||||
"resolved": "https://registry.npmjs.org/typeforce/-/typeforce-1.18.0.tgz",
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
"express-basic-auth": "^1.1.3",
|
||||
"express-rate-limit": "^5.0.0",
|
||||
"helmet": "^3.21.2",
|
||||
"level": "^5.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^6.1.4",
|
||||
"morgan": "^1.9.1",
|
||||
|
||||
+263
-435
@@ -21,8 +21,8 @@ const slpjs = new slp.Slp(SLP)
|
||||
const utils = slp.Utils
|
||||
|
||||
// SLP tx db (LevelDB for caching)
|
||||
const level = require("level")
|
||||
const slpTxDb = level("./slp-tx-db")
|
||||
// const level = require("level")
|
||||
// const slpTxDb = level("./slp-tx-db")
|
||||
|
||||
// Setup JSON RPC
|
||||
const BitboxHTTP = axios.create({
|
||||
@@ -53,101 +53,101 @@ router.get("/txDetails/:txid", txDetails)
|
||||
router.get("/tokenStats/:tokenId", tokenStats)
|
||||
router.get("/transactions/:tokenId/:address", txsTokenIdAddressSingle)
|
||||
|
||||
if (process.env.NON_JS_FRAMEWORK && process.env.NON_JS_FRAMEWORK === "true") {
|
||||
router.get(
|
||||
"/createTokenType1/:fundingAddress/:fundingWif/:tokenReceiverAddress/:batonReceiverAddress/:bchChangeReceiverAddress/:decimals/:name/:symbol/:documentUri/:documentHash/:initialTokenQty",
|
||||
createTokenType1
|
||||
)
|
||||
router.get(
|
||||
"/mintTokenType1/:fundingAddress/:fundingWif/:tokenReceiverAddress/:batonReceiverAddress/:bchChangeReceiverAddress/:tokenId/:additionalTokenQty",
|
||||
mintTokenType1
|
||||
)
|
||||
router.get(
|
||||
"/sendTokenType1/:fundingAddress/:fundingWif/:tokenReceiverAddress/:bchChangeReceiverAddress/:tokenId/:amount",
|
||||
sendTokenType1
|
||||
)
|
||||
router.get(
|
||||
"/burnTokenType1/:fundingAddress/:fundingWif/:bchChangeReceiverAddress/:tokenId/:amount",
|
||||
burnTokenType1
|
||||
)
|
||||
router.get(
|
||||
"/burnAllTokenType1/:fundingAddress/:fundingWif/:bchChangeReceiverAddress/:tokenId",
|
||||
burnAllTokenType1
|
||||
)
|
||||
}
|
||||
// if (process.env.NON_JS_FRAMEWORK && process.env.NON_JS_FRAMEWORK === "true") {
|
||||
// router.get(
|
||||
// "/createTokenType1/:fundingAddress/:fundingWif/:tokenReceiverAddress/:batonReceiverAddress/:bchChangeReceiverAddress/:decimals/:name/:symbol/:documentUri/:documentHash/:initialTokenQty",
|
||||
// createTokenType1
|
||||
// )
|
||||
// router.get(
|
||||
// "/mintTokenType1/:fundingAddress/:fundingWif/:tokenReceiverAddress/:batonReceiverAddress/:bchChangeReceiverAddress/:tokenId/:additionalTokenQty",
|
||||
// mintTokenType1
|
||||
// )
|
||||
// router.get(
|
||||
// "/sendTokenType1/:fundingAddress/:fundingWif/:tokenReceiverAddress/:bchChangeReceiverAddress/:tokenId/:amount",
|
||||
// sendTokenType1
|
||||
// )
|
||||
// router.get(
|
||||
// "/burnTokenType1/:fundingAddress/:fundingWif/:bchChangeReceiverAddress/:tokenId/:amount",
|
||||
// burnTokenType1
|
||||
// )
|
||||
// router.get(
|
||||
// "/burnAllTokenType1/:fundingAddress/:fundingWif/:bchChangeReceiverAddress/:tokenId",
|
||||
// burnAllTokenType1
|
||||
// )
|
||||
// }
|
||||
|
||||
// Retrieve raw transactions details from the full node.
|
||||
// TODO: move this function to a separate support library.
|
||||
// TODO: Add unit tests for this function.
|
||||
async function getRawTransactionsFromNode(txids) {
|
||||
try {
|
||||
const {
|
||||
BitboxHTTP,
|
||||
username,
|
||||
password,
|
||||
requestConfig
|
||||
} = routeUtils.setEnvVars()
|
||||
|
||||
const txPromises = txids.map(async txid => {
|
||||
// Check slpTxDb
|
||||
try {
|
||||
if (slpTxDb.isOpen()) {
|
||||
const rawTx = await slpTxDb.get(txid)
|
||||
return rawTx
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
requestConfig.data.id = "getrawtransaction"
|
||||
requestConfig.data.method = "getrawtransaction"
|
||||
requestConfig.data.params = [txid, 0]
|
||||
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
const result = response.data.result
|
||||
|
||||
// Insert to slpTxDb
|
||||
try {
|
||||
if (slpTxDb.isOpen()) await slpTxDb.put(txid, result)
|
||||
} catch (err) {
|
||||
// console.log("Error inserting to slpTxDb", err)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
const results = await axios.all(txPromises)
|
||||
return results
|
||||
} catch (err) {
|
||||
wlogger.error(`Error in slp.ts/getRawTransactionsFromNode().`, err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
// async function getRawTransactionsFromNode(txids) {
|
||||
// try {
|
||||
// const {
|
||||
// BitboxHTTP,
|
||||
// username,
|
||||
// password,
|
||||
// requestConfig
|
||||
// } = routeUtils.setEnvVars()
|
||||
//
|
||||
// const txPromises = txids.map(async txid => {
|
||||
// // Check slpTxDb
|
||||
// try {
|
||||
// if (slpTxDb.isOpen()) {
|
||||
// const rawTx = await slpTxDb.get(txid)
|
||||
// return rawTx
|
||||
// }
|
||||
// } catch (err) {}
|
||||
//
|
||||
// requestConfig.data.id = "getrawtransaction"
|
||||
// requestConfig.data.method = "getrawtransaction"
|
||||
// requestConfig.data.params = [txid, 0]
|
||||
//
|
||||
// const response = await BitboxHTTP(requestConfig)
|
||||
// const result = response.data.result
|
||||
//
|
||||
// // Insert to slpTxDb
|
||||
// try {
|
||||
// if (slpTxDb.isOpen()) await slpTxDb.put(txid, result)
|
||||
// } catch (err) {
|
||||
// // console.log("Error inserting to slpTxDb", err)
|
||||
// }
|
||||
//
|
||||
// return result
|
||||
// })
|
||||
//
|
||||
// const results = await axios.all(txPromises)
|
||||
// return results
|
||||
// } catch (err) {
|
||||
// wlogger.error(`Error in slp.ts/getRawTransactionsFromNode().`, err)
|
||||
// throw err
|
||||
// }
|
||||
// }
|
||||
|
||||
// Create a validator for validating SLP transactions.
|
||||
function createValidator(network, getRawTransactions = null) {
|
||||
let tmpSLP
|
||||
|
||||
if (network === "mainnet")
|
||||
tmpSLP = new SLPSDK({ restURL: process.env.REST_URL })
|
||||
else tmpSLP = new SLPSDK({ restURL: process.env.TREST_URL })
|
||||
|
||||
const slpValidator = new slp.LocalValidator(
|
||||
tmpSLP,
|
||||
getRawTransactions
|
||||
? getRawTransactions
|
||||
: tmpSLP.RawTransactions.getRawTransaction.bind(this)
|
||||
)
|
||||
|
||||
return slpValidator
|
||||
}
|
||||
// function createValidator(network, getRawTransactions = null) {
|
||||
// let tmpSLP
|
||||
//
|
||||
// if (network === "mainnet")
|
||||
// tmpSLP = new SLPSDK({ restURL: process.env.REST_URL })
|
||||
// else tmpSLP = new SLPSDK({ restURL: process.env.TREST_URL })
|
||||
//
|
||||
// const slpValidator = new slp.LocalValidator(
|
||||
// tmpSLP,
|
||||
// getRawTransactions
|
||||
// ? getRawTransactions
|
||||
// : tmpSLP.RawTransactions.getRawTransaction.bind(this)
|
||||
// )
|
||||
//
|
||||
// return slpValidator
|
||||
// }
|
||||
|
||||
// Instantiate the local SLP validator.
|
||||
const slpValidator = createValidator(
|
||||
process.env.NETWORK,
|
||||
getRawTransactionsFromNode
|
||||
)
|
||||
// const slpValidator = createValidator(
|
||||
// process.env.NETWORK,
|
||||
// getRawTransactionsFromNode
|
||||
// )
|
||||
|
||||
// Instantiate the bitboxproxy class in SLPJS.
|
||||
const bitboxproxy = new slp.BitboxNetwork(SLP, slpValidator)
|
||||
// const bitboxproxy = new slp.BitboxNetwork(SLP, slpValidator)
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
@@ -160,44 +160,45 @@ const requestConfig = {
|
||||
}
|
||||
}
|
||||
|
||||
function formatTokenOutput(token) {
|
||||
token.tokenDetails.id = token.tokenDetails.tokenIdHex
|
||||
delete token.tokenDetails.tokenIdHex
|
||||
token.tokenDetails.documentHash = token.tokenDetails.documentSha256Hex
|
||||
delete token.tokenDetails.documentSha256Hex
|
||||
token.tokenDetails.initialTokenQty = parseFloat(
|
||||
token.tokenDetails.genesisOrMintQuantity
|
||||
)
|
||||
delete token.tokenDetails.genesisOrMintQuantity
|
||||
delete token.tokenDetails.transactionType
|
||||
delete token.tokenDetails.batonVout
|
||||
delete token.tokenDetails.sendOutputs
|
||||
|
||||
token.tokenDetails.blockCreated = token.tokenStats.block_created
|
||||
token.tokenDetails.blockLastActiveSend =
|
||||
token.tokenStats.block_last_active_send
|
||||
token.tokenDetails.blockLastActiveMint =
|
||||
token.tokenStats.block_last_active_mint
|
||||
token.tokenDetails.txnsSinceGenesis =
|
||||
token.tokenStats.qty_valid_txns_since_genesis
|
||||
token.tokenDetails.validAddresses = token.tokenStats.qty_valid_token_addresses
|
||||
token.tokenDetails.totalMinted = parseFloat(token.tokenStats.qty_token_minted)
|
||||
token.tokenDetails.totalBurned = parseFloat(token.tokenStats.qty_token_burned)
|
||||
token.tokenDetails.circulatingSupply = parseFloat(
|
||||
token.tokenStats.qty_token_circulating_supply
|
||||
)
|
||||
token.tokenDetails.mintingBatonStatus = token.tokenStats.minting_baton_status
|
||||
|
||||
delete token.tokenStats.block_last_active_send
|
||||
delete token.tokenStats.block_last_active_mint
|
||||
delete token.tokenStats.qty_valid_txns_since_genesis
|
||||
delete token.tokenStats.qty_valid_token_addresses
|
||||
return token
|
||||
}
|
||||
// function formatTokenOutput(token) {
|
||||
// token.tokenDetails.id = token.tokenDetails.tokenIdHex
|
||||
// delete token.tokenDetails.tokenIdHex
|
||||
// token.tokenDetails.documentHash = token.tokenDetails.documentSha256Hex
|
||||
// delete token.tokenDetails.documentSha256Hex
|
||||
// token.tokenDetails.initialTokenQty = parseFloat(
|
||||
// token.tokenDetails.genesisOrMintQuantity
|
||||
// )
|
||||
// delete token.tokenDetails.genesisOrMintQuantity
|
||||
// delete token.tokenDetails.transactionType
|
||||
// delete token.tokenDetails.batonVout
|
||||
// delete token.tokenDetails.sendOutputs
|
||||
//
|
||||
// token.tokenDetails.blockCreated = token.tokenStats.block_created
|
||||
// token.tokenDetails.blockLastActiveSend =
|
||||
// token.tokenStats.block_last_active_send
|
||||
// token.tokenDetails.blockLastActiveMint =
|
||||
// token.tokenStats.block_last_active_mint
|
||||
// token.tokenDetails.txnsSinceGenesis =
|
||||
// token.tokenStats.qty_valid_txns_since_genesis
|
||||
// token.tokenDetails.validAddresses = token.tokenStats.qty_valid_token_addresses
|
||||
// token.tokenDetails.totalMinted = parseFloat(token.tokenStats.qty_token_minted)
|
||||
// token.tokenDetails.totalBurned = parseFloat(token.tokenStats.qty_token_burned)
|
||||
// token.tokenDetails.circulatingSupply = parseFloat(
|
||||
// token.tokenStats.qty_token_circulating_supply
|
||||
// )
|
||||
// token.tokenDetails.mintingBatonStatus = token.tokenStats.minting_baton_status
|
||||
//
|
||||
// delete token.tokenStats.block_last_active_send
|
||||
// delete token.tokenStats.block_last_active_mint
|
||||
// delete token.tokenStats.qty_valid_txns_since_genesis
|
||||
// delete token.tokenStats.qty_valid_token_addresses
|
||||
// return token
|
||||
// }
|
||||
|
||||
function root(req, res, next) {
|
||||
return res.json({ status: "slp" })
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/list List all SLP tokens.
|
||||
* @apiName List all SLP tokens.
|
||||
@@ -255,6 +256,7 @@ async function list(req, res, next) {
|
||||
return res.json({ error: `Error in /list: ${err.message}` })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/list/{tokenId} List single SLP token by id.
|
||||
* @apiName List single SLP token by id.
|
||||
@@ -292,6 +294,7 @@ async function listSingleToken(req, res, next) {
|
||||
return res.json({ error: `Error in /list/:tokenId: ${err.message}` })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /slp/list/ List Bulk SLP token .
|
||||
* @apiName List Bulk SLP token.
|
||||
@@ -814,6 +817,7 @@ async function balancesForTokenSingle(req, res, next) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/balance/{address}/{TokenId} List single slp token balance for address.
|
||||
* @apiName List single slp token balance for address.
|
||||
@@ -953,6 +957,7 @@ async function balancesForAddressByTokenID(req, res, next) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/convert/{address} Convert address to slpAddr, cashAddr and legacy.
|
||||
* @apiName Convert address to slpAddr, cashAddr and legacy.
|
||||
@@ -1002,6 +1007,7 @@ async function convertAddressSingle(req, res, next) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /slp/convert/ Convert multiple addresses to cash, legacy and simpleledger format.
|
||||
* @apiName Convert multiple addresses to cash, legacy and simpleledger format.
|
||||
@@ -1061,6 +1067,7 @@ async function convertAddressBulk(req, res, next) {
|
||||
res.status(200)
|
||||
return res.json(convertedAddresses)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /slp/validateTxid/ Validate multiple SLP transactions by txid.
|
||||
* @apiName Validate multiple SLP transactions by txid.
|
||||
@@ -1093,32 +1100,55 @@ async function validateBulk(req, res, next) {
|
||||
|
||||
wlogger.debug(`Executing slp/validate with these txids: `, txids)
|
||||
|
||||
// Validate each txid
|
||||
const validatePromises = txids.map(async txid => {
|
||||
try {
|
||||
// Dev note: must call module.exports to allow stubs in unit tests.
|
||||
const isValid = await module.exports.testableComponents.isValidSlpTxid(
|
||||
txid
|
||||
)
|
||||
const query = {
|
||||
v: 3,
|
||||
q: {
|
||||
db: ["c", "u"],
|
||||
find: {
|
||||
"tx.h": { $in: txids }
|
||||
},
|
||||
limit: 300,
|
||||
project: { "slp.valid": 1, "tx.h": 1, "slp.invalidReason": 1 }
|
||||
}
|
||||
}
|
||||
const s = JSON.stringify(query)
|
||||
const b64 = Buffer.from(s).toString("base64")
|
||||
const url = `${process.env.SLPDB_URL}q/${b64}`
|
||||
|
||||
const tmp = {
|
||||
txid: txid,
|
||||
valid: isValid ? true : false
|
||||
}
|
||||
return tmp
|
||||
} catch (err) {
|
||||
//console.log(`err obj: ${util.inspect(err)}`)
|
||||
//console.log(`err.response.data: ${util.inspect(err.response.data)}`)
|
||||
throw err
|
||||
const options = generateCredentials()
|
||||
|
||||
// Get data from SLPDB.
|
||||
const tokenRes = await axios.get(url, options)
|
||||
|
||||
const formattedTokens = []
|
||||
|
||||
const concatArray = tokenRes.data.c.concat(tokenRes.data.u)
|
||||
const tokenIds = []
|
||||
if (concatArray.length > 0) {
|
||||
concatArray.forEach(token => {
|
||||
tokenIds.push(token.tx.h)
|
||||
const validationResult = {
|
||||
txid: token.tx.h,
|
||||
valid: token.slp.valid
|
||||
}
|
||||
if (!validationResult.valid)
|
||||
validationResult.invalidReason = token.slp.invalidReason
|
||||
|
||||
formattedTokens.push(validationResult)
|
||||
})
|
||||
|
||||
// Filter array to only valid txid results
|
||||
const validateResults = await axios.all(validatePromises)
|
||||
const validTxids = validateResults.filter(result => result)
|
||||
txids.forEach(tokenId => {
|
||||
if (!tokenIds.includes(tokenId)) {
|
||||
formattedTokens.push({
|
||||
txid: tokenId,
|
||||
valid: false
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200)
|
||||
return res.json(validTxids)
|
||||
return res.json(formattedTokens)
|
||||
} catch (err) {
|
||||
wlogger.error(`Error in slp.ts/validateBulk().`, err)
|
||||
|
||||
@@ -1133,6 +1163,7 @@ async function validateBulk(req, res, next) {
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/validateTxid/{txid} Validate single SLP transaction by txid.
|
||||
* @apiName Validate single SLP transaction by txid.
|
||||
@@ -1157,13 +1188,41 @@ async function validateSingle(req, res, next) {
|
||||
|
||||
wlogger.debug(`Executing slp/validate/:txid with this txid: `, txid)
|
||||
|
||||
// Validate txid
|
||||
// Dev note: must call module.exports to allow stubs in unit tests.
|
||||
const isValid = await module.exports.testableComponents.isValidSlpTxid(txid)
|
||||
const query = {
|
||||
v: 3,
|
||||
q: {
|
||||
db: ["c", "u"],
|
||||
find: {
|
||||
"tx.h": txid
|
||||
},
|
||||
limit: 300,
|
||||
project: { "slp.valid": 1, "tx.h": 1, "slp.invalidReason": 1 }
|
||||
}
|
||||
}
|
||||
|
||||
const tmp = {
|
||||
const options = generateCredentials()
|
||||
|
||||
const s = JSON.stringify(query)
|
||||
const b64 = Buffer.from(s).toString("base64")
|
||||
const url = `${process.env.SLPDB_URL}q/${b64}`
|
||||
|
||||
// Get data from SLPDB.
|
||||
const tokenRes = await axios.get(url, options)
|
||||
|
||||
// Default return value.
|
||||
let result = {
|
||||
txid: txid,
|
||||
valid: isValid ? true : false
|
||||
valid: false
|
||||
}
|
||||
|
||||
// Build result.
|
||||
const concatArray = tokenRes.data.c.concat(tokenRes.data.u)
|
||||
if (concatArray.length > 0) {
|
||||
result = {
|
||||
txid: concatArray[0].tx.h,
|
||||
valid: concatArray[0].slp.valid
|
||||
}
|
||||
if (!result.valid) result.invalidReason = concatArray[0].slp.invalidReason
|
||||
}
|
||||
|
||||
res.status(200)
|
||||
@@ -1189,278 +1248,6 @@ async function isValidSlpTxid(txid) {
|
||||
return isValid
|
||||
}
|
||||
|
||||
// Below are functions which are enabled for teams not using our javascript SDKs which still need to create txs
|
||||
// These should never be enabled on our public REST API
|
||||
|
||||
async function createTokenType1(req, res, next) {
|
||||
const fundingAddress = req.params.fundingAddress
|
||||
if (!fundingAddress || fundingAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingAddress can not be empty" })
|
||||
}
|
||||
|
||||
const fundingWif = req.params.fundingWif
|
||||
if (!fundingWif || fundingWif === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingWif can not be empty" })
|
||||
}
|
||||
|
||||
const tokenReceiverAddress = req.params.tokenReceiverAddress
|
||||
if (!tokenReceiverAddress || tokenReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const batonReceiverAddress = req.params.batonReceiverAddress
|
||||
if (!batonReceiverAddress || batonReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "batonReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const bchChangeReceiverAddress = req.params.bchChangeReceiverAddress
|
||||
if (!bchChangeReceiverAddress || bchChangeReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "bchChangeReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const decimals = req.params.decimals
|
||||
if (!decimals || decimals === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "decimals can not be empty" })
|
||||
}
|
||||
|
||||
const name = req.params.name
|
||||
if (!name || name === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "name can not be empty" })
|
||||
}
|
||||
|
||||
const symbol = req.params.symbol
|
||||
if (!symbol || symbol === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "symbol can not be empty" })
|
||||
}
|
||||
|
||||
const documentUri = req.params.documentUri
|
||||
if (!documentUri || documentUri === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "documentUri can not be empty" })
|
||||
}
|
||||
|
||||
const documentHash = req.params.documentHash
|
||||
if (!documentHash || documentHash === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "documentHash can not be empty" })
|
||||
}
|
||||
|
||||
const initialTokenQty = req.params.initialTokenQty
|
||||
if (!initialTokenQty || initialTokenQty === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "initialTokenQty can not be empty" })
|
||||
}
|
||||
|
||||
const token = await SLP.TokenType1.create({
|
||||
fundingAddress: fundingAddress,
|
||||
fundingWif: fundingWif,
|
||||
tokenReceiverAddress: tokenReceiverAddress,
|
||||
batonReceiverAddress: batonReceiverAddress,
|
||||
bchChangeReceiverAddress: bchChangeReceiverAddress,
|
||||
decimals: decimals,
|
||||
name: name,
|
||||
symbol: symbol,
|
||||
documentUri: documentUri,
|
||||
documentHash: documentHash,
|
||||
initialTokenQty: initialTokenQty
|
||||
})
|
||||
|
||||
res.status(200)
|
||||
return res.json(token)
|
||||
}
|
||||
|
||||
async function mintTokenType1(req, res, next) {
|
||||
const fundingAddress = req.params.fundingAddress
|
||||
if (!fundingAddress || fundingAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingAddress can not be empty" })
|
||||
}
|
||||
|
||||
const fundingWif = req.params.fundingWif
|
||||
if (!fundingWif || fundingWif === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingWif can not be empty" })
|
||||
}
|
||||
|
||||
const tokenReceiverAddress = req.params.tokenReceiverAddress
|
||||
if (!tokenReceiverAddress || tokenReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const batonReceiverAddress = req.params.batonReceiverAddress
|
||||
if (!batonReceiverAddress || batonReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "batonReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const bchChangeReceiverAddress = req.params.bchChangeReceiverAddress
|
||||
if (!bchChangeReceiverAddress || bchChangeReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "bchChangeReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const tokenId = req.params.tokenId
|
||||
if (!tokenId || tokenId === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenId can not be empty" })
|
||||
}
|
||||
|
||||
const additionalTokenQty = req.params.additionalTokenQty
|
||||
if (!additionalTokenQty || additionalTokenQty === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "additionalTokenQty can not be empty" })
|
||||
}
|
||||
|
||||
const mint = await SLP.TokenType1.mint({
|
||||
fundingAddress: fundingAddress,
|
||||
fundingWif: fundingWif,
|
||||
tokenReceiverAddress: tokenReceiverAddress,
|
||||
batonReceiverAddress: batonReceiverAddress,
|
||||
bchChangeReceiverAddress: bchChangeReceiverAddress,
|
||||
tokenId: tokenId,
|
||||
additionalTokenQty: additionalTokenQty
|
||||
})
|
||||
|
||||
res.status(200)
|
||||
return res.json(mint)
|
||||
}
|
||||
|
||||
async function sendTokenType1(req, res, next) {
|
||||
const fundingAddress = req.params.fundingAddress
|
||||
if (!fundingAddress || fundingAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingAddress can not be empty" })
|
||||
}
|
||||
|
||||
const fundingWif = req.params.fundingWif
|
||||
if (!fundingWif || fundingWif === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingWif can not be empty" })
|
||||
}
|
||||
|
||||
const tokenReceiverAddress = req.params.tokenReceiverAddress
|
||||
if (!tokenReceiverAddress || tokenReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const bchChangeReceiverAddress = req.params.bchChangeReceiverAddress
|
||||
if (!bchChangeReceiverAddress || bchChangeReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "bchChangeReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const tokenId = req.params.tokenId
|
||||
if (!tokenId || tokenId === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenId can not be empty" })
|
||||
}
|
||||
|
||||
const amount = req.params.amount
|
||||
if (!amount || amount === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "amount can not be empty" })
|
||||
}
|
||||
const send = await SLP.TokenType1.send({
|
||||
fundingAddress: fundingAddress,
|
||||
fundingWif: fundingWif,
|
||||
tokenReceiverAddress: tokenReceiverAddress,
|
||||
bchChangeReceiverAddress: bchChangeReceiverAddress,
|
||||
tokenId: tokenId,
|
||||
amount: amount
|
||||
})
|
||||
|
||||
res.status(200)
|
||||
return res.json(send)
|
||||
}
|
||||
|
||||
async function burnTokenType1(req, res, next) {
|
||||
const fundingAddress = req.params.fundingAddress
|
||||
if (!fundingAddress || fundingAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingAddress can not be empty" })
|
||||
}
|
||||
|
||||
const fundingWif = req.params.fundingWif
|
||||
if (!fundingWif || fundingWif === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingWif can not be empty" })
|
||||
}
|
||||
|
||||
const bchChangeReceiverAddress = req.params.bchChangeReceiverAddress
|
||||
if (!bchChangeReceiverAddress || bchChangeReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "bchChangeReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const tokenId = req.params.tokenId
|
||||
if (!tokenId || tokenId === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenId can not be empty" })
|
||||
}
|
||||
|
||||
const amount = req.params.amount
|
||||
if (!amount || amount === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "amount can not be empty" })
|
||||
}
|
||||
|
||||
const burn = await SLP.TokenType1.burn({
|
||||
fundingAddress: fundingAddress,
|
||||
fundingWif: fundingWif,
|
||||
tokenId: tokenId,
|
||||
amount: amount,
|
||||
bchChangeReceiverAddress: bchChangeReceiverAddress
|
||||
})
|
||||
|
||||
res.status(200)
|
||||
return res.json(burn)
|
||||
}
|
||||
|
||||
async function burnAllTokenType1(req, res, next) {
|
||||
const fundingAddress = req.params.fundingAddress
|
||||
if (!fundingAddress || fundingAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingAddress can not be empty" })
|
||||
}
|
||||
|
||||
const fundingWif = req.params.fundingWif
|
||||
if (!fundingWif || fundingWif === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "fundingWif can not be empty" })
|
||||
}
|
||||
|
||||
const bchChangeReceiverAddress = req.params.bchChangeReceiverAddress
|
||||
if (!bchChangeReceiverAddress || bchChangeReceiverAddress === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "bchChangeReceiverAddress can not be empty" })
|
||||
}
|
||||
|
||||
const tokenId = req.params.tokenId
|
||||
if (!tokenId || tokenId === "") {
|
||||
res.status(400)
|
||||
return res.json({ error: "tokenId can not be empty" })
|
||||
}
|
||||
|
||||
const burnAll = await SLP.TokenType1.burnAll({
|
||||
fundingAddress: fundingAddress,
|
||||
fundingWif: fundingWif,
|
||||
tokenId: tokenId,
|
||||
bchChangeReceiverAddress: bchChangeReceiverAddress
|
||||
})
|
||||
|
||||
res.status(200)
|
||||
return res.json(burnAll)
|
||||
}
|
||||
/**
|
||||
* @api {get} /slp/txDetails/{txid} SLP transaction details.
|
||||
* @apiName SLP transaction details.
|
||||
@@ -1487,22 +1274,43 @@ async function txDetails(req, res, next) {
|
||||
return res.json({ error: "This is not a txid" })
|
||||
}
|
||||
|
||||
let tmpSLP
|
||||
if (process.env.NETWORK === "testnet")
|
||||
tmpSLP = new SLPSDK({ restURL: process.env.TREST_URL })
|
||||
else tmpSLP = new SLPSDK({ restURL: process.env.REST_URL })
|
||||
const query = {
|
||||
v: 3,
|
||||
db: ["g"],
|
||||
q: {
|
||||
find: {
|
||||
"tx.h": txid
|
||||
},
|
||||
limit: 300
|
||||
}
|
||||
}
|
||||
|
||||
const tmpbitboxNetwork = new slp.BitboxNetwork(tmpSLP, slpValidator)
|
||||
//console.log(
|
||||
// `tmpbitboxNetwork: ${JSON.stringify(tmpbitboxNetwork, null, 2)}`
|
||||
//)
|
||||
const s = JSON.stringify(query)
|
||||
const b64 = Buffer.from(s).toString("base64")
|
||||
const url = `${process.env.SLPDB_URL}q/${b64}`
|
||||
|
||||
// Get TX info + token info
|
||||
const result = await tmpbitboxNetwork.getTransactionDetails(txid)
|
||||
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
const options = generateCredentials()
|
||||
|
||||
// Get token data from SLPDB
|
||||
const tokenRes = await axios.get(url, options)
|
||||
// console.log(`tokenRes: ${util.inspect(tokenRes)}`)
|
||||
|
||||
// Format the returned data to an object.
|
||||
const formatted = await formatToRestObject(tokenRes)
|
||||
// console.log(`formatted: ${JSON.stringify(formatted,null,2)}`)
|
||||
|
||||
// Get information on the transaction from Insight API.
|
||||
const retData = await transactions.transactionsFromInsight(txid)
|
||||
// console.log(`retData: ${JSON.stringify(retData,null,2)}`)
|
||||
|
||||
// Return both the tx data from Insight and the formatted token information.
|
||||
const response = {
|
||||
retData,
|
||||
...formatted
|
||||
}
|
||||
|
||||
res.status(200)
|
||||
return res.json(result)
|
||||
return res.json(response)
|
||||
} catch (err) {
|
||||
wlogger.error(`Error in slp.ts/txDetails().`, err)
|
||||
|
||||
@@ -1523,6 +1331,7 @@ async function txDetails(req, res, next) {
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/tokenStats/{tokenId} List stats for a single slp token.
|
||||
* @apiName List stats for a single slp token.
|
||||
@@ -1587,6 +1396,7 @@ async function tokenStats(req, res, next) {
|
||||
return res.json({ error: `Error in /tokenStats: ${err.message}` })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /slp/transactions/{tokenId}/{address} SLP transactions by tokenId and address.
|
||||
* @apiName SLP transactions by tokenId and address.
|
||||
@@ -1668,6 +1478,24 @@ async function txsTokenIdAddressSingle(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a Basic Authorization header for slpserve.
|
||||
function generateCredentials() {
|
||||
// Generate the Basic Authentication header for a private instance of SLPDB.
|
||||
const username = "BITBOX"
|
||||
const password = SLPDB_PASS
|
||||
const combined = `${username}:${password}`
|
||||
var base64Credential = Buffer.from(combined).toString("base64")
|
||||
var readyCredential = `Basic ${base64Credential}`
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
authorization: readyCredential
|
||||
}
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
router,
|
||||
testableComponents: {
|
||||
@@ -1682,11 +1510,11 @@ module.exports = {
|
||||
convertAddressBulk,
|
||||
validateBulk,
|
||||
isValidSlpTxid,
|
||||
createTokenType1,
|
||||
mintTokenType1,
|
||||
sendTokenType1,
|
||||
burnTokenType1,
|
||||
burnAllTokenType1,
|
||||
// createTokenType1,
|
||||
// mintTokenType1,
|
||||
// sendTokenType1,
|
||||
// burnTokenType1,
|
||||
// burnAllTokenType1,
|
||||
txDetails,
|
||||
tokenStats,
|
||||
balancesForTokenSingle,
|
||||
|
||||
+6
-5
@@ -385,8 +385,9 @@ describe("#Block", () => {
|
||||
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
console.log(`process.env.RPC_BASEURL: ${process.env.RPC_BASEURL}`)
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(500, {
|
||||
error: {
|
||||
code: -1,
|
||||
@@ -410,7 +411,7 @@ describe("#Block", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockHash })
|
||||
}
|
||||
|
||||
@@ -501,7 +502,7 @@ describe("#Block", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(500, {
|
||||
error: {
|
||||
code: -1,
|
||||
@@ -546,7 +547,7 @@ describe("#Block", () => {
|
||||
// Mock the Insight URL for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockHash })
|
||||
|
||||
nock(`${process.env.BITCOINCOM_BASEURL}`)
|
||||
@@ -589,7 +590,7 @@ describe("#Block", () => {
|
||||
// Mock the Insight URL for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockBlockHash })
|
||||
|
||||
|
||||
+20
-20
@@ -119,7 +119,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockHash })
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockchainInfo })
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: 126769 })
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, {
|
||||
result:
|
||||
"000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c"
|
||||
@@ -288,7 +288,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockHeader })
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockHeaderConcise })
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockBlockHeader })
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockBlockHeaderConcise })
|
||||
}
|
||||
@@ -511,7 +511,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockChainTips })
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: 4049809.205246544 })
|
||||
}
|
||||
|
||||
@@ -592,7 +592,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockMempoolInfo })
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockRawMempool })
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: { error: "Transaction not in mempool" } })
|
||||
}
|
||||
|
||||
@@ -836,7 +836,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockTxOut })
|
||||
}
|
||||
|
||||
@@ -902,7 +902,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockTxOutProof })
|
||||
}
|
||||
|
||||
@@ -963,7 +963,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockTxOutProof })
|
||||
}
|
||||
|
||||
@@ -982,7 +982,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockTxOutProof })
|
||||
}
|
||||
@@ -1042,7 +1042,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: [expected] })
|
||||
}
|
||||
|
||||
@@ -1109,7 +1109,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: [expected] })
|
||||
}
|
||||
|
||||
@@ -1132,7 +1132,7 @@ describe("#BlockchainRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: [expected] })
|
||||
}
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ describe("#ControlRouter", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockGetNetworkInfo })
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ describe("#Mining", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockMiningInfo })
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ describe("#Mining", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: 517604755.6648782 })
|
||||
}
|
||||
|
||||
|
||||
+16
-16
@@ -134,7 +134,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockDecodeRawTransaction })
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockDecodeRawTransaction })
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockDecodeRawTransaction })
|
||||
}
|
||||
@@ -309,7 +309,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockDecodeScript })
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockDecodeScript })
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockDecodeScript })
|
||||
}
|
||||
@@ -453,7 +453,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(500, {
|
||||
error: { message: "parameter 1 must be of length 64 (not 6)" }
|
||||
})
|
||||
@@ -473,7 +473,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockRawTransactionConcise })
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockRawTransactionVerbose })
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(500, {
|
||||
error: { message: "parameter 1 must be of length 64 (not 6)" }
|
||||
})
|
||||
@@ -561,7 +561,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockRawTransactionConcise })
|
||||
}
|
||||
|
||||
@@ -578,7 +578,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockRawTransactionVerbose })
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(500, {
|
||||
error: { message: "TX decode failed" }
|
||||
})
|
||||
@@ -671,7 +671,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, {
|
||||
result:
|
||||
"aef8848396e67532b42008b9d75b5a5a3459a6717740f31f0553b74102b4b118"
|
||||
@@ -759,7 +759,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(500, {
|
||||
error: { message: "TX decode failed" }
|
||||
})
|
||||
@@ -781,7 +781,7 @@ describe("#Raw-Transactions", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, {
|
||||
result:
|
||||
"aef8848396e67532b42008b9d75b5a5a3459a6717740f31f0553b74102b4b118"
|
||||
|
||||
+13
-11
@@ -717,7 +717,7 @@ describe("#SLP", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.SLPDB_URL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockConvert })
|
||||
}
|
||||
|
||||
@@ -832,13 +832,14 @@ describe("#SLP", () => {
|
||||
assert.include(result.error, "Array too large")
|
||||
})
|
||||
|
||||
if (process.env.TEST === "integration") {
|
||||
it("should validate array with single element", async () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
sandbox
|
||||
.stub(slpRoute.testableComponents, "isValidSlpTxid")
|
||||
.resolves(true)
|
||||
}
|
||||
// if (process.env.TEST === "unit") {
|
||||
// sandbox
|
||||
// .stub(slpRoute.testableComponents, "isValidSlpTxid")
|
||||
// .resolves(true)
|
||||
// }
|
||||
|
||||
req.body.txids = [
|
||||
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d"
|
||||
@@ -853,11 +854,11 @@ describe("#SLP", () => {
|
||||
|
||||
it("should validate array with two elements", async () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
sandbox
|
||||
.stub(slpRoute.testableComponents, "isValidSlpTxid")
|
||||
.resolves(true)
|
||||
}
|
||||
// if (process.env.TEST === "unit") {
|
||||
// sandbox
|
||||
// .stub(slpRoute.testableComponents, "isValidSlpTxid")
|
||||
// .resolves(true)
|
||||
// }
|
||||
|
||||
req.body.txids = [
|
||||
"77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d",
|
||||
@@ -871,6 +872,7 @@ describe("#SLP", () => {
|
||||
assert.hasAllKeys(result[0], ["txid", "valid"])
|
||||
assert.equal(result.length, 2)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe("tokenStatsSingle()", () => {
|
||||
|
||||
+3
-3
@@ -135,7 +135,7 @@ describe("#Util", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockAddress })
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ describe("#Util", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.reply(200, { result: mockData.mockAddress })
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ describe("#Util", () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === "unit") {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(``)
|
||||
.post(uri => uri.includes("/"))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockAddress })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user