diff --git a/dist/public/bitcoin-com-mainnet-rest-v2.json b/dist/public/bitcoin-com-mainnet-rest-v2.json index 6006f4bf..41cc1880 100644 --- a/dist/public/bitcoin-com-mainnet-rest-v2.json +++ b/dist/public/bitcoin-com-mainnet-rest-v2.json @@ -1234,7 +1234,7 @@ "openapi": "3.0.0", "info": { "description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)", - "version": "3.12.2", + "version": "3.12.3", "title": "REST", "license": { "name": "MIT", diff --git a/dist/public/bitcoin-com-testnet-rest-v2.json b/dist/public/bitcoin-com-testnet-rest-v2.json index edfedd0a..16037fc9 100644 --- a/dist/public/bitcoin-com-testnet-rest-v2.json +++ b/dist/public/bitcoin-com-testnet-rest-v2.json @@ -1234,7 +1234,7 @@ "openapi": "3.0.0", "info": { "description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)", - "version": "3.12.2", + "version": "3.12.3", "title": "REST", "license": { "name": "MIT", diff --git a/package.json b/package.json index aae0ac4f..614c69e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rest.bitcoin.com", - "version": "3.12.2", + "version": "3.12.3", "description": "REST API for Bitcoin.com's Cloud", "author": "Gabriel Cardona ", "contributors": [ diff --git a/src/routes/v2/slp.ts b/src/routes/v2/slp.ts index 0a8260ff..3fe389a2 100644 --- a/src/routes/v2/slp.ts +++ b/src/routes/v2/slp.ts @@ -262,15 +262,56 @@ async function listSingleToken( try { let tokenId: string = req.params.tokenId + // Reject if tokenIds is not an array. if (!tokenId || tokenId === "") { res.status(400) - return res.json({ error: "tokenId can not be empty" }) + return res.json({ + error: "tokenId can not be empty" + }) } - const t: Promise = await lookupToken(tokenId) + const query: { + v: number + q: { + db: string[] + find: any + project: { + tokenDetails: number + tokenStats: number + _id: number + } + limit: number + } + } = { + v: 3, + q: { + db: ["t"], + find: { + $query: { + "tokenDetails.tokenIdHex": tokenId + } + }, + project: { tokenDetails: 1, tokenStats: 1, _id: 0 }, + limit: 1000 + } + } + + const s: string = JSON.stringify(query) + const b64: string = Buffer.from(s).toString("base64") + const url: string = `${process.env.SLPDB_URL}q/${b64}` + const tokenRes: AxiosResponse = await axios.get(url) + + let token res.status(200) - return res.json(t) + if (tokenRes.data.t.length) { + token = formatTokenOutput(tokenRes.data.t[0]) + return res.json(token.tokenDetails) + } else { + return res.json({ + id: "not found" + }) + } } catch (err) { wlogger.error(`Error in slp.ts/listSingleToken().`, err) diff --git a/swaggerJSONFiles/info.json b/swaggerJSONFiles/info.json index 725ef679..a864d24a 100644 --- a/swaggerJSONFiles/info.json +++ b/swaggerJSONFiles/info.json @@ -2,7 +2,7 @@ "openapi": "3.0.0", "info": { "description": "The Bitcoin Cash JSON PRC over HTTP", - "version": "3.12.2", + "version": "3.12.3", "title": "REST", "license": { "name": "MIT", diff --git a/swaggerJSONFilesBuilt/mainnet/info.json b/swaggerJSONFilesBuilt/mainnet/info.json index 128d0b7d..6a131830 100644 --- a/swaggerJSONFilesBuilt/mainnet/info.json +++ b/swaggerJSONFilesBuilt/mainnet/info.json @@ -2,7 +2,7 @@ "openapi": "3.0.0", "info": { "description": "rest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)", - "version": "3.12.2", + "version": "3.12.3", "title": "REST", "license": { "name": "MIT", diff --git a/swaggerJSONFilesBuilt/testnet/info.json b/swaggerJSONFilesBuilt/testnet/info.json index 2e0ebc6a..2bc26fdf 100644 --- a/swaggerJSONFilesBuilt/testnet/info.json +++ b/swaggerJSONFilesBuilt/testnet/info.json @@ -2,7 +2,7 @@ "openapi": "3.0.0", "info": { "description": "trest.bitcoin.com is the REST layer for Bitcoin.com's Cloud. More info: [developer.bitcoin.com/rest](https://developer.bitcoin.com/rest). Chatroom [geni.us/CashDev](http://geni.us/CashDev)", - "version": "3.12.2", + "version": "3.12.3", "title": "REST", "license": { "name": "MIT", diff --git a/test/v2/slp.js b/test/v2/slp.js index a743cc86..cbf391b1 100644 --- a/test/v2/slp.js +++ b/test/v2/slp.js @@ -13,6 +13,7 @@ const chai = require("chai") const assert = chai.assert const nock = require("nock") // HTTP mocking const sinon = require("sinon") +const axios = require("axios") // Prepare the slpRoute for stubbing dependcies on slpjs. const slpRoute = require("../../dist/routes/v2/slp") @@ -149,12 +150,12 @@ describe("#SLP", () => { }) }) - describe("listSingleToken()", () => { + describe("#listSingleToken()", () => { const listSingleToken = slpRoute.testableComponents.listSingleToken it("should throw 400 if tokenId is empty", async () => { const result = await listSingleToken(req, res) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) assert.hasAllKeys(result, ["error"]) assert.include(result.error, "tokenId can not be empty") @@ -188,9 +189,14 @@ describe("#SLP", () => { it("should return 'not found' for mainnet txid on testnet", async () => { // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { - nock(mockServerUrl) - .get(uri => uri.includes("/")) - .reply(200, mockData.mockSingleToken) + sandbox.stub(axios, "get").resolves({ + result: { + id: "not found" + }, + data: { + t: [] + } + }) } req.params.tokenId = @@ -200,7 +206,7 @@ describe("#SLP", () => { "259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1" const result = await listSingleToken(req, res) - // console.log(`result: ${util.inspect(result)}`) + console.log(`result: ${util.inspect(result)}`) assert.hasAllKeys(result, ["id"]) assert.include(result.id, "not found") diff --git a/yarn.lock b/yarn.lock index 1a731953..0651f4c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -279,6 +279,11 @@ "@types/connect" "*" "@types/node" "*" +"@types/chai@^4.1.7": + version "4.2.0" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.0.tgz#2478260021408dec32c123a7cad3414beb811a07" + integrity sha512-zw8UvoBEImn392tLjxoavuonblX/4Yb9ha4KBU10FirCfwgzhKO0dvyJSF9ByxV1xK1r2AgnAi/tvQaLgxQqxA== + "@types/connect@*": version "3.4.32" resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.32.tgz#aa0e9616b9435ccad02bc52b5b454ffc2c70ba28" @@ -332,6 +337,11 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== +"@types/mocha@^5.2.6": + version "5.2.7" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea" + integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ== + "@types/node@*": version "12.0.8" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.8.tgz#551466be11b2adc3f3d47156758f610bd9f6b1d8" @@ -372,6 +382,11 @@ "@types/express-serve-static-core" "*" "@types/mime" "*" +"@types/sinon@^7.0.11": + version "7.0.13" + resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-7.0.13.tgz#ca039c23a9e27ebea53e0901ef928ea2a1a6d313" + integrity sha512-d7c/C/+H/knZ3L8/cxhicHUiTDxdgap0b/aNJfsmLwFu/iOP17mdgbQsbHA3SJmrzsjD0l3UEE5SN4xxuz5ung== + "@types/wif@^2.0.1": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/wif/-/wif-2.0.1.tgz#bcab48b201403cb759cd7659aff4610cfd4888f4" @@ -929,6 +944,14 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== +axios@0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102" + integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI= + dependencies: + follow-redirects "^1.3.0" + is-buffer "^1.1.5" + axios@0.19.0, axios@^0.19.0: version "0.19.0" resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8" @@ -945,7 +968,7 @@ axios@^0.17.1: follow-redirects "^1.2.5" is-buffer "^1.1.5" -axios@^0.18.0, axios@^0.18.1: +axios@^0.18.0: version "0.18.1" resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.1.tgz#ff3f0de2e7b5d180e757ad98000f1081b87bcea3" integrity sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g== @@ -1853,7 +1876,7 @@ bip-schnorr@^0.3.0: random-bytes "^1.0.0" safe-buffer "^5.0.1" -bip21@Bitcoin-com/bip21: +bip21@Bitcoin-com/bip21, "bip21@github:Bitcoin-com/bip21": version "2.0.1" resolved "https://codeload.github.com/Bitcoin-com/bip21/tar.gz/28f8d03a3a16ed11eb5b963248ed1be8c46c6d6f" dependencies: @@ -1868,7 +1891,7 @@ bip32-utils@Bitcoin-com/bip32-utils#0.13.0: standard "^11.0.1" tape "*" -bip32-utils@Bitcoin-com/bip32-utils#0.13.1: +bip32-utils@Bitcoin-com/bip32-utils#0.13.1, "bip32-utils@github:Bitcoin-com/bip32-utils#0.13.1": version "0.13.1" resolved "https://codeload.github.com/Bitcoin-com/bip32-utils/tar.gz/b8a33ebd0a0ac39de7cd987e5c3f77a8c5d84e58" dependencies: @@ -1908,6 +1931,47 @@ bip66@^1.1.0, bip66@^1.1.5: dependencies: safe-buffer "^5.0.1" +bitbox-sdk@8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/bitbox-sdk/-/bitbox-sdk-8.1.0.tgz#f1b8e0d6c53ca60b2c34902bfe9ce12ef9c29599" + integrity sha512-kCRsTH0JxXPhtK/at3JGWf6nqv0pawFo1B2ii5EIpy2ux0O2lQzpVZLR28ACWx1neQrIn83q1wZaSr7BFHUs0Q== + dependencies: + "@types/bigi" "^1.4.2" + "@types/bip39" "^2.4.2" + "@types/chai" "^4.1.7" + "@types/mocha" "^5.2.6" + "@types/node" "^10.11.7" + "@types/randombytes" "^2.0.0" + "@types/sinon" "^7.0.11" + "@types/wif" "^2.0.1" + assert "^1.4.1" + axios "0.18.0" + bc-bip68 "^1.0.5" + bch-wallet-bridge.js "github:web3bch/bch-wallet-bridge.js#master" + bigi "^1.4.2" + bip-schnorr "^0.3.0" + bip21 Bitcoin-com/bip21 + bip32-utils Bitcoin-com/bip32-utils#0.13.1 + bip38 "^2.0.2" + bip39 "^2.5.0" + bip66 "^1.1.5" + bitcoincash-ops Bitcoin-com/bitcoincash-ops#2.0.0 + bitcoincashjs-lib Bitcoin-com/bitcoincashjs-lib#v4.0.0 + bitcoinjs-message "^2.0.0" + browserify "^16.2.2" + bs58 "^4.0.1" + buffer "^5.1.0" + cashaddrjs "^0.2.9" + coininfo Bitcoin-com/coininfo + qrcode "^1.2.0" + randombytes "^2.0.6" + repl.history "^0.1.4" + safe-buffer "^5.1.2" + satoshi-bitcoin "^1.0.4" + socket.io "^2.1.1" + socket.io-client "^2.1.1" + wif "^2.0.6" + bitbox-sdk@8.4.2: version "8.4.2" resolved "https://registry.yarnpkg.com/bitbox-sdk/-/bitbox-sdk-8.4.2.tgz#0d9ebc77f92b7884faae8a1a9ebbabf48315c877" @@ -2017,7 +2081,7 @@ bitcoin-txdecoder@0.0.3: dependencies: bitcoinjs-lib "3.3.*" -bitcoincash-ops@Bitcoin-com/bitcoincash-ops#2.0.0: +bitcoincash-ops@Bitcoin-com/bitcoincash-ops#2.0.0, "bitcoincash-ops@github:Bitcoin-com/bitcoincash-ops#2.0.0": version "2.0.0" resolved "https://codeload.github.com/Bitcoin-com/bitcoincash-ops/tar.gz/6ab82cc7326c67236f3b2d9d0457258ac2ef48e3" @@ -2068,6 +2132,26 @@ bitcoincashjs-lib@Bitcoin-com/bitcoincashjs-lib#v4.0.1: varuint-bitcoin "^1.0.4" wif "^2.0.1" +"bitcoincashjs-lib@github:Bitcoin-com/bitcoincashjs-lib#v4.0.0": + version "4.0.0" + resolved "https://codeload.github.com/Bitcoin-com/bitcoincashjs-lib/tar.gz/3d360c780ec7df4a74aea93664c2b5ff8b08949a" + dependencies: + bech32 "^1.1.2" + bigi "^1.4.0" + bip66 "^1.1.0" + bitcoincash-ops Bitcoin-com/bitcoincash-ops#2.0.0 + bs58check "^2.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.3" + ecurve "^1.0.0" + merkle-lib "^2.0.10" + pushdata-bitcoin Bitcoin-com/pushdata-bitcoin#1.2.1 + randombytes "^2.0.1" + safe-buffer "^5.0.1" + typeforce "^1.11.3" + varuint-bitcoin "^1.0.4" + wif "^2.0.1" + "bitcoincashjs-lib@https://github.com/Bitcoin-com/bitcoincashjs-lib.git": version "4.0.1" resolved "https://github.com/Bitcoin-com/bitcoincashjs-lib.git#28447b40a4ccd23913f7ade6589dc7214c99e60a" @@ -3147,7 +3231,7 @@ code-point-at@^1.0.0: resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= -coininfo@Bitcoin-com/coininfo: +coininfo@Bitcoin-com/coininfo, "coininfo@github:Bitcoin-com/coininfo": version "4.0.0" resolved "https://codeload.github.com/Bitcoin-com/coininfo/tar.gz/eece2c6141d08c3e7783929f2a1e1e681aa1a82c" dependencies: @@ -5100,7 +5184,7 @@ follow-redirects@1.5.10: dependencies: debug "=3.1.0" -follow-redirects@^1.2.5: +follow-redirects@^1.2.5, follow-redirects@^1.3.0: version "1.7.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76" integrity sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ== @@ -7512,11 +7596,6 @@ lodash@=4.17.11, lodash@^4.14.0, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5 resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== -lodash@^4.17.14: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== - lodash@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/lodash/-/lodash-1.0.2.tgz#8f57560c83b59fc270bd3d561b690043430e2551" @@ -10985,15 +11064,15 @@ slide@^1.1.5, slide@^1.1.6, slide@~1.1.3, slide@~1.1.6: resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" integrity sha1-VusCfWW00tzmyy4tMsTUr8nh1wc= -slp-sdk@4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/slp-sdk/-/slp-sdk-4.5.0.tgz#1084ccecf1d21919e7fee1dd904fbefd3f2e6b28" - integrity sha512-KdHCrmHfU+UOcGY/JsjdYHolpXMQRyIr6byk5gKdzRvlArMcqK8QQLHrY2dHe0kjHz4SMNp3k2849+fa4furqw== +slp-sdk@4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/slp-sdk/-/slp-sdk-4.3.0.tgz#723248ee84892882a286d05553a9c79354147db5" + integrity sha512-3FqxleVpGgEBxkyeidQiKDEx/aX89uLgPdYVsgRBeWm7zYaNsTpzh2POMJinzWe1eok7iq1WbgQSCpdAu3hMug== dependencies: - axios "0.19.0" + axios "^0.17.1" babel-register "^6.26.0" bignumber.js "^8.0.2" - bitbox-sdk "8.4.2" + bitbox-sdk "8.1.0" chalk "^2.3.0" clear "0.1.0" commander "^2.13.0" @@ -11002,20 +11081,20 @@ slp-sdk@4.5.0: mkdirp "^0.5.1" node-emoji "^1.8.1" repl.history "^0.1.4" - slpjs "0.20.5" + slpjs "0.18.0" touch "^3.1.0" -slpjs@0.20.5: - version "0.20.5" - resolved "https://registry.yarnpkg.com/slpjs/-/slpjs-0.20.5.tgz#95d6d6136f6843c55fe5f803380f5b60e53f3af1" - integrity sha512-JhorPnLsPl5CMseZShVaeJZrcRMp55kGiDQthI7uimJ0yKkYlfGoYXjKDEIBiqT8PbFpDlnSSezgLHfOdBdm5g== +slpjs@0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/slpjs/-/slpjs-0.18.0.tgz#b7e8910073db41ecdd06302baa4d96d8bb91c573" + integrity sha512-DGXRX7txx34mE9rkUOZV7xYW8jbGMD7yzsIUWiTDBR4/8oNKQkaFjPKXML/jdwz0SeyEPkhQzcY5hPi0CCk3cg== dependencies: "@types/lodash" "^4.14.120" - axios "^0.18.1" + axios "^0.18.0" bchaddrjs-slp "git://github.com/simpleledger/bchaddrjs.git#master" bignumber.js "^8.1.1" bitcore-lib-cash "^0.19.0" - lodash "^4.17.14" + lodash "^4.17.11" smart-buffer@4.0.2: version "4.0.2"