Skip to content

Commit

Permalink
Merge pull request #290 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
2.2.2
  • Loading branch information
cgcardona authored Feb 10, 2019
2 parents 79adb74 + 3d391a0 commit 6017de3
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 114 deletions.
29 changes: 28 additions & 1 deletion dist/public/bitcoin-com-mainnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,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": "2.2.1",
"version": "2.2.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down Expand Up @@ -2656,6 +2656,33 @@
}
}
},
"/slp/address/convert/{address}": {
"get": {
"tags": [
"slp"
],
"summary": "convert address to slpAddr, cashAddr and legacy",
"description": "convert address to slpAddr, cashAddr and legacy",
"operationId": "slpAddressConvert",
"parameters": [
{
"name": "address",
"in": "path",
"description": "The slp address",
"required": true,
"example": "simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "successful response"
}
}
}
},
"/slp/validateTxid": {
"post": {
"tags": [
Expand Down
29 changes: 28 additions & 1 deletion dist/public/bitcoin-com-testnet-rest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,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": "2.2.1",
"version": "2.2.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down Expand Up @@ -2656,6 +2656,33 @@
}
}
},
"/slp/address/convert/{address}": {
"get": {
"tags": [
"slp"
],
"summary": "convert address to slpAddr, cashAddr and legacy",
"description": "convert address to slpAddr, cashAddr and legacy",
"operationId": "slpAddressConvert",
"parameters": [
{
"name": "address",
"in": "path",
"description": "The slp address",
"required": true,
"example": "slptest:qz35h5mfa8w2pqma2jq06lp7dnv5fxkp2shlcycvd5",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "successful response"
}
}
}
},
"/slp/validateTxid": {
"post": {
"tags": [
Expand Down
106 changes: 68 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rest.bitcoin.com",
"version": "2.2.1",
"version": "2.2.2",
"description": "REST API for Bitcoin.com's Cloud",
"author": "Gabriel Cardona <[email protected]>",
"contributors": [
Expand Down Expand Up @@ -50,6 +50,7 @@
"pg": "^6.2.3",
"pg-hstore": "^2.3.2",
"sequelize": "^3.30.4",
"slp-sdk": "1.1.7",
"slpjs": "0.12.2",
"socket.io": "^2.1.1",
"strftime": "^0.10.0",
Expand Down
84 changes: 42 additions & 42 deletions src/routes/v2/slp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ util.inspect.defaultOptions = { depth: 5 }
const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default
const BITBOX = new BITBOXCli()

const SLPSDK = require("slp-sdk/lib/SLP").default
const SLP = new SLPSDK()

// Instantiate SLPJS.
const slp = require("slpjs")
const slpjs = new slp.Slp(BITBOX)
Expand All @@ -35,9 +38,6 @@ const BitboxHTTP = axios.create({
const username = process.env.RPC_USERNAME
const password = process.env.RPC_PASSWORD

// const SLPsdk = require("slp-sdk/lib/SLP").default
// const SLP = new SLPsdk()

// Retrieve raw transactions details from the full node.
async function getRawTransactionsFromNode(txids: string[]) {
try {
Expand Down Expand Up @@ -176,7 +176,7 @@ router.get(
config.slpRateLimit5,
balancesForAddressByTokenID
)
// router.get("/address/convert/:address", config.slpRateLimit6, convertAddress)
router.get("/address/convert/:address", config.slpRateLimit6, convertAddress)
router.post("/validateTxid", config.slpRateLimit7, validateBulk)

function root(
Expand Down Expand Up @@ -539,43 +539,43 @@ async function balancesForAddressByTokenID(
}
}

// async function convertAddress(
// req: express.Request,
// res: express.Response,
// next: express.NextFunction
// ) {
// try {
// let address = req.params.address
// if (!address || address === "") {
// res.status(400)
// return res.json({ error: "address can not be empty" })
// }
// const slpAddr = SLP.Address.toSLPAddress(req.params.address)
// const obj: {
// [slpAddress: string]: any
// cashAddress: any
// legacyAddress: any
// } = {
// slpAddress: "",
// cashAddress: "",
// legacyAddress: ""
// }
// obj.slpAddress = slpAddr
// obj.cashAddress = SLP.Address.toCashAddress(slpAddr)
// obj.legacyAddress = BITBOX.Address.toLegacyAddress(obj.cashAddress)
// return res.json(obj)
// } catch (err) {
// const { msg, status } = routeUtils.decodeError(err)
// if (msg) {
// res.status(status)
// return res.json({ error: msg })
// }
// res.status(500)
// return res.json({
// error: `Error in /address/convert/:address: ${err.message}`
// })
// }
// }
async function convertAddress(
req: express.Request,
res: express.Response,
next: express.NextFunction
) {
try {
let address = req.params.address
if (!address || address === "") {
res.status(400)
return res.json({ error: "address can not be empty" })
}
const slpAddr = SLP.Address.toSLPAddress(req.params.address)
const obj: {
[slpAddress: string]: any
cashAddress: any
legacyAddress: any
} = {
slpAddress: "",
cashAddress: "",
legacyAddress: ""
}
obj.slpAddress = slpAddr
obj.cashAddress = SLP.Address.toCashAddress(slpAddr)
obj.legacyAddress = BITBOX.Address.toLegacyAddress(obj.cashAddress)
return res.json(obj)
} catch (err) {
const { msg, status } = routeUtils.decodeError(err)
if (msg) {
res.status(status)
return res.json({ error: msg })
}
res.status(500)
return res.json({
error: `Error in /address/convert/:address: ${err.message}`
})
}
}

async function validateBulk(
req: express.Request,
Expand Down Expand Up @@ -654,7 +654,7 @@ module.exports = {
listSingleToken,
balancesForAddress,
balancesForAddressByTokenID,
// convertAddress,
convertAddress,
validateBulk,
isValidSlpTxid
}
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": "2.2.1",
"version": "2.2.2",
"title": "REST",
"license": {
"name": "MIT",
Expand Down
25 changes: 25 additions & 0 deletions swaggerJSONFiles/paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,31 @@
}
}
},
"/slp/address/convert/{address}": {
"get": {
"tags": ["slp"],
"summary": "convert address to slpAddr, cashAddr and legacy",
"description": "convert address to slpAddr, cashAddr and legacy",
"operationId": "slpAddressConvert",
"parameters": [
{
"name": "address",
"in": "path",
"description": "The slp address",
"required": true,
"example": "",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "successful response"
}
}
}
},
"/slp/validateTxid": {
"post": {
"tags": ["slp"],
Expand Down
Loading

0 comments on commit 6017de3

Please sign in to comment.