Skip to content

Commit

Permalink
Merge pull request #499 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
v3.12.3
  • Loading branch information
Gabriel Cardona authored Aug 14, 2019
2 parents e66e27b + 320c29c commit 0df4bfe
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 39 deletions.
2 changes: 1 addition & 1 deletion dist/public/bitcoin-com-mainnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion dist/public/bitcoin-com-testnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"contributors": [
Expand Down
47 changes: 44 additions & 3 deletions src/routes/v2/slp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = 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)

Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFiles/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFilesBuilt/mainnet/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion swaggerJSONFilesBuilt/testnet/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 12 additions & 6 deletions test/v2/slp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 =
Expand All @@ -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")
Expand Down
Loading

0 comments on commit 0df4bfe

Please sign in to comment.