mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 01:02:05 -07:00
Removed v1 routes
This commit is contained in:
@@ -1,318 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default
|
||||
const BITBOX = new BITBOXCli()
|
||||
|
||||
const util = require("util")
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const config = {
|
||||
addressRateLimit1: undefined,
|
||||
addressRateLimit2: undefined,
|
||||
addressRateLimit3: undefined,
|
||||
addressRateLimit4: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 6) {
|
||||
config[`addressRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
router.get("/", config.addressRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "address" })
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/details/:address",
|
||||
config.addressRateLimit2,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
let addresses = JSON.parse(req.params.address)
|
||||
|
||||
// Enforce no more than 20 addresses.
|
||||
if (addresses.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 addresses"
|
||||
})
|
||||
}
|
||||
|
||||
const result = []
|
||||
addresses = addresses.map(address => {
|
||||
const path = `${
|
||||
process.env.BITCOINCOM_BASEURL
|
||||
}addr/${BITBOX.Address.toLegacyAddress(address)}`
|
||||
return axios.get(path) // Returns a promise.
|
||||
})
|
||||
|
||||
axios.all(addresses).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data
|
||||
parsed.legacyAddress = BITBOX.Address.toLegacyAddress(
|
||||
parsed.addrStr
|
||||
)
|
||||
parsed.cashAddress = BITBOX.Address.toCashAddress(parsed.addrStr)
|
||||
delete parsed.addrStr
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
let path = `${
|
||||
process.env.BITCOINCOM_BASEURL
|
||||
}addr/${BITBOX.Address.toLegacyAddress(req.params.address)}`
|
||||
if (req.query.from && req.query.to)
|
||||
path = `${path}?from=${req.query.from}&to=${req.query.to}`
|
||||
|
||||
axios
|
||||
.get(path)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
delete parsed.addrStr
|
||||
parsed.legacyAddress = BITBOX.Address.toLegacyAddress(
|
||||
req.params.address
|
||||
)
|
||||
parsed.cashAddress = BITBOX.Address.toCashAddress(req.params.address)
|
||||
res.json(parsed)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/utxo/:address",
|
||||
config.addressRateLimit3,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
let addresses = JSON.parse(req.params.address)
|
||||
if (addresses.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 addresses"
|
||||
})
|
||||
}
|
||||
|
||||
addresses = addresses.map(address =>
|
||||
BITBOX.Address.toLegacyAddress(address)
|
||||
)
|
||||
const final = []
|
||||
addresses.forEach(address => {
|
||||
final.push([])
|
||||
})
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}addrs/${addresses}/utxo`)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
parsed.forEach(data => {
|
||||
data.legacyAddress = BITBOX.Address.toLegacyAddress(data.address)
|
||||
data.cashAddress = BITBOX.Address.toCashAddress(data.address)
|
||||
delete data.address
|
||||
addresses.forEach((address, index) => {
|
||||
if (addresses[index] === data.legacyAddress)
|
||||
final[index].push(data)
|
||||
})
|
||||
})
|
||||
res.json(final)
|
||||
})
|
||||
.catch(error => {
|
||||
//res.send(error.response.data.error.message)
|
||||
// console.log(`Error: `, error)
|
||||
})
|
||||
} catch (error) {
|
||||
axios
|
||||
.get(
|
||||
`${
|
||||
process.env.BITCOINCOM_BASEURL
|
||||
}addr/${BITBOX.Address.toLegacyAddress(req.params.address)}/utxo`
|
||||
)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
parsed.forEach(data => {
|
||||
delete data.address
|
||||
data.legacyAddress = BITBOX.Address.toLegacyAddress(
|
||||
req.params.address
|
||||
)
|
||||
data.cashAddress = BITBOX.Address.toCashAddress(req.params.address)
|
||||
})
|
||||
res.json(parsed)
|
||||
})
|
||||
.catch(error => {
|
||||
//res.send(error.response.data.error.message)
|
||||
// console.log(`Error: `, error)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/unconfirmed/:address",
|
||||
config.addressRateLimit4,
|
||||
(req, res, next) => {
|
||||
try {
|
||||
let addresses = JSON.parse(req.params.address)
|
||||
if (addresses.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 addresses"
|
||||
})
|
||||
}
|
||||
addresses = addresses.map(address =>
|
||||
BITBOX.Address.toLegacyAddress(address)
|
||||
)
|
||||
const final = []
|
||||
addresses.forEach(address => {
|
||||
final.push([])
|
||||
})
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}addrs/${addresses}/utxo`)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
parsed.forEach(data => {
|
||||
data.legacyAddress = BITBOX.Address.toLegacyAddress(data.address)
|
||||
data.cashAddress = BITBOX.Address.toCashAddress(data.address)
|
||||
delete data.address
|
||||
if (data.confirmations === 0) {
|
||||
addresses.forEach((address, index) => {
|
||||
if (addresses[index] === data.legacyAddress)
|
||||
final[index].push(data)
|
||||
})
|
||||
}
|
||||
})
|
||||
res.json(final)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
} catch (error) {
|
||||
axios
|
||||
.get(
|
||||
`${
|
||||
process.env.BITCOINCOM_BASEURL
|
||||
}addr/${BITBOX.Address.toLegacyAddress(req.params.address)}/utxo`
|
||||
)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
const unconfirmed = []
|
||||
parsed.forEach(data => {
|
||||
data.legacyAddress = BITBOX.Address.toLegacyAddress(data.address)
|
||||
data.cashAddress = BITBOX.Address.toCashAddress(data.address)
|
||||
delete data.address
|
||||
if (data.confirmations === 0) unconfirmed.push(data)
|
||||
})
|
||||
res.json(unconfirmed)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/unconfirmed/:address",
|
||||
config.addressRateLimit4,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
let addresses = JSON.parse(req.params.address)
|
||||
if (addresses.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 addresses"
|
||||
})
|
||||
}
|
||||
addresses = addresses.map(address =>
|
||||
BITBOX.Address.toLegacyAddress(address)
|
||||
)
|
||||
const final = []
|
||||
addresses.forEach(address => {
|
||||
final.push([])
|
||||
})
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}txs/?address=${addresses}`)
|
||||
.then(response => {
|
||||
res.json(response.data)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
} catch (error) {
|
||||
axios
|
||||
.get(
|
||||
`${
|
||||
process.env.BITCOINCOM_BASEURL
|
||||
}txs/?address=${BITBOX.Address.toLegacyAddress(req.params.address)}`
|
||||
)
|
||||
.then(response => {
|
||||
res.json(response.data)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/transactions/:address",
|
||||
config.addressRateLimit5,
|
||||
(req, res, next) => {
|
||||
try {
|
||||
let addresses = JSON.parse(req.params.address)
|
||||
if (addresses.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 addresses"
|
||||
})
|
||||
}
|
||||
addresses = addresses.map(address =>
|
||||
BITBOX.Address.toLegacyAddress(address)
|
||||
)
|
||||
const final = []
|
||||
addresses.forEach(address => {
|
||||
final.push([])
|
||||
})
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}txs/?address=${addresses}`)
|
||||
.then(response => {
|
||||
res.json(response.data)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
} catch (error) {
|
||||
axios
|
||||
.get(
|
||||
`${
|
||||
process.env.BITCOINCOM_BASEURL
|
||||
}txs/?address=${BITBOX.Address.toLegacyAddress(req.params.address)}`
|
||||
)
|
||||
.then(response => {
|
||||
res.json(response.data)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
@@ -1,90 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
blockRateLimit1: undefined,
|
||||
blockRateLimit2: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 3) {
|
||||
config[`blockRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
router.get("/", config.blockRateLimit1, (req, res, next) => {
|
||||
res.json({ status: "block" })
|
||||
})
|
||||
|
||||
router.get("/details/:id", config.blockRateLimit2, (req, res, next) => {
|
||||
if (req.params.id.length !== 64) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getblockhash",
|
||||
method: "getblockhash",
|
||||
params: [parseInt(req.params.id)]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}block/${response.data.result}`)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
res.json(parsed)
|
||||
})
|
||||
.catch(error => {
|
||||
//res.send(error.response.data.error.message)
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
//res.send(error.response.data.error.message)
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
})
|
||||
} else {
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}block/${req.params.id}`)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
res.json(parsed)
|
||||
})
|
||||
.catch(error => {
|
||||
//res.send(error.response.data.error.message)
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,721 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
blockchainRateLimit1: undefined,
|
||||
blockchainRateLimit2: undefined,
|
||||
blockchainRateLimit3: undefined,
|
||||
blockchainRateLimit4: undefined,
|
||||
blockchainRateLimit5: undefined,
|
||||
blockchainRateLimit6: undefined,
|
||||
blockchainRateLimit7: undefined,
|
||||
blockchainRateLimit8: undefined,
|
||||
blockchainRateLimit9: undefined,
|
||||
blockchainRateLimit10: undefined,
|
||||
blockchainRateLimit11: undefined,
|
||||
blockchainRateLimit12: undefined,
|
||||
blockchainRateLimit13: undefined,
|
||||
blockchainRateLimit14: undefined,
|
||||
blockchainRateLimit15: undefined,
|
||||
blockchainRateLimit16: undefined,
|
||||
blockchainRateLimit17: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 18) {
|
||||
config[`blockchainRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.blockchainRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "blockchain" })
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/getBestBlockHash",
|
||||
config.blockchainRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getbestblockhash"
|
||||
requestConfig.data.method = "getbestblockhash"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getBlock/:hash",
|
||||
config.blockchainRateLimit3,
|
||||
async (req, res, next) => {
|
||||
let verbose = false
|
||||
if (req.query.verbose && req.query.verbose === "true") verbose = true
|
||||
|
||||
let showTxs = true
|
||||
if (req.query.txs && req.query.txs === "false") showTxs = false
|
||||
|
||||
requestConfig.data.id = "getblock"
|
||||
requestConfig.data.method = "getblock"
|
||||
requestConfig.data.params = [req.params.hash, verbose]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
if (!showTxs) delete response.data.result.tx
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getBlockchainInfo",
|
||||
config.blockchainRateLimit4,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getblockchaininfo"
|
||||
requestConfig.data.method = "getblockchaininfo"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getBlockCount",
|
||||
config.blockchainRateLimit5,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getblockcount"
|
||||
requestConfig.data.method = "getblockcount"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getBlockHash/:height",
|
||||
config.blockchainRateLimit6,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
let heights = JSON.parse(req.params.height)
|
||||
if (heights.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 heights"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
heights = heights.map(height =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getblockhash",
|
||||
method: "getblockhash",
|
||||
params: [height]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(heights).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getblockhash",
|
||||
method: "getblockhash",
|
||||
params: [parseInt(req.params.height)]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getBlockHeader/:hash",
|
||||
config.blockchainRateLimit7,
|
||||
async (req, res, next) => {
|
||||
let verbose = false
|
||||
if (req.query.verbose && req.query.verbose === "true") verbose = true
|
||||
|
||||
try {
|
||||
let hashes = JSON.parse(req.params.hash)
|
||||
if (hashes.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 hashes"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
hashes = hashes.map(hash =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getblockheader",
|
||||
method: "getblockheader",
|
||||
params: [hash, verbose]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(hashes).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getblockheader",
|
||||
method: "getblockheader",
|
||||
params: [req.params.hash, verbose]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getChainTips",
|
||||
config.blockchainRateLimit8,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getchaintips"
|
||||
requestConfig.data.method = "getchaintips"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getDifficulty",
|
||||
config.blockchainRateLimit9,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getdifficulty"
|
||||
requestConfig.data.method = "getdifficulty"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getMempoolAncestors/:txid",
|
||||
config.blockchainRateLimit10,
|
||||
async (req, res, next) => {
|
||||
let verbose = false
|
||||
if (req.query.verbose && req.query.verbose === "true") verbose = true
|
||||
|
||||
try {
|
||||
let txids = JSON.parse(req.params.txid)
|
||||
if (txids.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 txids"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
txids = txids.map(txid =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getmempoolancestors",
|
||||
method: "getmempoolancestors",
|
||||
params: [txid, verbose]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(txids).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getmempoolancestors",
|
||||
method: "getmempoolancestors",
|
||||
params: [req.params.txid, verbose]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getMempoolDescendants/:txid",
|
||||
config.blockchainRateLimit11,
|
||||
async (req, res, next) => {
|
||||
let verbose = false
|
||||
if (req.query.verbose && req.query.verbose === "true") verbose = true
|
||||
|
||||
try {
|
||||
let txids = JSON.parse(req.params.txid)
|
||||
if (txids.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 txids"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
txids = txids.map(txid =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getmempooldescendants",
|
||||
method: "getmempooldescendants",
|
||||
params: [txid, verbose]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(txids).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getmempooldescendants",
|
||||
method: "getmempooldescendants",
|
||||
params: [req.params.txid, verbose]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getMempoolEntry/:txid",
|
||||
config.blockchainRateLimit12,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
let txids = JSON.parse(req.params.txid)
|
||||
if (txids.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 txids"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
txids = txids.map(txid =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getmempoolentry",
|
||||
method: "getmempoolentry",
|
||||
params: [txid]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(txids).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getmempoolentry",
|
||||
method: "getmempoolentry",
|
||||
params: [req.params.txid]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getMempoolInfo",
|
||||
config.blockchainRateLimit13,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getmempoolinfo"
|
||||
requestConfig.data.method = "getmempoolinfo"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getRawMempool",
|
||||
config.blockchainRateLimit14,
|
||||
async (req, res, next) => {
|
||||
let verbose = false
|
||||
if (req.query.verbose && req.query.verbose === true) verbose = true
|
||||
|
||||
requestConfig.data.id = "getrawmempool"
|
||||
requestConfig.data.method = "getrawmempool"
|
||||
requestConfig.data.params = [verbose]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getTxOut/:txid/:n",
|
||||
config.blockchainRateLimit15,
|
||||
async (req, res, next) => {
|
||||
let include_mempool = false
|
||||
if (req.query.include_mempool && req.query.include_mempool === "true")
|
||||
include_mempool = true
|
||||
|
||||
requestConfig.data.id = "gettxout"
|
||||
requestConfig.data.method = "gettxout"
|
||||
requestConfig.data.params = [
|
||||
req.params.txid,
|
||||
parseInt(req.params.n),
|
||||
include_mempool
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getTxOutProof/:txids",
|
||||
config.blockchainRateLimit16,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "gettxoutproof"
|
||||
requestConfig.data.method = "gettxoutproof"
|
||||
requestConfig.data.params = [req.params.txids]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
//
|
||||
// router.get('/preciousBlock/:hash', async (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"preciousblock",
|
||||
// method: "preciousblock",
|
||||
// params: [
|
||||
// req.params.hash
|
||||
// ]
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(JSON.stringify(response.data.result));
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.post('/pruneBlockchain/:height', async (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"pruneblockchain",
|
||||
// method: "pruneblockchain",
|
||||
// params: [
|
||||
// req.params.height
|
||||
// ]
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/verifyChain', async (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"verifychain",
|
||||
// method: "verifychain"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
|
||||
router.get(
|
||||
"/verifyTxOutProof/:proof",
|
||||
config.blockchainRateLimit17,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "verifytxoutproof"
|
||||
requestConfig.data.method = "verifytxoutproof"
|
||||
requestConfig.data.params = [req.params.proof]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
@@ -1,106 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
//const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default;
|
||||
//const BITBOX = new BITBOXCli();
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
controlRateLimit1: undefined,
|
||||
controlRateLimit2: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 3) {
|
||||
config[`controlRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.controlRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "control" })
|
||||
})
|
||||
|
||||
router.get("/getInfo", config.controlRateLimit2, async (req, res, next) => {
|
||||
requestConfig.data.id = "getinfo"
|
||||
requestConfig.data.method = "getinfo"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
})
|
||||
|
||||
// router.get('/getMemoryInfo', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"getmemoryinfo",
|
||||
// method: "getmemoryinfo"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/help', (req, res, next) => {
|
||||
// BITBOX.Control.help()
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.post('/stop', (req, res, next) => {
|
||||
// BITBOX.Control.stop()
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = router
|
||||
@@ -1,529 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default
|
||||
const BITBOX = new BITBOXCli()
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
dataRetrievalRateLimit1: undefined,
|
||||
dataRetrievalRateLimit2: undefined,
|
||||
dataRetrievalRateLimit3: undefined,
|
||||
dataRetrievalRateLimit4: undefined,
|
||||
dataRetrievalRateLimit5: undefined,
|
||||
dataRetrievalRateLimit6: undefined,
|
||||
dataRetrievalRateLimit7: undefined,
|
||||
dataRetrievalRateLimit8: undefined,
|
||||
dataRetrievalRateLimit9: undefined,
|
||||
dataRetrievalRateLimit10: undefined,
|
||||
dataRetrievalRateLimit11: undefined,
|
||||
dataRetrievalRateLimit12: undefined,
|
||||
dataRetrievalRateLimit13: undefined,
|
||||
dataRetrievalRateLimit14: undefined,
|
||||
dataRetrievalRateLimit15: undefined,
|
||||
dataRetrievalRateLimit16: undefined,
|
||||
dataRetrievalRateLimit17: undefined,
|
||||
dataRetrievalRateLimit18: undefined,
|
||||
dataRetrievalRateLimit19: undefined,
|
||||
dataRetrievalRateLimit20: undefined,
|
||||
dataRetrievalRateLimit21: undefined,
|
||||
dataRetrievalRateLimit22: undefined,
|
||||
dataRetrievalRateLimit23: undefined,
|
||||
dataRetrievalRateLimit24: undefined,
|
||||
dataRetrievalRateLimit25: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 26) {
|
||||
config[`dataRetrievalRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.dataRetrievalRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "dataRetrieval" })
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/balancesForAddress/:address",
|
||||
config.dataRetrievalRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getallbalancesforaddress"
|
||||
requestConfig.data.method = "whc_getallbalancesforaddress"
|
||||
requestConfig.data.params = [req.params.address]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
// Check for no balance error
|
||||
if (
|
||||
error &&
|
||||
error.response &&
|
||||
error.response.data &&
|
||||
error.response.data.error &&
|
||||
error.response.data.error.code === -8 &&
|
||||
error.response.data.error.message === "Address not found"
|
||||
)
|
||||
res.json([])
|
||||
else res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/balancesForId/:propertyId",
|
||||
config.dataRetrievalRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getallbalancesforid"
|
||||
requestConfig.data.method = "whc_getallbalancesforid"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
//res.status(500).send(error.response.data.error)
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/balance/:address/:propertyId",
|
||||
config.dataRetrievalRateLimit3,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getbalance"
|
||||
requestConfig.data.method = "whc_getbalance"
|
||||
requestConfig.data.params = [
|
||||
req.params.address,
|
||||
parseInt(req.params.propertyId)
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/balancesHash/:propertyId",
|
||||
config.dataRetrievalRateLimit4,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getbalanceshash"
|
||||
requestConfig.data.method = "whc_getbalanceshash"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/crowdSale/:propertyId",
|
||||
config.dataRetrievalRateLimit5,
|
||||
async (req, res, next) => {
|
||||
let verbose = false
|
||||
if (req.query.verbose && req.query.verbose === "true") verbose = true
|
||||
|
||||
requestConfig.data.id = "whc_getcrowdsale"
|
||||
requestConfig.data.method = "whc_getcrowdsale"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId), verbose]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
//res.status(500).send(error.response.data.error);
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/currentConsensusHash",
|
||||
config.dataRetrievalRateLimit6,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getcurrentconsensushash"
|
||||
requestConfig.data.method = "whc_getcurrentconsensushash"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/grants/:propertyId",
|
||||
config.dataRetrievalRateLimit8,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getgrants"
|
||||
requestConfig.data.method = "whc_getgrants"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
//res.status(500).send(error.response.data.error);
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get("/info", config.dataRetrievalRateLimit9, async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getinfo"
|
||||
requestConfig.data.method = "whc_getinfo"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/payload/:txid",
|
||||
config.dataRetrievalRateLimit10,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getpayload"
|
||||
requestConfig.data.method = "whc_getpayload"
|
||||
requestConfig.data.params = [req.params.txid]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/property/:propertyId",
|
||||
config.dataRetrievalRateLimit11,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getproperty"
|
||||
requestConfig.data.method = "whc_getproperty"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/seedBlocks/:startBlock/:endBlock",
|
||||
config.dataRetrievalRateLimit12,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getseedblocks"
|
||||
requestConfig.data.method = "whc_getseedblocks"
|
||||
requestConfig.data.params = [
|
||||
parseInt(req.params.startBlock),
|
||||
parseInt(req.params.endBlock)
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/STO/:txid/:recipientFilter",
|
||||
config.dataRetrievalRateLimit13,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_getsto"
|
||||
requestConfig.data.method = "whc_getsto"
|
||||
requestConfig.data.params = [req.params.txid, req.params.recipientFilter]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/transaction/:txid",
|
||||
config.dataRetrievalRateLimit14,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_gettransaction"
|
||||
requestConfig.data.method = "whc_gettransaction"
|
||||
requestConfig.data.params = [req.params.txid]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
//res.status(500).send(error.response.data.error);
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/blockTransactions/:index",
|
||||
config.dataRetrievalRateLimit15,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_listblocktransactions"
|
||||
requestConfig.data.method = "whc_listblocktransactions"
|
||||
requestConfig.data.params = [parseInt(req.params.index)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/pendingTransactions",
|
||||
config.dataRetrievalRateLimit16,
|
||||
async (req, res, next) => {
|
||||
const params = []
|
||||
if (req.query.address) params.push(req.query.address)
|
||||
|
||||
requestConfig.data.id = "whc_listpendingtransactions"
|
||||
requestConfig.data.method = "whc_listpendingtransactions"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
//res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/properties",
|
||||
config.dataRetrievalRateLimit17,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_listproperties"
|
||||
requestConfig.data.method = "whc_listproperties"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/frozenBalance/:address/:propertyId",
|
||||
config.dataRetrievalRateLimit18,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
BITBOX.Address.toCashAddress(req.params.address),
|
||||
parseInt(req.params.propertyId)
|
||||
]
|
||||
requestConfig.data.id = "whc_getfrozenbalance"
|
||||
requestConfig.data.method = "whc_getfrozenbalance"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/frozenBalanceForAddress/:address",
|
||||
config.dataRetrievalRateLimit19,
|
||||
async (req, res, next) => {
|
||||
const params = [BITBOX.Address.toCashAddress(req.params.address)]
|
||||
requestConfig.data.id = "whc_getfrozenbalanceforaddress"
|
||||
requestConfig.data.method = "whc_getfrozenbalanceforaddress"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/frozenBalanceForId/:propertyId",
|
||||
config.dataRetrievalRateLimit20,
|
||||
async (req, res, next) => {
|
||||
const params = [parseInt(req.params.propertyId)]
|
||||
requestConfig.data.id = "whc_getfrozenbalanceforid"
|
||||
requestConfig.data.method = "whc_getfrozenbalanceforid"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/ERC721AddressTokens/:address/:propertyId",
|
||||
config.dataRetrievalRateLimit21,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.address, req.params.propertyId]
|
||||
requestConfig.data.id = "whc_getERC721AddressTokens"
|
||||
requestConfig.data.method = "whc_getERC721AddressTokens"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/ERC721PropertyDestroyTokens/:propertyId",
|
||||
config.dataRetrievalRateLimit22,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.propertyId]
|
||||
requestConfig.data.id = "whc_getERC721PropertyDestroyTokens"
|
||||
requestConfig.data.method = "whc_getERC721PropertyDestroyTokens"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/ERC721PropertyNews/:propertyId",
|
||||
config.dataRetrievalRateLimit23,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.propertyId]
|
||||
requestConfig.data.id = "whc_getERC721PropertyNews"
|
||||
requestConfig.data.method = "whc_getERC721PropertyNews"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/ERC721TokenNews/:propertyId/:tokenId",
|
||||
config.dataRetrievalRateLimit24,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.propertyId, req.params.tokenId]
|
||||
requestConfig.data.id = "whc_getERC721TokenNews"
|
||||
requestConfig.data.method = "whc_getERC721TokenNews"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/ownerOfERC721Token/:propertyId/:tokenId/:address",
|
||||
config.dataRetrievalRateLimit25,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
req.params.propertyId,
|
||||
req.params.tokenId,
|
||||
req.params.address
|
||||
]
|
||||
requestConfig.data.id = "whc_ownerOfERC721Token"
|
||||
requestConfig.data.method = "whc_ownerOfERC721Token"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
@@ -1,75 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
//const axios = require("axios");
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
//const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default;
|
||||
//const BITBOX = new BITBOXCli();
|
||||
|
||||
//const BitboxHTTP = axios.create({
|
||||
// baseURL: process.env.RPC_BASEURL,
|
||||
//});
|
||||
//const username = process.env.RPC_USERNAME;
|
||||
//const password = process.env.RPC_PASSWORD;
|
||||
|
||||
const config = {
|
||||
generatingRateLimit1: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 2) {
|
||||
config[`generatingRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
router.get("/", config.generatingRateLimit1, (req, res, next) => {
|
||||
res.json({ status: "generating" })
|
||||
})
|
||||
//
|
||||
// router.post('/generateToAddress/:nblocks/:address', (req, res, next) => {
|
||||
// let maxtries = 1000000;
|
||||
// if(req.query.maxtries) {
|
||||
// maxtries = parseInt(req.query.maxtries);
|
||||
// }
|
||||
//
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"generatetoaddress",
|
||||
// method: "generatetoaddress",
|
||||
// params: [
|
||||
// req.params.nblocks,
|
||||
// req.params.address,
|
||||
// maxtries
|
||||
// ]
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = router
|
||||
@@ -1,27 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const healthCheckRateLimit = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
/* GET home page. */
|
||||
router.get("/", healthCheckRateLimit, (req, res, next) => {
|
||||
res.json({ status: "winning" })
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,35 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const config = {
|
||||
indexRateLimit1: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 2) {
|
||||
config[`indexRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60 * 60 * 1000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
/* GET home page. */
|
||||
router.get("/v1", config.indexRateLimit1, (req, res, next) => {
|
||||
res.render("swagger")
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,145 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
//const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default;
|
||||
//const BITBOX = new BITBOXCli();
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
miningRateLimit1: undefined,
|
||||
miningRateLimit2: undefined,
|
||||
miningRateLimit3: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 4) {
|
||||
config[`miningRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.miningRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "mining" })
|
||||
})
|
||||
//
|
||||
// router.get('/getBlockTemplate/:templateRequest', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"getblocktemplate",
|
||||
// method: "getblocktemplate",
|
||||
// params: [
|
||||
// req.params.templateRequest
|
||||
// ]
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
|
||||
router.get(
|
||||
"/getMiningInfo",
|
||||
config.miningRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getmininginfo"
|
||||
requestConfig.data.method = "getmininginfo"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getNetworkHashps",
|
||||
config.miningRateLimit3,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "getnetworkhashps"
|
||||
requestConfig.data.method = "getnetworkhashps"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
//
|
||||
// router.post('/submitBlock/:hex', (req, res, next) => {
|
||||
// let parameters = '';
|
||||
// if(req.query.parameters && req.query.parameters !== '') {
|
||||
// parameters = true;
|
||||
// }
|
||||
//
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"submitblock",
|
||||
// method: "submitblock",
|
||||
// params: [
|
||||
// req.params.hex,
|
||||
// parameters
|
||||
// ]
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = router
|
||||
@@ -1,202 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
//const axios = require("axios");
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
//const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default;
|
||||
//const BITBOX = new BITBOXCli();
|
||||
|
||||
//const BitboxHTTP = axios.create({
|
||||
// baseURL: process.env.RPC_BASEURL,
|
||||
//});
|
||||
//const username = process.env.RPC_USERNAME;
|
||||
//const password = process.env.RPC_PASSWORD;
|
||||
|
||||
const config = {
|
||||
networkRateLimit1: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 2) {
|
||||
config[`networkRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
router.get("/", config.networkRateLimit1, (req, res, next) => {
|
||||
res.json({ status: "network" })
|
||||
})
|
||||
|
||||
// router.post('/addNode/:node/:command', (req, res, next) => {
|
||||
// BITBOX.Network.addNode(req.params.node, req.params.command)
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.post('/clearBanned', (req, res, next) => {
|
||||
// BITBOX.Network.clearBanned()
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.post('/disconnectNode/:address/:nodeid', (req, res, next) => {
|
||||
// BITBOX.Network.disconnectNode(req.params.address, req.params.nodeid)
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/getAddedNodeInfo/:node', (req, res, next) => {
|
||||
// BITBOX.Network.getAddedNodeInfo(req.params.node)
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/getConnectionCount', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"getconnectioncount",
|
||||
// method: "getconnectioncount"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/getNetTotals', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"getnettotals",
|
||||
// method: "getnettotals"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/getNetworkInfo', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"getnetworkinfo",
|
||||
// method: "getnetworkinfo"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/getPeerInfo', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"getpeerinfo",
|
||||
// method: "getpeerinfo"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(response.data.result);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.get('/ping', (req, res, next) => {
|
||||
// BitboxHTTP({
|
||||
// method: 'post',
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// id:"ping",
|
||||
// method: "ping"
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// res.json(JSON.stringify(response.data.result));
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.post('/setBan/:subnet/:command', (req, res, next) => {
|
||||
// // TODO finish this
|
||||
// BITBOX.Network.getConnectionCount(req.params.subnet, req.params.command)
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// router.post('/setNetworkActive/:state', (req, res, next) => {
|
||||
// let state = true;
|
||||
// if(req.params.state && req.params.state === 'false') {
|
||||
// state = false;
|
||||
// }
|
||||
// BITBOX.Network.getConnectionCount(state)
|
||||
// .then((result) => {
|
||||
// res.json(result);
|
||||
// }, (err) => { console.log(err);
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = router
|
||||
@@ -1,480 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default
|
||||
const BITBOX = new BITBOXCli()
|
||||
|
||||
const config = {
|
||||
payloadCreationRateLimit1: undefined,
|
||||
payloadCreationRateLimit2: undefined,
|
||||
payloadCreationRateLimit3: undefined,
|
||||
payloadCreationRateLimit4: undefined,
|
||||
payloadCreationRateLimit5: undefined,
|
||||
payloadCreationRateLimit6: undefined,
|
||||
payloadCreationRateLimit7: undefined,
|
||||
payloadCreationRateLimit8: undefined,
|
||||
payloadCreationRateLimit9: undefined,
|
||||
payloadCreationRateLimit10: undefined,
|
||||
payloadCreationRateLimit11: undefined,
|
||||
payloadCreationRateLimit12: undefined,
|
||||
payloadCreationRateLimit13: undefined,
|
||||
payloadCreationRateLimit14: undefined,
|
||||
payloadCreationRateLimit15: undefined,
|
||||
payloadCreationRateLimit16: undefined,
|
||||
payloadCreationRateLimit17: undefined,
|
||||
payloadCreationRateLimit18: undefined,
|
||||
payloadCreationRateLimit19: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 20) {
|
||||
config[`payloadCreationRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.payloadCreationRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "payloadCreation" })
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/burnBCH",
|
||||
config.payloadCreationRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_burnbch"
|
||||
requestConfig.data.method = "whc_createpayload_burnbch"
|
||||
requestConfig.data.params = []
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/changeIssuer/:propertyId",
|
||||
config.payloadCreationRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_changeissuer"
|
||||
requestConfig.data.method = "whc_createpayload_changeissuer"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/closeCrowdSale/:propertyId",
|
||||
config.payloadCreationRateLimit3,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_closecrowdsale"
|
||||
requestConfig.data.method = "whc_createpayload_closecrowdsale"
|
||||
requestConfig.data.params = [parseInt(req.params.propertyId)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/grant/:propertyId/:amount",
|
||||
config.payloadCreationRateLimit4,
|
||||
async (req, res, next) => {
|
||||
const params = [parseInt(req.params.propertyId), req.params.amount]
|
||||
if (req.query.memo) params.push(req.query.memo)
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_grant"
|
||||
requestConfig.data.method = "whc_createpayload_grant"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
//res.status(500).send(error.response.data.error);
|
||||
res.status(500)
|
||||
return res.send(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/crowdsale/:ecosystem/:propertyPrecision/:previousId/:category/:subcategory/:name/:url/:data/:propertyIdDesired/:tokensPerUnit/:deadline/:earlyBonus/:undefine/:totalNumber",
|
||||
config.payloadCreationRateLimit6,
|
||||
async (req, res, next) => {
|
||||
// Validate deadline
|
||||
const now = new Date()
|
||||
const OneHundredYears = 1000 * 60 * 60 * 24 * 365 * 100
|
||||
const OneHundredYearsFromNow = now.getTime() + OneHundredYears
|
||||
const OneHundredYearsFromNowUnixTimestamp = Math.floor(
|
||||
OneHundredYearsFromNow / 1000
|
||||
)
|
||||
if (req.params.deadline > OneHundredYearsFromNowUnixTimestamp) {
|
||||
res.status(422)
|
||||
res.send(
|
||||
"Invalid deadline. Unix timestamp should be less than 100 years from now. Unix timestamp === JavaScript getTime()/1000"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_issuancecrowdsale"
|
||||
requestConfig.data.method = "whc_createpayload_issuancecrowdsale"
|
||||
requestConfig.data.params = [
|
||||
parseInt(req.params.ecosystem),
|
||||
parseInt(req.params.propertyPrecision),
|
||||
parseInt(req.params.previousId),
|
||||
req.params.category,
|
||||
req.params.subcategory,
|
||||
req.params.name,
|
||||
req.params.url,
|
||||
req.params.data,
|
||||
parseInt(req.params.propertyIdDesired),
|
||||
req.params.tokensPerUnit,
|
||||
parseInt(req.params.deadline),
|
||||
parseInt(req.params.earlyBonus),
|
||||
parseInt(req.params.undefine),
|
||||
req.params.totalNumber
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/fixed/:ecosystem/:propertyPrecision/:previousId/:category/:subcategory/:name/:url/:data/:amount",
|
||||
config.payloadCreationRateLimit7,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_issuancefixed"
|
||||
requestConfig.data.method = "whc_createpayload_issuancefixed"
|
||||
requestConfig.data.params = [
|
||||
parseInt(req.params.ecosystem),
|
||||
parseInt(req.params.propertyPrecision),
|
||||
parseInt(req.params.previousId),
|
||||
req.params.category,
|
||||
req.params.subcategory,
|
||||
req.params.name,
|
||||
req.params.url,
|
||||
req.params.data,
|
||||
req.params.amount
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/managed/:ecosystem/:propertyPrecision/:previousId/:category/:subcategory/:name/:url/:data",
|
||||
config.payloadCreationRateLimit8,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_issuancemanaged"
|
||||
requestConfig.data.method = "whc_createpayload_issuancemanaged"
|
||||
requestConfig.data.params = [
|
||||
parseInt(req.params.ecosystem),
|
||||
parseInt(req.params.propertyPrecision),
|
||||
parseInt(req.params.previousId),
|
||||
req.params.category,
|
||||
req.params.subcategory,
|
||||
req.params.name,
|
||||
req.params.url,
|
||||
req.params.data
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/participateCrowdSale/:amount",
|
||||
config.payloadCreationRateLimit9,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_particrowdsale"
|
||||
requestConfig.data.method = "whc_createpayload_particrowdsale"
|
||||
requestConfig.data.params = [req.params.amount]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/revoke/:propertyId/:amount",
|
||||
config.payloadCreationRateLimit10,
|
||||
async (req, res, next) => {
|
||||
const params = [parseInt(req.params.propertyId), req.params.amount]
|
||||
if (req.query.memo) params.push(req.query.memo)
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_revoke"
|
||||
requestConfig.data.method = "whc_createpayload_revoke"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/sendAll/:ecosystem",
|
||||
config.payloadCreationRateLimit11,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_sendall"
|
||||
requestConfig.data.method = "whc_createpayload_sendall"
|
||||
requestConfig.data.params = [parseInt(req.params.ecosystem)]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/simpleSend/:propertyId/:amount",
|
||||
config.payloadCreationRateLimit12,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createpayload_simplesend"
|
||||
requestConfig.data.method = "whc_createpayload_simplesend"
|
||||
requestConfig.data.params = [
|
||||
parseInt(req.params.propertyId),
|
||||
req.params.amount
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/STO/:propertyId/:amount",
|
||||
config.payloadCreationRateLimit13,
|
||||
async (req, res, next) => {
|
||||
const params = [parseInt(req.params.propertyId), req.params.amount]
|
||||
if (req.query.distributionProperty)
|
||||
params.push(parseInt(req.query.distributionProperty))
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_sto"
|
||||
requestConfig.data.method = "whc_createpayload_sto"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/freeze/:toAddress/:propertyId",
|
||||
config.payloadCreationRateLimit14,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
BITBOX.Address.toCashAddress(req.params.toAddress),
|
||||
parseInt(req.params.propertyId),
|
||||
"100"
|
||||
]
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_freeze"
|
||||
requestConfig.data.method = "whc_createpayload_freeze"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/unfreeze/:toAddress/:propertyId",
|
||||
config.payloadCreationRateLimit15,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
BITBOX.Address.toCashAddress(req.params.toAddress),
|
||||
parseInt(req.params.propertyId),
|
||||
"100"
|
||||
]
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_unfreeze"
|
||||
requestConfig.data.method = "whc_createpayload_unfreeze"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/issueERC721Property/:name/:symbol/:data/:url/:totalNumber",
|
||||
config.payloadCreationRateLimit16,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
req.params.name,
|
||||
req.params.symbol,
|
||||
req.params.data,
|
||||
req.params.url,
|
||||
req.params.totalNumber
|
||||
]
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_issueERC721property"
|
||||
requestConfig.data.method = "whc_createpayload_issueERC721property"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/issueERC721Token/:propertyId/:tokenId/:attributes/:url",
|
||||
config.payloadCreationRateLimit17,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
req.params.propertyId,
|
||||
req.params.tokenId,
|
||||
req.params.attributes,
|
||||
req.params.url
|
||||
]
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_issueERC721token"
|
||||
requestConfig.data.method = "whc_createpayload_issueERC721token"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/transferERC721Token/:owner/:receiver/:propertyId",
|
||||
config.payloadCreationRateLimit18,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
req.params.owner,
|
||||
req.params.receiver,
|
||||
req.params.propertyId
|
||||
]
|
||||
if (req.query.tokenId) params.push(req.query.tokenId)
|
||||
|
||||
requestConfig.data.id = "whc_transferERC721Token"
|
||||
requestConfig.data.method = "whc_transferERC721Token"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/destroyERC721Token/:propertyId",
|
||||
config.payloadCreationRateLimit19,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.propertyId]
|
||||
if (req.query.tokenId) params.push(req.query.tokenId)
|
||||
|
||||
requestConfig.data.id = "whc_createpayload_destroyERC721token"
|
||||
requestConfig.data.method = "whc_createpayload_destroyERC721token"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
@@ -1,511 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
//const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default;
|
||||
//const BITBOX = new BITBOXCli();
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
rawTransactionsRateLimit1: undefined,
|
||||
rawTransactionsRateLimit2: undefined,
|
||||
rawTransactionsRateLimit3: undefined,
|
||||
rawTransactionsRateLimit4: undefined,
|
||||
rawTransactionsRateLimit5: undefined,
|
||||
rawTransactionsRateLimit6: undefined,
|
||||
rawTransactionsRateLimit7: undefined,
|
||||
rawTransactionsRateLimit8: undefined,
|
||||
rawTransactionsRateLimit9: undefined,
|
||||
rawTransactionsRateLimit10: undefined,
|
||||
rawTransactionsRateLimit11: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
|
||||
while (i < 12) {
|
||||
config[`rawTransactionsRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
//const requestConfig = {
|
||||
// method: "post",
|
||||
// auth: {
|
||||
// username: username,
|
||||
// password: password,
|
||||
// },
|
||||
// data: {
|
||||
// jsonrpc: "1.0",
|
||||
// },
|
||||
//};
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.rawTransactionsRateLimit1, (req, res, next) => {
|
||||
res.json({ status: "rawtransactions" })
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/decodeRawTransaction/:hex",
|
||||
config.rawTransactionsRateLimit2,
|
||||
(req, res, next) => {
|
||||
try {
|
||||
let transactions = JSON.parse(req.params.hex)
|
||||
if (transactions.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 transactions"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
transactions = transactions.map(transaction =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "decoderawtransaction",
|
||||
method: "decoderawtransaction",
|
||||
params: [transaction]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(transactions).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "decoderawtransaction",
|
||||
method: "decoderawtransaction",
|
||||
params: [req.params.hex]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/decodeScript/:script",
|
||||
config.rawTransactionsRateLimit3,
|
||||
(req, res, next) => {
|
||||
try {
|
||||
let scripts = JSON.parse(req.params.script)
|
||||
if (scripts.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 scripts"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
scripts = scripts.map(script =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "decodescript",
|
||||
method: "decodescript",
|
||||
params: [script]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(scripts).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "decodescript",
|
||||
method: "decodescript",
|
||||
params: [req.params.script]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/getRawTransaction/:txid",
|
||||
config.rawTransactionsRateLimit4,
|
||||
(req, res, next) => {
|
||||
let verbose = 0
|
||||
if (req.query.verbose && req.query.verbose === "true") verbose = 1
|
||||
|
||||
try {
|
||||
let txids = JSON.parse(req.params.txid)
|
||||
if (txids.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 txids"
|
||||
})
|
||||
}
|
||||
const result = []
|
||||
txids = txids.map(txid =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getrawtransaction",
|
||||
method: "getrawtransaction",
|
||||
params: [txid, verbose]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(txids).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "getrawtransaction",
|
||||
method: "getrawtransaction",
|
||||
params: [req.params.txid, verbose]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/sendRawTransaction/:hex",
|
||||
config.rawTransactionsRateLimit5,
|
||||
(req, res, next) => {
|
||||
try {
|
||||
let transactions = JSON.parse(req.params.hex)
|
||||
if (transactions.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 transactions"
|
||||
})
|
||||
}
|
||||
|
||||
const result = []
|
||||
transactions = transactions.map(transaction =>
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "sendrawtransaction",
|
||||
method: "sendrawtransaction",
|
||||
params: [transaction]
|
||||
}
|
||||
}).catch(error => {
|
||||
try {
|
||||
return {
|
||||
data: {
|
||||
result: error.response.data.error.message
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
return {
|
||||
data: {
|
||||
result: "unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
axios.all(transactions).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data.result
|
||||
result.push(parsed)
|
||||
}
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
BitboxHTTP({
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0",
|
||||
id: "sendrawtransaction",
|
||||
method: "sendrawtransaction",
|
||||
params: [req.params.hex]
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
res.json(response.data.result)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/change/:rawtx/:prevTxs/:destination/:fee",
|
||||
config.rawTransactionsRateLimit6,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const params = [
|
||||
req.params.rawtx,
|
||||
JSON.parse(req.params.prevTxs),
|
||||
req.params.destination,
|
||||
parseFloat(req.params.fee)
|
||||
]
|
||||
if (req.query.position) params.push(parseInt(req.query.position))
|
||||
|
||||
requestConfig.data.id = "whc_createrawtx_change"
|
||||
requestConfig.data.method = "whc_createrawtx_change"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
} catch (err) {
|
||||
// console.log(`Error in /change: `)
|
||||
res.status(500)
|
||||
res.send(`Error in /change: ${err.message}`)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/input/:rawTx/:txid/:n",
|
||||
config.rawTransactionsRateLimit7,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createrawtx_input"
|
||||
requestConfig.data.method = "whc_createrawtx_input"
|
||||
requestConfig.data.params = [
|
||||
req.params.rawTx,
|
||||
req.params.txid,
|
||||
parseInt(req.params.n)
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/opReturn/:rawTx/:payload",
|
||||
config.rawTransactionsRateLimit8,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "whc_createrawtx_opreturn"
|
||||
requestConfig.data.method = "whc_createrawtx_opreturn"
|
||||
requestConfig.data.params = [req.params.rawTx, req.params.payload]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/reference/:rawTx/:destination",
|
||||
config.rawTransactionsRateLimit9,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.rawTx, req.params.destination]
|
||||
if (req.query.amount) params.push(req.query.amount)
|
||||
|
||||
requestConfig.data.id = "whc_createrawtx_reference"
|
||||
requestConfig.data.method = "whc_createrawtx_reference"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/decodeTransaction/:rawTx",
|
||||
config.rawTransactionsRateLimit10,
|
||||
async (req, res, next) => {
|
||||
const params = [req.params.rawTx]
|
||||
if (req.query.prevTxs) params.push(JSON.parse(req.query.prevTxs))
|
||||
|
||||
if (req.query.height) params.push(req.query.height)
|
||||
|
||||
requestConfig.data.id = "whc_decodetransaction"
|
||||
requestConfig.data.method = "whc_decodetransaction"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error.message)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.post(
|
||||
"/create/:inputs/:outputs",
|
||||
config.rawTransactionsRateLimit11,
|
||||
async (req, res, next) => {
|
||||
const params = [
|
||||
JSON.parse(req.params.inputs),
|
||||
JSON.parse(req.params.outputs)
|
||||
]
|
||||
if (req.query.locktime) params.push(req.query.locktime)
|
||||
|
||||
requestConfig.data.id = "createrawtransaction"
|
||||
requestConfig.data.method = "createrawtransaction"
|
||||
requestConfig.data.params = params
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error.message)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
@@ -1,213 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
const bitdbToken = process.env.BITDB_TOKEN
|
||||
const bitboxproxy = require("slpjs").bitbox
|
||||
const utils = require("slpjs").utils
|
||||
|
||||
const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default
|
||||
const BITBOX = new BITBOXCli()
|
||||
|
||||
const config = {
|
||||
slpRateLimit1: undefined,
|
||||
slpRateLimit2: undefined,
|
||||
slpRateLimit3: undefined,
|
||||
slpRateLimit4: undefined,
|
||||
slpRateLimit5: undefined,
|
||||
slpRateLimit6: undefined,
|
||||
slpRateLimit7: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 8) {
|
||||
config[`slpRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
router.get("/", config.slpRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "slp" })
|
||||
})
|
||||
|
||||
router.get("/list", config.slpRateLimit2, async (req, res, next) => {
|
||||
try {
|
||||
const query = {
|
||||
v: 3,
|
||||
q: {
|
||||
find: { "out.h1": "534c5000", "out.s3": "GENESIS" },
|
||||
limit: 1000
|
||||
},
|
||||
r: {
|
||||
f:
|
||||
'[ .[] | { id: .tx.h, timestamp: (.blk.t | strftime("%Y-%m-%d %H:%M")), symbol: .out[0].s4, name: .out[0].s5, document: .out[0].s6 } ]'
|
||||
}
|
||||
}
|
||||
|
||||
const s = JSON.stringify(query)
|
||||
const b64 = Buffer.from(s).toString("base64")
|
||||
const url = `https://bitdb.network/q/${b64}`
|
||||
const header = {
|
||||
headers: { key: bitdbToken }
|
||||
}
|
||||
|
||||
const tokenRes = await axios.get(url, header)
|
||||
const tokens = tokenRes.data.c
|
||||
if (tokenRes.data.u && tokenRes.data.u.length) tokens.concat(tokenRes.u)
|
||||
res.json(tokens.reverse())
|
||||
|
||||
return tokens
|
||||
} catch (err) {
|
||||
res.status(500).send(err.response.data.error)
|
||||
}
|
||||
})
|
||||
|
||||
router.get("/list/:tokenId", config.slpRateLimit3, async (req, res, next) => {
|
||||
try {
|
||||
const query = {
|
||||
v: 3,
|
||||
q: {
|
||||
find: { "out.h1": "534c5000", "out.s3": "GENESIS" },
|
||||
limit: 1000
|
||||
},
|
||||
r: {
|
||||
f:
|
||||
'[ .[] | { id: .tx.h, timestamp: (.blk.t | strftime("%Y-%m-%d %H:%M")), symbol: .out[0].s4, name: .out[0].s5, document: .out[0].s6 } ]'
|
||||
}
|
||||
}
|
||||
|
||||
const s = JSON.stringify(query)
|
||||
const b64 = Buffer.from(s).toString("base64")
|
||||
const url = `https://bitdb.network/q/${b64}`
|
||||
const header = {
|
||||
headers: { key: bitdbToken }
|
||||
}
|
||||
|
||||
const tokenRes = await axios.get(url, header)
|
||||
const tokens = tokenRes.data.c
|
||||
if (tokenRes.data.u && tokenRes.data.u.length) tokens.concat(tokenRes.u)
|
||||
|
||||
tokens.forEach(token => {
|
||||
if (token.id === req.params.tokenId) return res.json(token)
|
||||
})
|
||||
} catch (err) {
|
||||
res.status(500).send(err.response.data.error)
|
||||
}
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/balancesForAddress/:address",
|
||||
config.slpRateLimit4,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const slpAddr = utils.toSlpAddress(req.params.address)
|
||||
const balances = await bitboxproxy.getAllTokenBalances(slpAddr)
|
||||
balances.slpAddress = slpAddr
|
||||
balances.cashAddress = utils.toCashAddress(slpAddr)
|
||||
balances.legacyAddress = BITBOX.Address.toLegacyAddress(
|
||||
balances.cashAddress
|
||||
)
|
||||
return res.json(balances)
|
||||
} catch (err) {
|
||||
res.status(500).send(err.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/balance/:address/:tokenId",
|
||||
config.slpRateLimit5,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const slpAddr = utils.toSlpAddress(req.params.address)
|
||||
const balances = await bitboxproxy.getAllTokenBalances(slpAddr)
|
||||
const query = {
|
||||
v: 3,
|
||||
q: {
|
||||
find: { "out.h1": "534c5000", "out.s3": "GENESIS" },
|
||||
limit: 1000
|
||||
},
|
||||
r: {
|
||||
f:
|
||||
'[ .[] | { id: .tx.h, timestamp: (.blk.t | strftime("%Y-%m-%d %H:%M")), symbol: .out[0].s4, name: .out[0].s5, document: .out[0].s6 } ]'
|
||||
}
|
||||
}
|
||||
|
||||
const s = JSON.stringify(query)
|
||||
const b64 = Buffer.from(s).toString("base64")
|
||||
const url = `https://bitdb.network/q/${b64}`
|
||||
const header = {
|
||||
headers: { key: bitdbToken }
|
||||
}
|
||||
|
||||
const tokenRes = await axios.get(url, header)
|
||||
const tokens = tokenRes.data.c
|
||||
if (tokenRes.data.u && tokenRes.data.u.length) tokens.concat(tokenRes.u)
|
||||
|
||||
let t
|
||||
tokens.forEach(token => {
|
||||
if (token.id === req.params.tokenId) t = token
|
||||
})
|
||||
|
||||
const obj = {}
|
||||
obj.id = t.id
|
||||
obj.timestamp = t.timestamp
|
||||
obj.symbol = t.symbol
|
||||
obj.name = t.name
|
||||
obj.document = t.document
|
||||
obj.balance = balances[req.params.tokenId]
|
||||
obj.slpAddress = slpAddr
|
||||
obj.cashAddress = utils.toCashAddress(slpAddr)
|
||||
obj.legacyAddress = BITBOX.Address.toLegacyAddress(obj.cashAddress)
|
||||
return res.json(obj)
|
||||
} catch (err) {
|
||||
res.status(500).send(err.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/address/convert/:address",
|
||||
config.slpRateLimit6,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const slpAddr = utils.toSlpAddress(req.params.address)
|
||||
const obj = {}
|
||||
obj.slpAddress = slpAddr
|
||||
obj.cashAddress = utils.toCashAddress(slpAddr)
|
||||
obj.legacyAddress = BITBOX.Address.toLegacyAddress(obj.cashAddress)
|
||||
return res.json(obj)
|
||||
} catch (err) {
|
||||
res.status(500).send(err.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get(
|
||||
"/balancesForToken/:tokenId",
|
||||
config.slpRateLimit7,
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const balances = "use v2"
|
||||
return res.json(balances)
|
||||
} catch (err) {
|
||||
res.status(500).send(err.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
@@ -1,93 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default
|
||||
const BITBOX = new BITBOXCli()
|
||||
|
||||
const config = {
|
||||
transactionRateLimit1: undefined,
|
||||
transactionRateLimit2: undefined
|
||||
}
|
||||
|
||||
const processInputs = tx => {
|
||||
if (tx.vin) {
|
||||
tx.vin.forEach(vin => {
|
||||
if (!vin.coinbase) {
|
||||
const address = vin.addr
|
||||
vin.legacyAddress = BITBOX.Address.toLegacyAddress(address)
|
||||
vin.cashAddress = BITBOX.Address.toCashAddress(address)
|
||||
vin.value = vin.valueSat
|
||||
delete vin.addr
|
||||
delete vin.valueSat
|
||||
delete vin.doubleSpentTxID
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 6) {
|
||||
config[`transactionRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
router.get("/", config.transactionRateLimit1, (req, res, next) => {
|
||||
res.json({ status: "transaction" })
|
||||
})
|
||||
|
||||
router.get("/details/:txid", config.transactionRateLimit1, (req, res, next) => {
|
||||
try {
|
||||
let txs = JSON.parse(req.params.txid)
|
||||
if (txs.length > 20) {
|
||||
res.json({
|
||||
error: "Array too large. Max 20 txids"
|
||||
})
|
||||
}
|
||||
|
||||
const result = []
|
||||
txs = txs.map(tx => axios.get(`${process.env.BITCOINCOM_BASEURL}tx/${tx}`))
|
||||
axios.all(txs).then(
|
||||
axios.spread((...args) => {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const parsed = args[i].data
|
||||
result.push(parsed)
|
||||
}
|
||||
result.forEach(tx => {
|
||||
processInputs(tx)
|
||||
})
|
||||
res.json(result)
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
axios
|
||||
.get(`${process.env.BITCOINCOM_BASEURL}tx/${req.params.txid}`)
|
||||
.then(response => {
|
||||
const parsed = response.data
|
||||
if (parsed) processInputs(parsed)
|
||||
|
||||
res.json(parsed)
|
||||
})
|
||||
.catch(error => {
|
||||
res.send(error.response.data.error.message)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,70 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const axios = require("axios")
|
||||
const RateLimit = require("express-rate-limit")
|
||||
|
||||
const BitboxHTTP = axios.create({
|
||||
baseURL: process.env.RPC_BASEURL
|
||||
})
|
||||
const username = process.env.RPC_USERNAME
|
||||
const password = process.env.RPC_PASSWORD
|
||||
|
||||
const config = {
|
||||
utilRateLimit1: undefined,
|
||||
utilRateLimit2: undefined
|
||||
}
|
||||
|
||||
let i = 1
|
||||
while (i < 3) {
|
||||
config[`utilRateLimit${i}`] = new RateLimit({
|
||||
windowMs: 60000, // 1 hour window
|
||||
delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
max: 60, // start blocking after 60 requests
|
||||
handler: function(req, res /*next*/) {
|
||||
res.format({
|
||||
json: function() {
|
||||
res.status(500).json({
|
||||
error: "Too many requests. Limits are 60 requests per minute."
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
method: "post",
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: {
|
||||
jsonrpc: "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", config.utilRateLimit1, async (req, res, next) => {
|
||||
res.json({ status: "util" })
|
||||
})
|
||||
|
||||
router.get(
|
||||
"/validateAddress/:address",
|
||||
config.utilRateLimit2,
|
||||
async (req, res, next) => {
|
||||
requestConfig.data.id = "validateaddress"
|
||||
requestConfig.data.method = "validateaddress"
|
||||
requestConfig.data.params = [req.params.address]
|
||||
|
||||
try {
|
||||
const response = await BitboxHTTP(requestConfig)
|
||||
res.json(response.data.result)
|
||||
} catch (error) {
|
||||
res.status(500).send(error.response.data.error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user