mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61b1b8ebdf | ||
|
|
de6c19e877 | ||
|
|
66efb76f94 | ||
|
|
1250a40ff0 | ||
|
|
6786ca9ee5 | ||
|
|
e96b9e7a44 | ||
|
|
d29f99965f | ||
|
|
9825ec1bab | ||
|
|
fb61cfeca3 | ||
|
|
5f9a635ab5 | ||
|
|
41c5504846 | ||
|
|
e5f9455fbb | ||
|
|
20cb48caff | ||
|
|
f241aed5b2 |
+3
-3
@@ -14,7 +14,7 @@
|
||||
"scripts": {
|
||||
"start": "node ./src/app.js",
|
||||
"dev": "nodemon ./dist/app.js",
|
||||
"test": "npm run lint && npm run test-v4",
|
||||
"test": "npm run lint && npm run test-v5",
|
||||
"lint": "standard --env mocha --fix",
|
||||
"test-v4": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v4/",
|
||||
"test-v5": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v5/",
|
||||
@@ -23,7 +23,7 @@
|
||||
"test:integration:nft": "mocha --timeout 25000 -g '#nft' test/v4/integration/nft.js",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/routes/v4 -o docs",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/routes/v5 -o docs",
|
||||
"test:temp1": "export NETWORK=mainnet && export TEST=integration && mocha -g '#utxosBulk' --exit --timeout 30000 test/v5/",
|
||||
"test:temp2": "export NETWORK=mainnet && mocha -g '#utxosBulk' --exit --timeout 30000 test/v5/"
|
||||
},
|
||||
@@ -86,6 +86,6 @@
|
||||
},
|
||||
"apidoc": {
|
||||
"title": "bch-api",
|
||||
"url": "https://api.fullstack.cash/v4"
|
||||
"url": "https://api.fullstack.cash/v5"
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -46,12 +46,14 @@ const ControlV5 = require('./routes/v5/full-node/control')
|
||||
const MiningV5 = require('./routes/v5/full-node/mining')
|
||||
const networkV5 = require('./routes/v5/full-node/network')
|
||||
const RawtransactionsV5 = require('./routes/v5/full-node/rawtransactions')
|
||||
const DSProofV5 = require('./routes/v5/full-node/dsproof')
|
||||
const UtilV5 = require('./routes/v5/util')
|
||||
const SlpV5 = require('./routes/v5/slp')
|
||||
const xpubV5 = require('./routes/v5/xpub')
|
||||
const ElectrumXV5 = require('./routes/v5/electrumx')
|
||||
const EncryptionV5 = require('./routes/v5/encryption')
|
||||
const PriceV5 = require('./routes/v5/price')
|
||||
const JWTV5 = require('./routes/v5/jwt')
|
||||
// const Ninsight = require('./routes/v5/ninsight')
|
||||
|
||||
require('dotenv').config()
|
||||
@@ -78,7 +80,8 @@ const electrumxv5 = new ElectrumXV5()
|
||||
const encryptionv5 = new EncryptionV5()
|
||||
const pricev5 = new PriceV5()
|
||||
const utilV5 = new UtilV5({ electrumx: electrumxv5 })
|
||||
|
||||
const dsproofV5 = new DSProofV5()
|
||||
const jwtV5 = new JWTV5()
|
||||
const app = express()
|
||||
|
||||
app.locals.env = process.env
|
||||
@@ -187,6 +190,8 @@ app.use(`/${v5prefix}/` + 'electrumx', electrumxv5.router)
|
||||
app.use(`/${v5prefix}/` + 'encryption', encryptionv5.router)
|
||||
app.use(`/${v5prefix}/` + 'price', pricev5.router)
|
||||
app.use(`/${v5prefix}/` + 'util', utilV5.router)
|
||||
app.use(`/${v5prefix}/` + 'dsproof', dsproofV5.router)
|
||||
app.use(`/${v5prefix}/` + 'jwt', jwtV5.router)
|
||||
|
||||
// const ninsight = new Ninsight()
|
||||
app.use(`/${v5prefix}/` + 'ninsight', ninsight.router)
|
||||
|
||||
@@ -25,7 +25,7 @@ class Price {
|
||||
|
||||
this.priceUrl = 'https://api.coinbase.com/v2/exchange-rates?currency=BCH'
|
||||
this.coinexPriceUrl =
|
||||
'https://api.coinex.com/v1/market/ticker?market=bchausdt'
|
||||
'https://api.coinex.com/v1/market/ticker?market=xecusdt'
|
||||
|
||||
this.bchCoinexPriceUrl =
|
||||
'https://api.coinex.com/v1/market/ticker?market=bchusdt'
|
||||
|
||||
+234
-271
@@ -32,7 +32,12 @@ class Electrum {
|
||||
this.bchjs = bchjs
|
||||
// _this.bitcore = bitcore
|
||||
|
||||
this.fulcrumApi = 'http://fulcrum-api.fullstackbch.nl/v1/'
|
||||
this.fulcrumApi = process.env.FULCRUM_API
|
||||
if (!this.fulcrumApi) {
|
||||
throw new Error(
|
||||
'FULCRUM_API env var not set. Can not connect to Fulcrum indexer.'
|
||||
)
|
||||
}
|
||||
|
||||
// _this.electrumx = new ElectrumCash(
|
||||
// 'bch-api',
|
||||
@@ -57,10 +62,10 @@ class Electrum {
|
||||
this.router.post('/tx/broadcast', this.broadcastTransaction)
|
||||
this.router.get('/block/headers/:height', this.getBlockHeaders)
|
||||
this.router.post('/block/headers', this.blockHeadersBulk)
|
||||
// this.router.get('/transactions/:address', this.getTransactions)
|
||||
// this.router.post('/transactions', this.transactionsBulk)
|
||||
// this.router.get('/unconfirmed/:address', this.getMempool)
|
||||
// this.router.post('/unconfirmed', this.mempoolBulk)
|
||||
this.router.get('/transactions/:address', this.getTransactions)
|
||||
this.router.post('/transactions', this.transactionsBulk)
|
||||
this.router.get('/unconfirmed/:address', this.getMempool)
|
||||
this.router.post('/unconfirmed', this.mempoolBulk)
|
||||
|
||||
_this = this
|
||||
}
|
||||
@@ -777,63 +782,53 @@ class Electrum {
|
||||
*
|
||||
*/
|
||||
// GET handler for single balance
|
||||
// async getTransactions (req, res, next) {
|
||||
// try {
|
||||
// const address = req.params.address
|
||||
//
|
||||
// // Reject if address is an array.
|
||||
// if (Array.isArray(address)) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// error: 'address can not be an array. Use POST for bulk upload.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // Ensure the address is in cash address format.
|
||||
// const cashAddr = _this.bchjs.Address.toCashAddress(address)
|
||||
//
|
||||
// // Prevent a common user error. Ensure they are using the correct network address.
|
||||
// const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
|
||||
// if (!networkIsValid) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// error:
|
||||
// 'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// wlogger.debug(
|
||||
// 'Executing electrumx/getTransactions with this address: ',
|
||||
// cashAddr
|
||||
// )
|
||||
//
|
||||
// // Get data from ElectrumX server.
|
||||
// const electrumResponse = await _this._transactionsFromElectrumx(cashAddr)
|
||||
// // console.log(`_utxosFromElectrumx(): ${JSON.stringify(electrumResponse, null, 2)}`)
|
||||
//
|
||||
// // Pass the error message if ElectrumX reports an error.
|
||||
// if (Object.prototype.hasOwnProperty.call(electrumResponse, 'code')) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// message: electrumResponse.message
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// res.status(200)
|
||||
// return res.json({
|
||||
// success: true,
|
||||
// transactions: electrumResponse
|
||||
// })
|
||||
// } catch (err) {
|
||||
// // Write out error to error log.
|
||||
// wlogger.error('Error in elecrumx.js/getTransactions().', err)
|
||||
//
|
||||
// return _this.errorHandler(err, res)
|
||||
// }
|
||||
// }
|
||||
async getTransactions (req, res, next) {
|
||||
try {
|
||||
const address = req.params.address
|
||||
|
||||
// Reject if address is an array.
|
||||
if (Array.isArray(address)) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'address can not be an array. Use POST for bulk upload.'
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure the address is in cash address format.
|
||||
const cashAddr = _this.bchjs.Address.toCashAddress(address)
|
||||
|
||||
// Prevent a common user error. Ensure they are using the correct network address.
|
||||
const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
|
||||
if (!networkIsValid) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error:
|
||||
'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
|
||||
})
|
||||
}
|
||||
|
||||
wlogger.debug(
|
||||
'Executing electrumx/getTransactions with this address: ',
|
||||
cashAddr
|
||||
)
|
||||
|
||||
// Get data from ElectrumX server.
|
||||
const response = await _this.axios.get(
|
||||
`${_this.fulcrumApi}electrumx/transactions/${address}`
|
||||
)
|
||||
// console.log('response', response, _this.fulcrumApi)
|
||||
|
||||
res.status(200)
|
||||
return res.json(response.data)
|
||||
} catch (err) {
|
||||
// Write out error to error log.
|
||||
wlogger.error('Error in elecrumx.js/getTransactions().', err)
|
||||
|
||||
return _this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /electrumx/transactions Get the transaction history for an array of addresses.
|
||||
@@ -848,82 +843,72 @@ class Electrum {
|
||||
*
|
||||
*/
|
||||
// POST handler for bulk queries on transaction histories for addresses.
|
||||
// async transactionsBulk (req, res, next) {
|
||||
// try {
|
||||
// let addresses = req.body.addresses
|
||||
//
|
||||
// // Reject if addresses is not an array.
|
||||
// if (!Array.isArray(addresses)) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// error: 'addresses needs to be an array. Use GET for single address.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // Enforce array size rate limits
|
||||
// if (!_this.routeUtils.validateArraySize(req, addresses)) {
|
||||
// res.status(400) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
||||
// return res.json({
|
||||
// error: 'Array too large.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// wlogger.debug(
|
||||
// 'Executing electrumx.js/transactionsBulk with these addresses: ',
|
||||
// addresses
|
||||
// )
|
||||
//
|
||||
// // Validate each element in the address array.
|
||||
// for (let i = 0; i < addresses.length; i++) {
|
||||
// const thisAddress = addresses[i]
|
||||
//
|
||||
// // Ensure the input is a valid BCH address.
|
||||
// try {
|
||||
// _this.bchjs.Address.toLegacyAddress(thisAddress)
|
||||
// } catch (err) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// error: `Invalid BCH address. Double check your address is valid: ${thisAddress}`
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // Prevent a common user error. Ensure they are using the correct network address.
|
||||
// const networkIsValid = _this.routeUtils.validateNetwork(thisAddress)
|
||||
// if (!networkIsValid) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// error: `Invalid network for address ${thisAddress}. Trying to use a testnet address on mainnet, or vice versa.`
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Loops through each address and creates an array of Promises, querying
|
||||
// // ElectrumX API in parallel.
|
||||
// addresses = addresses.map(async (address, index) => {
|
||||
// // console.log(`address: ${address}`)
|
||||
// const transactions = await _this._transactionsFromElectrumx(address)
|
||||
//
|
||||
// return {
|
||||
// transactions,
|
||||
// address
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// // Wait for all parallel Insight requests to return.
|
||||
// const result = await Promise.all(addresses)
|
||||
//
|
||||
// // Return the array of retrieved address information.
|
||||
// res.status(200)
|
||||
// return res.json({
|
||||
// success: true,
|
||||
// transactions: result
|
||||
// })
|
||||
// } catch (err) {
|
||||
// wlogger.error('Error in electrumx.js/transactionsBulk().', err)
|
||||
//
|
||||
// return _this.errorHandler(err, res)
|
||||
// }
|
||||
// }
|
||||
async transactionsBulk (req, res, next) {
|
||||
try {
|
||||
const addresses = req.body.addresses
|
||||
|
||||
// Reject if addresses is not an array.
|
||||
if (!Array.isArray(addresses)) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'addresses needs to be an array. Use GET for single address.'
|
||||
})
|
||||
}
|
||||
|
||||
// Enforce array size rate limits
|
||||
if (!_this.routeUtils.validateArraySize(req, addresses)) {
|
||||
res.status(400) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'Array too large.'
|
||||
})
|
||||
}
|
||||
|
||||
wlogger.debug(
|
||||
'Executing electrumx.js/transactionsBulk with these addresses: ',
|
||||
addresses
|
||||
)
|
||||
|
||||
// Validate each element in the address array.
|
||||
for (let i = 0; i < addresses.length; i++) {
|
||||
const thisAddress = addresses[i]
|
||||
|
||||
// Ensure the input is a valid BCH address.
|
||||
try {
|
||||
_this.bchjs.Address.toLegacyAddress(thisAddress)
|
||||
} catch (err) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `Invalid BCH address. Double check your address is valid: ${thisAddress}`
|
||||
})
|
||||
}
|
||||
|
||||
// Prevent a common user error. Ensure they are using the correct network address.
|
||||
const networkIsValid = _this.routeUtils.validateNetwork(thisAddress)
|
||||
if (!networkIsValid) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `Invalid network for address ${thisAddress}. Trying to use a testnet address on mainnet, or vice versa.`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const response = await _this.axios.post(
|
||||
`${_this.fulcrumApi}electrumx/transactions/`,
|
||||
{ addresses }
|
||||
)
|
||||
|
||||
res.status(200)
|
||||
return res.json(response.data)
|
||||
} catch (err) {
|
||||
wlogger.error('Error in electrumx.js/transactionsBulk().', err)
|
||||
|
||||
return _this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a promise that resolves to unconfirmed UTXO data (mempool) for an address.
|
||||
// Expects input to be a cash address, and input validation to have
|
||||
@@ -970,63 +955,53 @@ class Electrum {
|
||||
*
|
||||
*/
|
||||
// GET handler for single balance
|
||||
// async getMempool (req, res, next) {
|
||||
// try {
|
||||
// const address = req.params.address
|
||||
//
|
||||
// // Reject if address is an array.
|
||||
// if (Array.isArray(address)) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// error: 'address can not be an array. Use POST for bulk upload.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // Ensure the address is in cash address format.
|
||||
// const cashAddr = _this.bchjs.Address.toCashAddress(address)
|
||||
//
|
||||
// // Prevent a common user error. Ensure they are using the correct network address.
|
||||
// const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
|
||||
// if (!networkIsValid) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// error:
|
||||
// 'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// wlogger.debug(
|
||||
// 'Executing electrumx/getMempool with this address: ',
|
||||
// cashAddr
|
||||
// )
|
||||
//
|
||||
// // Get data from ElectrumX server.
|
||||
// const electrumResponse = await _this._mempoolFromElectrumx(cashAddr)
|
||||
// // console.log(`_mempoolFromElectrumx(): ${JSON.stringify(electrumResponse, null, 2)}`)
|
||||
//
|
||||
// // Pass the error message if ElectrumX reports an error.
|
||||
// if (Object.prototype.hasOwnProperty.call(electrumResponse, 'code')) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// message: electrumResponse.message
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// res.status(200)
|
||||
// return res.json({
|
||||
// success: true,
|
||||
// utxos: electrumResponse
|
||||
// })
|
||||
// } catch (err) {
|
||||
// // Write out error to error log.
|
||||
// wlogger.error('Error in elecrumx.js/getMempool().', err)
|
||||
//
|
||||
// return _this.errorHandler(err, res)
|
||||
// }
|
||||
// }
|
||||
async getMempool (req, res, next) {
|
||||
try {
|
||||
const address = req.params.address
|
||||
|
||||
// Reject if address is an array.
|
||||
if (Array.isArray(address)) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'address can not be an array. Use POST for bulk upload.'
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure the address is in cash address format.
|
||||
const cashAddr = _this.bchjs.Address.toCashAddress(address)
|
||||
|
||||
// Prevent a common user error. Ensure they are using the correct network address.
|
||||
const networkIsValid = _this.routeUtils.validateNetwork(cashAddr)
|
||||
if (!networkIsValid) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error:
|
||||
'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
|
||||
})
|
||||
}
|
||||
|
||||
wlogger.debug(
|
||||
'Executing electrumx/getMempool with this address: ',
|
||||
cashAddr
|
||||
)
|
||||
|
||||
// Get data from ElectrumX server.
|
||||
const response = await _this.axios.get(
|
||||
`${_this.fulcrumApi}electrumx/unconfirmed/${address}`
|
||||
)
|
||||
// console.log('response', response, _this.fulcrumApi)
|
||||
|
||||
res.status(200)
|
||||
return res.json(response.data)
|
||||
} catch (err) {
|
||||
// Write out error to error log.
|
||||
wlogger.error('Error in elecrumx.js/getMempool().', err)
|
||||
|
||||
return _this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /electrumx/unconfirmed Get unconfirmed utxos for an array of addresses.
|
||||
@@ -1041,82 +1016,70 @@ class Electrum {
|
||||
*
|
||||
*/
|
||||
// POST handler for bulk queries on address details
|
||||
// async mempoolBulk (req, res, next) {
|
||||
// try {
|
||||
// let addresses = req.body.addresses
|
||||
//
|
||||
// // Reject if addresses is not an array.
|
||||
// if (!Array.isArray(addresses)) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// error: 'addresses needs to be an array. Use GET for single address.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // Enforce array size rate limits
|
||||
// if (!_this.routeUtils.validateArraySize(req, addresses)) {
|
||||
// res.status(400) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
||||
// return res.json({
|
||||
// error: 'Array too large.'
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// wlogger.debug(
|
||||
// 'Executing electrumx.js/mempoolBulk with these addresses: ',
|
||||
// addresses
|
||||
// )
|
||||
//
|
||||
// // Validate each element in the address array.
|
||||
// for (let i = 0; i < addresses.length; i++) {
|
||||
// const thisAddress = addresses[i]
|
||||
//
|
||||
// // Ensure the input is a valid BCH address.
|
||||
// try {
|
||||
// _this.bchjs.Address.toLegacyAddress(thisAddress)
|
||||
// } catch (err) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// error: `Invalid BCH address. Double check your address is valid: ${thisAddress}`
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // Prevent a common user error. Ensure they are using the correct network address.
|
||||
// const networkIsValid = _this.routeUtils.validateNetwork(thisAddress)
|
||||
// if (!networkIsValid) {
|
||||
// res.status(400)
|
||||
// return res.json({
|
||||
// error: `Invalid network for address ${thisAddress}. Trying to use a testnet address on mainnet, or vice versa.`
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Loops through each address and creates an array of Promises, querying
|
||||
// // Insight API in parallel.
|
||||
// addresses = addresses.map(async (address, index) => {
|
||||
// // console.log(`address: ${address}`)
|
||||
// const utxos = await _this._mempoolFromElectrumx(address)
|
||||
//
|
||||
// return {
|
||||
// utxos,
|
||||
// address
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// // Wait for all parallel Insight requests to return.
|
||||
// const result = await Promise.all(addresses)
|
||||
//
|
||||
// // Return the array of retrieved address information.
|
||||
// res.status(200)
|
||||
// return res.json({
|
||||
// success: true,
|
||||
// utxos: result
|
||||
// })
|
||||
// } catch (err) {
|
||||
// wlogger.error('Error in electrumx.js/mempoolBulk().', err)
|
||||
//
|
||||
// return _this.errorHandler(err, res)
|
||||
// }
|
||||
// }
|
||||
async mempoolBulk (req, res, next) {
|
||||
try {
|
||||
const addresses = req.body.addresses
|
||||
|
||||
// Reject if addresses is not an array.
|
||||
if (!Array.isArray(addresses)) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'addresses needs to be an array. Use GET for single address.'
|
||||
})
|
||||
}
|
||||
|
||||
// Enforce array size rate limits
|
||||
if (!_this.routeUtils.validateArraySize(req, addresses)) {
|
||||
res.status(400) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'Array too large.'
|
||||
})
|
||||
}
|
||||
|
||||
wlogger.debug(
|
||||
'Executing electrumx.js/mempoolBulk with these addresses: ',
|
||||
addresses
|
||||
)
|
||||
|
||||
// Validate each element in the address array.
|
||||
for (let i = 0; i < addresses.length; i++) {
|
||||
const thisAddress = addresses[i]
|
||||
|
||||
// Ensure the input is a valid BCH address.
|
||||
try {
|
||||
_this.bchjs.Address.toLegacyAddress(thisAddress)
|
||||
} catch (err) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `Invalid BCH address. Double check your address is valid: ${thisAddress}`
|
||||
})
|
||||
}
|
||||
|
||||
// Prevent a common user error. Ensure they are using the correct network address.
|
||||
const networkIsValid = _this.routeUtils.validateNetwork(thisAddress)
|
||||
if (!networkIsValid) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `Invalid network for address ${thisAddress}. Trying to use a testnet address on mainnet, or vice versa.`
|
||||
})
|
||||
}
|
||||
}
|
||||
const response = await _this.axios.post(
|
||||
`${_this.fulcrumApi}electrumx/unconfirmed/`,
|
||||
{ addresses }
|
||||
)
|
||||
res.status(200)
|
||||
return res.json(response.data)
|
||||
} catch (err) {
|
||||
wlogger.error('Error in electrumx.js/mempoolBulk().', err)
|
||||
|
||||
return _this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
|
||||
// DRY error handler.
|
||||
errorHandler (err, res) {
|
||||
|
||||
@@ -18,7 +18,7 @@ const routeUtils = new RouteUtils()
|
||||
const BCHJS = require('@psf/bch-js')
|
||||
const restURL = process.env.LOCAL_RESTURL
|
||||
? process.env.LOCAL_RESTURL
|
||||
: 'https://api.fullstack.cash/v4/'
|
||||
: 'https://api.fullstack.cash/v5/'
|
||||
const bchjs = new BCHJS({ restURL })
|
||||
|
||||
let _this
|
||||
@@ -76,7 +76,7 @@ class Encryption {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/encryption/publickey/bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/encryption/publickey/bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getPublicKey (req, res, next) {
|
||||
|
||||
@@ -81,7 +81,7 @@ class Blockchain {
|
||||
* block chain.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getBestBlockHash" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getBestBlockHash" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {String} bestBlockHash 000000000000000002bc884334336d99c9a9c616670a9244c6a8c1fc35aa91a1
|
||||
*/
|
||||
@@ -112,7 +112,7 @@ class Blockchain {
|
||||
* @apiDescription Returns an object containing various state info regarding blockchain processing.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getBlockchainInfo" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getBlockchainInfo" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {Object} object Object containing data
|
||||
* @apiSuccess {String} object.chain "main"
|
||||
@@ -156,7 +156,7 @@ class Blockchain {
|
||||
* @apiDescription Returns the number of blocks in the longest blockchain.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getBlockCount" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getBlockCount" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {Number} bestBlockCount 587665
|
||||
*/
|
||||
@@ -189,7 +189,7 @@ class Blockchain {
|
||||
* returns an Object with information about blockheader hash.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getBlockHeader/000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201?verbose=true" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getBlockHeader/000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201?verbose=true" -H "accept: application/json"
|
||||
*
|
||||
* @apiParam {String} hash block hash
|
||||
* @apiParam {Boolean} verbose Return verbose data
|
||||
@@ -250,7 +250,7 @@ class Blockchain {
|
||||
* returns an Object with information about blockheader hash.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/blockchain/getBlockHeader" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\",\"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3\"],\"verbose\":true}"
|
||||
* curl -X POST "https://api.fullstack.cash/v5/blockchain/getBlockHeader" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\",\"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3\"],\"verbose\":true}"
|
||||
*
|
||||
* @apiParam {String} hash block hash
|
||||
* @apiParam {Boolean} verbose Return verbose data
|
||||
@@ -342,7 +342,7 @@ class Blockchain {
|
||||
* including the main chain as well as orphaned branches.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getChainTips" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getChainTips" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getChainTips (req, res, next) {
|
||||
@@ -373,7 +373,7 @@ class Blockchain {
|
||||
* power on the network.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getDifficulty" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getDifficulty" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getDifficulty (req, res, next) {
|
||||
@@ -405,7 +405,7 @@ class Blockchain {
|
||||
* mempool (unconfirmed)
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getMempoolEntry/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getMempoolEntry/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getMempoolEntrySingle (req, res, next) {
|
||||
@@ -443,7 +443,7 @@ class Blockchain {
|
||||
* @apiDescription Returns mempool data for multiple transactions
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST https://api.fullstack.cash/v4/blockchain/getMempoolEntry -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}"
|
||||
* curl -X POST https://api.fullstack.cash/v5/blockchain/getMempoolEntry -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}"
|
||||
*/
|
||||
async getMempoolEntryBulk (req, res, next) {
|
||||
try {
|
||||
@@ -516,7 +516,7 @@ class Blockchain {
|
||||
* against the 25 ancestor chain-limit.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getMempoolAncestors/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getMempoolAncestors/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getMempoolAncestorsSingle (req, res, next) {
|
||||
@@ -558,7 +558,7 @@ class Blockchain {
|
||||
* @apiDescription Returns details on the active state of the TX memory pool.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET https://api.fullstack.cash/v4/getMempoolInfo -H "accept: application/json"
|
||||
* curl -X GET https://api.fullstack.cash/v5/getMempoolInfo -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getMempoolInfo (req, res, next) {
|
||||
@@ -588,7 +588,7 @@ class Blockchain {
|
||||
* @apiDescription Returns details on the active state of the TX memory pool.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET https://api.fullstack.cash/v4/getMempoolInfo -H "accept: application/json"
|
||||
* curl -X GET https://api.fullstack.cash/v5/getMempoolInfo -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -600,7 +600,7 @@ class Blockchain {
|
||||
* of string transaction ids.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/getRawMempool/?verbose=true" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/getRawMempool/?verbose=true" -H "accept: application/json"
|
||||
*
|
||||
* @apiParam {Boolean} verbose Return verbose data
|
||||
*
|
||||
@@ -636,7 +636,7 @@ class Blockchain {
|
||||
* @apiDescription Returns details about an unspent transaction output.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getTxOut/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33/0?mempool=false" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getTxOut/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33/0?mempool=false" -H "accept: application/json"
|
||||
*
|
||||
* @apiParam {String} txid Transaction id (required)
|
||||
* @apiParam {Number} n Output number (required)
|
||||
@@ -693,7 +693,7 @@ class Blockchain {
|
||||
* @apiDescription Returns details about an unspent transaction output (UTXO).
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl "https://api.fullstack.cash/v4/blockchain/getTxOut/" -X POST -H "Content-Type: application/json" --data-binary '{"txid":"d5228d2cdc77fbe5a9aa79f19b0933b6802f9f0067f42847fc4fe343664723e5","vout":0,"mempool":true}'
|
||||
* curl "https://api.fullstack.cash/v5/blockchain/getTxOut/" -X POST -H "Content-Type: application/json" --data-binary '{"txid":"d5228d2cdc77fbe5a9aa79f19b0933b6802f9f0067f42847fc4fe343664723e5","vout":0,"mempool":true}'
|
||||
*
|
||||
* @apiParam {String} txid Transaction id (required)
|
||||
* @apiParam {Number} vout of transaction (required)
|
||||
@@ -747,7 +747,7 @@ class Blockchain {
|
||||
* @apiDescription Returns a hex-encoded proof that 'txid' was included in a block.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/blockchain/getTxOutProofSingle/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getTxOutProofSingle/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json"
|
||||
*
|
||||
* @apiParam {String} txid Transaction id (required)
|
||||
*
|
||||
@@ -946,7 +946,7 @@ class Blockchain {
|
||||
* @apiDescription Returns block details
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl "https://api.fullstack.cash/v4/blockchain/getblock/" -X POST -H "Content-Type: application/json" --data-binary '{"blockhash":"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b","verbosity":0 }'
|
||||
* curl "https://api.fullstack.cash/v5/blockchain/getblock/" -X POST -H "Content-Type: application/json" --data-binary '{"blockhash":"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b","verbosity":0 }'
|
||||
*
|
||||
* @apiParam {String} blockhash Block hash (required)
|
||||
* @apiParam {Number} verbosity Default 1 (optional)
|
||||
|
||||
@@ -53,7 +53,7 @@ class Control {
|
||||
* @apiDescription RPC call which gets basic full node information.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/control/getnetworkinfo" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/control/getnetworkinfo" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getNetworkInfo (req, res, next) {
|
||||
@@ -75,42 +75,6 @@ class Control {
|
||||
return _this.errorHandler(error, res)
|
||||
}
|
||||
}
|
||||
// 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 = Control
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
'use strict'
|
||||
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
|
||||
const axios = require('axios')
|
||||
const wlogger = require('../../../util/winston-logging')
|
||||
|
||||
const RouteUtils = require('../../../util/route-utils')
|
||||
const routeUtils = new RouteUtils()
|
||||
|
||||
// Used to convert error messages to strings, to safely pass to users.
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
let _this
|
||||
class DSProof {
|
||||
constructor () {
|
||||
_this = this
|
||||
_this.axios = axios
|
||||
_this.routeUtils = routeUtils
|
||||
|
||||
_this.router = router
|
||||
_this.router.get('/', this.root)
|
||||
_this.router.get('/getdsproof/:txid', _this.getDSProof)
|
||||
}
|
||||
|
||||
// DRY error handler.
|
||||
errorHandler (err, res) {
|
||||
// Attempt to decode the error message.
|
||||
const { msg, status } = _this.routeUtils.decodeError(err)
|
||||
if (msg) {
|
||||
res.status(status)
|
||||
return res.json({ error: msg })
|
||||
}
|
||||
|
||||
res.status(500)
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
|
||||
root (req, res, next) {
|
||||
return res.json({ status: 'dsproof' })
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /dsproof/getdsproof/:txid Get Double-Spend Proof.
|
||||
* @apiName DS Proof.
|
||||
* @apiGroup DSProof
|
||||
* @apiDescription Get information for a double-spend proof.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v5/dsproof/getdsproof/a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
async getDSProof (req, res, next) {
|
||||
try {
|
||||
const txid = req.params.txid
|
||||
|
||||
let verbose = 2 // default
|
||||
if (req.query.verbose === 'true') verbose = 3
|
||||
|
||||
if (!txid || txid === '') {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: 'txid can not be empty'
|
||||
})
|
||||
}
|
||||
|
||||
if (txid.length !== 64) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `txid must be of length 64 (not ${txid.length})`
|
||||
})
|
||||
}
|
||||
|
||||
const options = _this.routeUtils.getAxiosOptions()
|
||||
options.data.id = 'getdsproof'
|
||||
options.data.method = 'getdsproof'
|
||||
options.data.params = [txid, verbose]
|
||||
|
||||
const response = await _this.axios.request(options)
|
||||
return res.json(response.data.result)
|
||||
} catch (err) {
|
||||
wlogger.error('Error in dsproof.js/getDSProof().', err)
|
||||
|
||||
return _this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DSProof
|
||||
@@ -77,7 +77,7 @@ class Mining {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/mining/getMiningInfo" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/mining/getMiningInfo" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ class Mining {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/mining/getNetworkHashps?nblocks=120&height=-1" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/mining/getNetworkHashps?nblocks=120&height=-1" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -65,7 +65,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/rawtransactions/decodeRawTransaction/02000000010e991f7ccec410f27d333f737f149b5d3be6728687da81072e638aed0063a176010000006b483045022100cd20443b0af090053450bc4ab00d563d4ac5955bb36e0135b00b8a96a19f233302205047f2c70a08c6ef4b76f2d198b33a31d17edfaa7e1e9e865894da0d396009354121024d4e7f522f67105b7bf5f9dbe557e7b2244613fdfcd6fe09304f93877328f6beffffffff02a0860100000000001976a9140ee020c07f39526ac5505c54fa1ab98490979b8388acb5f0f70b000000001976a9143a9b2b0c12fe722fcf653b6ef5dcc38732d6ff5188ac00000000" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/rawtransactions/decodeRawTransaction/02000000010e991f7ccec410f27d333f737f149b5d3be6728687da81072e638aed0063a176010000006b483045022100cd20443b0af090053450bc4ab00d563d4ac5955bb36e0135b00b8a96a19f233302205047f2c70a08c6ef4b76f2d198b33a31d17edfaa7e1e9e865894da0d396009354121024d4e7f522f67105b7bf5f9dbe557e7b2244613fdfcd6fe09304f93877328f6beffffffff02a0860100000000001976a9140ee020c07f39526ac5505c54fa1ab98490979b8388acb5f0f70b000000001976a9143a9b2b0c12fe722fcf653b6ef5dcc38732d6ff5188ac00000000" -H "accept: application/json"
|
||||
*/
|
||||
async decodeRawTransactionSingle (req, res, next) {
|
||||
try {
|
||||
@@ -103,7 +103,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/rawtransactions/decodeRawTransaction" -H "accept: application/json" -H "Content-Type: application/json" -d '{"hexes":["01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000","01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/rawtransactions/decodeRawTransaction" -H "accept: application/json" -H "Content-Type: application/json" -d '{"hexes":["01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000","01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -177,7 +177,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/rawtransactions/decodeScript/4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/rawtransactions/decodeScript/4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -218,7 +218,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
*curl -X POST "https://api.fullstack.cash/v4/rawtransactions/decodeScript" -H "accept:" -H "Content-Type: application/json" -d '{"hexes":["01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000","01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"]}'
|
||||
*curl -X POST "https://api.fullstack.cash/v5/rawtransactions/decodeScript" -H "accept:" -H "Content-Type: application/json" -d '{"hexes":["01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000","01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -308,7 +308,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/rawtransactions/getRawTransaction" -H "accept: application/json" -H "Content-Type: application/json" -d '{"txids":["a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1","5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e"],"verbose":true}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/rawtransactions/getRawTransaction" -H "accept: application/json" -H "Content-Type: application/json" -d '{"txids":["a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1","5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e"],"verbose":true}'
|
||||
*
|
||||
*/
|
||||
async getRawTransactionBulk (req, res, next) {
|
||||
@@ -375,7 +375,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/rawtransactions/getRawTransaction/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33?verbose=true" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/rawtransactions/getRawTransaction/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33?verbose=true" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -421,7 +421,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/rawtransactions/sendRawTransaction" -H "accept:application/json" -H "Content-Type: application/json" -d '{"hexes":["01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000","01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/rawtransactions/sendRawTransaction" -H "accept:application/json" -H "Content-Type: application/json" -d '{"hexes":["01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000","01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -515,7 +515,7 @@ class RawTransactions {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/rawtransactions/sendRawTransaction/01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" -H "accept: "
|
||||
* curl -X GET "https://api.fullstack.cash/v5/rawtransactions/sendRawTransaction/01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" -H "accept: "
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Utility functions for troubleshooting a JWT token.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
// Public npm libraries.
|
||||
const jwt = require('jsonwebtoken')
|
||||
const axios = require('axios')
|
||||
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
|
||||
const config = require('../../../config')
|
||||
const wlogger = require('../../util/winston-logging')
|
||||
|
||||
const RouteUtils = require('../../util/route-utils')
|
||||
const routeUtils = new RouteUtils()
|
||||
|
||||
// Used for processing error messages before sending them to the user.
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
let _this
|
||||
|
||||
class JWT {
|
||||
constructor () {
|
||||
_this = this
|
||||
|
||||
_this.axios = axios
|
||||
_this.routeUtils = routeUtils
|
||||
_this.jwt = jwt
|
||||
_this.config = config
|
||||
|
||||
_this.router = router
|
||||
_this.router.get('/', _this.root)
|
||||
_this.router.post('/info', _this.jwtInfo)
|
||||
}
|
||||
|
||||
root (req, res, next) {
|
||||
return res.json({ status: 'jwt' })
|
||||
}
|
||||
|
||||
// DRY error handler.
|
||||
errorHandler (err, res) {
|
||||
// Attempt to decode the error message.
|
||||
const { msg, status } = _this.routeUtils.decodeError(err)
|
||||
if (msg) {
|
||||
res.status(status)
|
||||
return res.json({ error: msg })
|
||||
}
|
||||
|
||||
res.status(500)
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /jwt/info Get JWT Info
|
||||
* @apiName GetJWTInfo
|
||||
* @apiGroup JWT
|
||||
* @apiDescription
|
||||
* Get info on your JWT token. Useful for debugging rate limit issues with your
|
||||
* JWT token.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v5/jwt/info" -H "accept: application/json" -H "Content-Type: application/json" -d '{"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwZGRmZmI2NzRhM2Q2MDAxOTY3NjE1NCIsImVtYWlsIjoiY2hyaXNAYmNodGVzdC5uZXQiLCJhcGlMZXZlbCI6NjAsInJhdGVMaW1pdCI6MywicG9pbnRzVG9Db25zdW1lIjoxNiwiZHVyYXRpb24iOjMwLCJpYXQiOjE2MjU0MzQ2MzYsImv5cCI6MTYyODAyNjYzNn0.1WLugTkQKVG0yMXD1h5nxfho3gRzvSvs8NMa9obVhPM"}'
|
||||
*
|
||||
*/
|
||||
async jwtInfo (req, res, next) {
|
||||
try {
|
||||
const jwtIn = req.body.jwt
|
||||
// console.log('jwt: ', jwtIn)
|
||||
// console.log('_this.config.apiTokenSecret: ', _this.config.apiTokenSecret)
|
||||
|
||||
const decoded = _this.jwt.verify(jwtIn, _this.config.apiTokenSecret)
|
||||
// console.log('decoded: ', decoded)
|
||||
|
||||
const expiration = new Date(decoded.exp * 1000)
|
||||
decoded.expiration = expiration.toISOString()
|
||||
|
||||
const createdAt = new Date(decoded.iat * 1000)
|
||||
decoded.createdAt = createdAt.toISOString()
|
||||
|
||||
res.status(200)
|
||||
return res.json(decoded)
|
||||
} catch (error) {
|
||||
// console.log('Error in jwt.js/jwtInfo().', error)
|
||||
wlogger.error('Error in jwt.js/jwtInfo().', error)
|
||||
|
||||
return _this.errorHandler(error, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JWT
|
||||
@@ -25,7 +25,7 @@ class Price {
|
||||
|
||||
this.priceUrl = 'https://api.coinbase.com/v2/exchange-rates?currency=BCH'
|
||||
this.coinexPriceUrl =
|
||||
'https://api.coinex.com/v1/market/ticker?market=bchausdt'
|
||||
'https://api.coinex.com/v1/market/ticker?market=xecusdt'
|
||||
|
||||
this.bchCoinexPriceUrl =
|
||||
'https://api.coinex.com/v1/market/ticker?market=bchusdt'
|
||||
@@ -64,7 +64,7 @@ class Price {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/price/usd" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/price/usd" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getUSD (req, res, next) {
|
||||
@@ -96,7 +96,7 @@ class Price {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/price/rates" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/price/rates" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
// Get rates for several different currencies
|
||||
@@ -129,7 +129,7 @@ class Price {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/price/bchausd" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/price/bchausd" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getBCHAUSD (req, res, next) {
|
||||
@@ -163,7 +163,7 @@ class Price {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/price/bchusd" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/price/bchusd" -H "accept: application/json"
|
||||
*
|
||||
*/
|
||||
async getBCHUSD (req, res, next) {
|
||||
|
||||
+25
-25
@@ -16,7 +16,7 @@ const wlogger = require('../../util/winston-logging')
|
||||
// Instantiate a local copy of bch-js using the local REST API server.
|
||||
const LOCAL_RESTURL = process.env.LOCAL_RESTURL
|
||||
? process.env.LOCAL_RESTURL
|
||||
: 'https://api.fullstack.cash/v4/'
|
||||
: 'https://api.fullstack.cash/v5/'
|
||||
|
||||
const BCHJS = require('@psf/bch-js')
|
||||
// const BCHJS = require('../../../../bch-js')
|
||||
@@ -51,10 +51,10 @@ const rawTransactions = new RawTransactions()
|
||||
// Setup REST and TREST URLs used by slpjs
|
||||
// Dev note: this allows for unit tests to mock the URL.
|
||||
if (!process.env.REST_URL) {
|
||||
process.env.REST_URL = 'https://bchn.fullstack.cash/v4/'
|
||||
process.env.REST_URL = 'https://bchn.fullstack.cash/v5/'
|
||||
}
|
||||
if (!process.env.TREST_URL) {
|
||||
process.env.TREST_URL = 'https://testnet.fullstack.cash/v4/'
|
||||
process.env.TREST_URL = 'https://testnet.fullstack.cash/v5/'
|
||||
}
|
||||
|
||||
let _this
|
||||
@@ -181,7 +181,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/list/259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/list/259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -214,7 +214,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/list" -H "accept:application/json" -H "Content-Type: application/json" -d '{"tokenIds":["7380843cd1089a1a01783f86af37734dc99667a1cdc577391b5f6ea42fc1bfb4","9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/list" -H "accept:application/json" -H "Content-Type: application/json" -d '{"tokenIds":["7380843cd1089a1a01783f86af37734dc99667a1cdc577391b5f6ea42fc1bfb4","9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -362,7 +362,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/balancesForAddress/simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/balancesForAddress/simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -546,7 +546,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/balancesForAddress" -d "{\"addresses\":[\"simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57\"]}" -H "accept:application/json"
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/balancesForAddress" -d "{\"addresses\":[\"simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57\"]}" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -761,7 +761,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/balancesForToken/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/balancesForToken/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -868,7 +868,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/convert/simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/convert/simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -914,7 +914,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/convert" -H "accept:application/json" -H "Content-Type: application/json" -d '{"addresses":["simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/convert" -H "accept:application/json" -H "Content-Type: application/json" -d '{"addresses":["simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -976,7 +976,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/validateTxid" -H "accept:application/json" -H "Content-Type: application/json" -d '{"txids":["f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a","fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/validateTxid" -H "accept:application/json" -H "Content-Type: application/json" -d '{"txids":["f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a","fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1122,7 +1122,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/validateTxid/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/validateTxid/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1203,7 +1203,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/validateTxid2/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/validateTxid2/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1268,7 +1268,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/whitelist" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/whitelist" -H "accept:application/json"
|
||||
*
|
||||
*/
|
||||
async getSlpWhitelist (req, res, next) {
|
||||
@@ -1321,7 +1321,7 @@ class Slp {
|
||||
* /slp/whitelist endpoint.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/validateTxid3/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/validateTxid3/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1403,7 +1403,7 @@ class Slp {
|
||||
* /slp/whitelist endpoint.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/validateTxid3" -H "accept:application/json" -H "Content-Type: application/json" -d '{"txids":["f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a","fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/validateTxid3" -H "accept:application/json" -H "Content-Type: application/json" -d '{"txids":["f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a","fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952"]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1554,7 +1554,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/txDetails/8ab4ac5dea3f9024e3954ee5b61452955d659a34561f79ef62ac44e133d0980e" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/txDetails/8ab4ac5dea3f9024e3954ee5b61452955d659a34561f79ef62ac44e133d0980e" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1646,7 +1646,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/tokenStats/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/tokenStats/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1677,7 +1677,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/transactions/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0/simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/transactions/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0/simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l" -H "accept:application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1901,7 +1901,7 @@ class Slp {
|
||||
* (1 or 2) will also be returned.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/generateSendOpReturn" -H "accept:application/json" -H "Content-Type: application/json" -d '{"tokenUtxos":[{"tokenId": "0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1","decimals": 0, "tokenQty": 2}], "sendQty": 1.5}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/generateSendOpReturn" -H "accept:application/json" -H "Content-Type: application/json" -d '{"tokenUtxos":[{"tokenId": "0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1","decimals": 0, "tokenQty": 2}], "sendQty": 1.5}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -1986,7 +1986,7 @@ class Slp {
|
||||
* not been confirmed.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/hydrateUtxos" -H "accept:application/json" -H "Content-Type: application/json" -d '{"utxos":[{"utxos":[{"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 3, "value": "6816", "height": 606848, "confirmations": 13, "satoshis": 6816}, {"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 2, "value": "546", "height": 606848, "confirmations": 13, "satoshis": 546}]}]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/hydrateUtxos" -H "accept:application/json" -H "Content-Type: application/json" -d '{"utxos":[{"utxos":[{"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 3, "value": "6816", "height": 606848, "confirmations": 13, "satoshis": 6816}, {"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 2, "value": "546", "height": 606848, "confirmations": 13, "satoshis": 546}]}]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -2095,7 +2095,7 @@ class Slp {
|
||||
* SLP tokens.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/slp/hydrateUtxosWL" -H "accept:application/json" -H "Content-Type: application/json" -d '{"utxos":[{"utxos":[{"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 3, "value": "6816", "height": 606848, "confirmations": 13, "satoshis": 6816}, {"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 2, "value": "546", "height": 606848, "confirmations": 13, "satoshis": 546}]}]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/slp/hydrateUtxosWL" -H "accept:application/json" -H "Content-Type: application/json" -d '{"utxos":[{"utxos":[{"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 3, "value": "6816", "height": 606848, "confirmations": 13, "satoshis": 6816}, {"txid": "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56","vout": 2, "value": "546", "height": 606848, "confirmations": 13, "satoshis": 546}]}]}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -2196,7 +2196,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/status" -H "accept:application/json" -H "Content-Type: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/status" -H "accept:application/json" -H "Content-Type: application/json"
|
||||
*
|
||||
*/
|
||||
async getStatus (req, res, next) {
|
||||
@@ -2239,7 +2239,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/nftChildren/68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/nftChildren/68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a" -H "accept:application/json"
|
||||
*
|
||||
*/
|
||||
async getNftChildren (req, res, next) {
|
||||
@@ -2315,7 +2315,7 @@ class Slp {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/slp/nftGroup/45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9" -H "accept:application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/slp/nftGroup/45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9" -H "accept:application/json"
|
||||
*
|
||||
*/
|
||||
async getNftGroup (req, res, next) {
|
||||
|
||||
@@ -14,7 +14,7 @@ util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const BCHJS = require('@psf/bch-js')
|
||||
const bchjs = new BCHJS()
|
||||
// const BCHJS_TESTNET = 'https://testnet.bchjs.cash/v4/'
|
||||
// const BCHJS_TESTNET = 'https://testnet.bchjs.cash/v5/'
|
||||
|
||||
// const bchjsHTTP = axios.create({
|
||||
// baseURL: process.env.RPC_BASEURL
|
||||
@@ -75,7 +75,7 @@ class UtilRoute {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://api.fullstack.cash/v4/util/validateAddress/bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c" -H "accept: application/json"
|
||||
* curl -X GET "https://api.fullstack.cash/v5/util/validateAddress/bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -124,8 +124,8 @@ class UtilRoute {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/util/validateAddress" -H "accept: application/json" -H "Content-Type: application/json" -d '{"addresses":["bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c","bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v4/util/validateAddress" -H "accept: application/json" -H "Content-Type: application/json" -d '{"addresses":["bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c","bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0"],"from": 1, "to": 5}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/util/validateAddress" -H "accept: application/json" -H "Content-Type: application/json" -d '{"addresses":["bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c","bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0"]}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/util/validateAddress" -H "accept: application/json" -H "Content-Type: application/json" -d '{"addresses":["bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c","bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0"],"from": 1, "to": 5}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -227,8 +227,8 @@ class UtilRoute {
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://api.fullstack.cash/v4/util/sweep" -H "accept: application/json" -H "Content-Type: application/json" -d '{"wif":"Kz52sdXLAiKtH82iAFRi6aTZanWtW5Eyv37KWdpY6tTv7pjoHste", "balanceOnly": true}'
|
||||
* curl -X POST "https://api.fullstack.cash/v4/util/sweep" -H "accept: application/json" -H "Content-Type: application/json" -d '{"wif":"Kz52sdXLAiKtH82iAFRi6aTZanWtW5Eyv37KWdpY6tTv7pjoHste", "toAddr": "bitcoincash:qpt8m4kqu963geedyrur6pdggqmv5kxwnq0rn322qu"}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/util/sweep" -H "accept: application/json" -H "Content-Type: application/json" -d '{"wif":"Kz52sdXLAiKtH82iAFRi6aTZanWtW5Eyv37KWdpY6tTv7pjoHste", "balanceOnly": true}'
|
||||
* curl -X POST "https://api.fullstack.cash/v5/util/sweep" -H "accept: application/json" -H "Content-Type: application/json" -d '{"wif":"Kz52sdXLAiKtH82iAFRi6aTZanWtW5Eyv37KWdpY6tTv7pjoHste", "toAddr": "bitcoincash:qpt8m4kqu963geedyrur6pdggqmv5kxwnq0rn322qu"}'
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1102,6 +1102,491 @@ describe('#Electrumx', () => {
|
||||
assert.property(result.headers[0], 'headers')
|
||||
})
|
||||
})
|
||||
describe('#getTransactions', () => {
|
||||
it('should throw 400 if address is empty', async () => {
|
||||
const result = await electrumxRoute.getTransactions(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 422, 'Expect 422 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Unsupported address format')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw 400 on array input', async () => {
|
||||
req.params.address = ['qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']
|
||||
|
||||
const result = await electrumxRoute.getTransactions(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'address can not be an array')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw an error for an invalid address', async () => {
|
||||
req.params.address = '02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
|
||||
|
||||
const result = await electrumxRoute.getTransactions(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 422, 'Expect 422 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Unsupported address format')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should detect a network mismatch', async () => {
|
||||
req.params.address = 'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
|
||||
|
||||
const result = await electrumxRoute.getTransactions(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid network', 'Proper error message')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should pass errors from electrum-cash to user', async () => {
|
||||
// Address has invalid checksum.
|
||||
req.params.address =
|
||||
'bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur2'
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.getTransactions(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Unsupported address format')
|
||||
})
|
||||
|
||||
it('should get transaction for a single address', async () => {
|
||||
req.params.address =
|
||||
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||
|
||||
// Mock unit tests to prevent live network calls.
|
||||
if (process.env.TEST === 'unit') {
|
||||
electrumxRoute.isReady = true // Force flag.
|
||||
|
||||
sandbox.stub(electrumxRoute.axios, 'get').resolves({
|
||||
data: { success: true, transactions: mockData.transactions }
|
||||
})
|
||||
}
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.getTransactions(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, true)
|
||||
|
||||
assert.property(result, 'transactions')
|
||||
assert.isArray(result.transactions)
|
||||
|
||||
assert.property(result.transactions[0], 'height')
|
||||
assert.property(result.transactions[0], 'tx_hash')
|
||||
})
|
||||
})
|
||||
describe('#transactionsBulk', () => {
|
||||
it('should throw 400 if addresses is empty', async () => {
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'addresses needs to be an array')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw 400 if input provided is not array', async () => {
|
||||
req.body.addresses = 'qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
|
||||
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'addresses needs to be an array')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw 400 error if addresses array is too large', async () => {
|
||||
const testArray = []
|
||||
for (var i = 0; i < 25; i++) testArray.push('')
|
||||
|
||||
req.body.addresses = testArray
|
||||
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Array too large')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw an error for an invalid address', async () => {
|
||||
req.body.addresses = ['02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']
|
||||
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid BCH address')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should detect a network mismatch', async () => {
|
||||
req.body.addresses = [
|
||||
'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
|
||||
]
|
||||
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid network', 'Proper error message')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should pass errors from electrum-cash to user', async () => {
|
||||
// Address has invalid checksum.
|
||||
req.body.addresses = [
|
||||
'bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur2'
|
||||
]
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid BCH address')
|
||||
})
|
||||
it('should handle error', async () => {
|
||||
req.body.addresses = [
|
||||
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7',
|
||||
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||
]
|
||||
// Force error
|
||||
sandbox.stub(electrumxRoute.axios, 'post').throws(new Error('Test error'))
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Test error')
|
||||
})
|
||||
it('should get transaction for an array of addresses', async () => {
|
||||
req.body.addresses = [
|
||||
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7',
|
||||
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||
]
|
||||
|
||||
// Mock unit tests to prevent live network calls.
|
||||
if (process.env.TEST === 'unit') {
|
||||
electrumxRoute.isReady = true // Force flag.
|
||||
|
||||
sandbox
|
||||
.stub(electrumxRoute.axios, 'post')
|
||||
.resolves({ data: mockData.transactionsBulk })
|
||||
}
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.transactionsBulk(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, true)
|
||||
|
||||
assert.property(result, 'transactions')
|
||||
assert.isArray(result.transactions)
|
||||
|
||||
assert.property(result.transactions[0], 'transactions')
|
||||
assert.isArray(result.transactions[0].transactions)
|
||||
|
||||
assert.property(result.transactions[0].transactions[0], 'height')
|
||||
assert.property(result.transactions[0].transactions[0], 'tx_hash')
|
||||
})
|
||||
})
|
||||
describe('#getMempool', () => {
|
||||
it('should throw 400 if address is empty', async () => {
|
||||
const result = await electrumxRoute.getMempool(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 422, 'Expect 422 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Unsupported address format')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw 400 on array input', async () => {
|
||||
req.params.address = ['qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']
|
||||
|
||||
const result = await electrumxRoute.getMempool(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'address can not be an array')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw an error for an invalid address', async () => {
|
||||
req.params.address = '02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
|
||||
|
||||
const result = await electrumxRoute.getMempool(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 422, 'Expect 422 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Unsupported address format')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should detect a network mismatch', async () => {
|
||||
req.params.address = 'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
|
||||
|
||||
const result = await electrumxRoute.getMempool(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid network', 'Proper error message')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should pass errors from electrum-cash to user', async () => {
|
||||
// Address has invalid checksum.
|
||||
req.params.address =
|
||||
'bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur2'
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.getMempool(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Unsupported address format')
|
||||
})
|
||||
|
||||
it('should get mempool for a single address', async () => {
|
||||
req.params.address =
|
||||
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||
|
||||
// Mock unit tests to prevent live network calls.
|
||||
if (process.env.TEST === 'unit') {
|
||||
electrumxRoute.isReady = true // Force flag.
|
||||
|
||||
sandbox
|
||||
.stub(electrumxRoute.axios, 'get')
|
||||
.resolves({ data: { success: true, utxos: mockData.utxos } })
|
||||
}
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.getMempool(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, true)
|
||||
|
||||
assert.property(result, 'utxos')
|
||||
assert.isArray(result.utxos)
|
||||
})
|
||||
})
|
||||
describe('#mempoolBulk', () => {
|
||||
it('should throw 400 if addresses is empty', async () => {
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'addresses needs to be an array')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw 400 if input provided is not array', async () => {
|
||||
req.body.addresses = 'qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
|
||||
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'addresses needs to be an array')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw 400 error if addresses array is too large', async () => {
|
||||
const testArray = []
|
||||
for (var i = 0; i < 25; i++) testArray.push('')
|
||||
|
||||
req.body.addresses = testArray
|
||||
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Array too large')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should throw an error for an invalid address', async () => {
|
||||
req.body.addresses = ['02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']
|
||||
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid BCH address')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should detect a network mismatch', async () => {
|
||||
req.body.addresses = [
|
||||
'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
|
||||
]
|
||||
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid network', 'Proper error message')
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
})
|
||||
|
||||
it('should pass errors from electrum-cash to user', async () => {
|
||||
// Address has invalid checksum.
|
||||
req.body.addresses = [
|
||||
'bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur2'
|
||||
]
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Invalid BCH address')
|
||||
})
|
||||
it('should handle error', async () => {
|
||||
req.body.addresses = [
|
||||
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7',
|
||||
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||
]
|
||||
// Force error
|
||||
sandbox.stub(electrumxRoute.axios, 'post').throws(new Error('Test error'))
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, false)
|
||||
|
||||
assert.property(result, 'error')
|
||||
assert.include(result.error, 'Test error')
|
||||
})
|
||||
it('should get mempool for multiple addresses', async () => {
|
||||
req.body.addresses = [
|
||||
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7',
|
||||
'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||
]
|
||||
|
||||
// Mock unit tests to prevent live network calls.
|
||||
if (process.env.TEST === 'unit') {
|
||||
electrumxRoute.isReady = true // Force flag.
|
||||
|
||||
sandbox
|
||||
.stub(electrumxRoute.axios, 'post')
|
||||
.resolves({ data: mockData.utxosArray })
|
||||
}
|
||||
|
||||
// Call the details API.
|
||||
const result = await electrumxRoute.mempoolBulk(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, true)
|
||||
|
||||
assert.property(result, 'utxos')
|
||||
assert.property(result.utxos[0], 'utxos')
|
||||
assert.property(result.utxos[0], 'address')
|
||||
|
||||
assert.isArray(result.utxos[0].utxos)
|
||||
assert.isString(result.utxos[0].address)
|
||||
})
|
||||
})
|
||||
|
||||
// describe('#_utxosFromElectrumx', () => {
|
||||
// it('should throw error for invalid address', async () => {
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
TESTS FOR THE DSPROOF.JS LIBRARY
|
||||
|
||||
This test file uses the environment variable TEST to switch between unit
|
||||
and integration tests. By default, TEST is set to 'unit'. Set this variable
|
||||
to 'integration' to run the tests against BCH mainnet.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const assert = chai.assert
|
||||
const DSProofRoute = require('../../src/routes/v5/full-node/dsproof')
|
||||
const uut = new DSProofRoute()
|
||||
|
||||
// const nock = require('nock') // HTTP mocking
|
||||
const sinon = require('sinon')
|
||||
|
||||
let originalEnvVars // Used during transition from integration to unit tests.
|
||||
|
||||
// Mocking data.
|
||||
const { mockReq, mockRes } = require('./mocks/express-mocks')
|
||||
const mockData = require('./mocks/dsproof-mocks')
|
||||
|
||||
// Used for debugging.
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
describe('#DSProof', () => {
|
||||
let req, res
|
||||
let sandbox
|
||||
before(() => {
|
||||
// Save existing environment variables.
|
||||
originalEnvVars = {
|
||||
BITCOINCOM_BASEURL: process.env.BITCOINCOM_BASEURL,
|
||||
RPC_BASEURL: process.env.RPC_BASEURL,
|
||||
RPC_USERNAME: process.env.RPC_USERNAME,
|
||||
RPC_PASSWORD: process.env.RPC_PASSWORD
|
||||
}
|
||||
|
||||
// Set default environment variables for unit tests.
|
||||
if (!process.env.TEST) process.env.TEST = 'unit'
|
||||
if (process.env.TEST === 'unit') {
|
||||
process.env.BITCOINCOM_BASEURL = 'http://fakeurl/api/'
|
||||
process.env.RPC_BASEURL = 'http://fakeurl/api'
|
||||
process.env.RPC_USERNAME = 'fakeusername'
|
||||
process.env.RPC_PASSWORD = 'fakepassword'
|
||||
}
|
||||
})
|
||||
|
||||
// Setup the mocks before each test.
|
||||
beforeEach(() => {
|
||||
// Mock the req and res objects used by Express routes.
|
||||
req = mockReq
|
||||
res = mockRes
|
||||
|
||||
// Explicitly reset the parmas and body.
|
||||
req.params = {}
|
||||
req.body = {}
|
||||
req.query = {}
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
// Restore Sandbox
|
||||
sandbox.restore()
|
||||
})
|
||||
|
||||
after(() => {
|
||||
// Restore any pre-existing environment variables.
|
||||
process.env.BITCOINCOM_BASEURL = originalEnvVars.BITCOINCOM_BASEURL
|
||||
process.env.RPC_BASEURL = originalEnvVars.RPC_BASEURL
|
||||
process.env.RPC_USERNAME = originalEnvVars.RPC_USERNAME
|
||||
process.env.RPC_PASSWORD = originalEnvVars.RPC_PASSWORD
|
||||
})
|
||||
|
||||
describe('#root', async () => {
|
||||
// root route handler.
|
||||
it('should respond to GET for base route', async () => {
|
||||
const result = uut.root(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(result.status, 'dsproof', 'Returns static string')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getDSProof', async () => {
|
||||
it('should throw 400 error if txid is missing', async () => {
|
||||
const result = await uut.getDSProof(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.hasAllKeys(result, ['error', 'success'])
|
||||
assert.isFalse(result.success)
|
||||
assert.include(result.error, 'txid can not be empty')
|
||||
})
|
||||
it('should throw 400 error if txid is invalid', async () => {
|
||||
req.params.txid = 'abc123'
|
||||
|
||||
const result = await uut.getDSProof(req, res)
|
||||
|
||||
assert.hasAllKeys(result, ['error', 'success'])
|
||||
assert.isFalse(result.success)
|
||||
|
||||
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
|
||||
assert.include(result.error, 'txid must be of length 64')
|
||||
})
|
||||
it('should throw 503 when network issues', async () => {
|
||||
req.params.txid =
|
||||
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||
|
||||
// Save the existing RPC URL.
|
||||
const savedUrl2 = process.env.RPC_BASEURL
|
||||
|
||||
// Manipulate the URL to cause a 500 network error.
|
||||
process.env.RPC_BASEURL = 'http://fakeurl/api/'
|
||||
|
||||
await uut.getDSProof(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
// Restore the saved URL.
|
||||
process.env.RPC_BASEURL = savedUrl2
|
||||
|
||||
assert.isAbove(
|
||||
res.statusCode,
|
||||
499,
|
||||
'HTTP status code 500 or greater expected.'
|
||||
)
|
||||
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
||||
})
|
||||
it('returns proper error when downstream service stalls', async () => {
|
||||
req.params.txid =
|
||||
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||
// Mock the timeout error.
|
||||
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
|
||||
|
||||
const result = await uut.getDSProof(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.isAbove(res.statusCode, 499, 'HTTP status code 503 expected.')
|
||||
assert.include(
|
||||
result.error,
|
||||
'Could not communicate with full node',
|
||||
'Error message expected'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns proper error when downstream service is down', async () => {
|
||||
req.params.txid =
|
||||
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||
// Mock the timeout error.
|
||||
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' })
|
||||
|
||||
const result = await uut.getDSProof(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.isAbove(res.statusCode, 499, 'HTTP status code 503 expected.')
|
||||
assert.include(
|
||||
result.error,
|
||||
'Could not communicate with full node',
|
||||
'Error message expected'
|
||||
)
|
||||
})
|
||||
|
||||
it('should GET double-spend proof', async function () {
|
||||
req.params.txid =
|
||||
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
sandbox
|
||||
.stub(uut.axios, 'request')
|
||||
.resolves({ data: { result: mockData.mockGetDsProof } })
|
||||
} else {
|
||||
return this.skip()
|
||||
}
|
||||
|
||||
const result = await uut.getDSProof(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.property(result, 'dspid')
|
||||
assert.property(result, 'txid')
|
||||
assert.property(result, 'outpoint')
|
||||
assert.property(result, 'path')
|
||||
assert.property(result, 'descendants')
|
||||
|
||||
assert.property(result.outpoint, 'txid')
|
||||
assert.property(result.outpoint, 'vout')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
TESTS FOR THE JWT.JS LIBRARY
|
||||
|
||||
This test file uses the environment variable TEST to switch between unit
|
||||
and integration tests. By default, TEST is set to 'unit'. Set this variable
|
||||
to 'integration' to run the tests against BCH mainnet.
|
||||
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const assert = chai.assert
|
||||
const JWTRoute = require('../../src/routes/v5/jwt')
|
||||
const uut = new JWTRoute()
|
||||
const sinon = require('sinon')
|
||||
|
||||
// Mocking data.
|
||||
const { mockReq, mockRes } = require('./mocks/express-mocks')
|
||||
// const mockData = require('./mocks/control-mock')
|
||||
|
||||
// Used for debugging.
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
describe('#JWTRouter', () => {
|
||||
let req, res
|
||||
let sandbox
|
||||
|
||||
before(() => {
|
||||
// Set default environment variables for unit tests.
|
||||
})
|
||||
|
||||
// Setup the mocks before each test.
|
||||
beforeEach(() => {
|
||||
// Mock the req and res objects used by Express routes.
|
||||
req = mockReq
|
||||
res = mockRes
|
||||
|
||||
// Explicitly reset the parmas and body.
|
||||
req.params = {}
|
||||
req.body = {}
|
||||
req.query = {}
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
// Restore Sandbox
|
||||
sandbox.restore()
|
||||
})
|
||||
|
||||
after(() => {})
|
||||
|
||||
describe('#root', async () => {
|
||||
// root route handler.
|
||||
// const root = controlRoute.testableComponents.root
|
||||
|
||||
it('should respond to GET for base route', async () => {
|
||||
const result = uut.root(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.equal(result.status, 'jwt', 'Returns static string')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#jwtInfo', () => {
|
||||
it('should decode the JWT token', async () => {
|
||||
const jwtToken =
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwZWM3NTY1YTM4ZjkyMjdlOWVjNTM3MCIsImVtYWlsIjoidGVzdHVzZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjAsInJhdGVMaW1pdCI6MywicG9pbnRzVG9Db25zdW1lIjo1MDAsImR1cmF0aW9uIjozMCwiaWF0IjoxNjI2MTA5MzQ4LCJleHAiOjE2Mjg3MDEzNDh9.hF8BKU-1SvlvQBnTNbB65ErQTtNSl-pWlRANSJY-Zb4'
|
||||
req.body.jwt = jwtToken
|
||||
|
||||
const result = await uut.jwtInfo(req, res)
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.property(result, 'id')
|
||||
assert.property(result, 'email')
|
||||
assert.property(result, 'apiLevel')
|
||||
assert.property(result, 'rateLimit')
|
||||
assert.property(result, 'pointsToConsume')
|
||||
assert.property(result, 'duration')
|
||||
assert.property(result, 'iat')
|
||||
assert.property(result, 'exp')
|
||||
assert.property(result, 'expiration')
|
||||
assert.property(result, 'createdAt')
|
||||
})
|
||||
|
||||
it('should return an error with malformed JWT token', async () => {
|
||||
const jwtToken =
|
||||
'eyJhbGciOiJIUzI1NiLsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwZWM3NTY1YTM4ZjkyMjdlOWVjNTM3MCIsImVtYWlsIjoidGVzdHVzZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjAsInJhdGVMaW1pdCI6MywicG9pbnRzVG9Db25zdW1lIjo1MDAsImR1cmF0aW9uIjozMCwiaWF0IjoxNjI2MTA5MzQ4LCJleHAiOjE2Mjg3MDEzNDh9.hF8BKU-1SvlvQBnTNbB65ErQTtNSl-pWlRANSJY-Zb4'
|
||||
req.body.jwt = jwtToken
|
||||
|
||||
const result = await uut.jwtInfo(req, res)
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.equal(result.error, 'invalid token')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
This library contains mocking data for running unit tests on the dsproof route.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const mockGetDsProof = {
|
||||
dspid: '6234fff2a9dbcaa50e2c50d74e1d725a2bed1757d7a05a2db7a82df659554397',
|
||||
txid: 'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e',
|
||||
outpoint: {
|
||||
txid: '17ebef34f7e9a0692317dd6fbb43ffccff45b7d688a2a754dbccfc5e6d93ce3e',
|
||||
vout: 1
|
||||
},
|
||||
path: ['ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'],
|
||||
descendants: [
|
||||
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mockGetDsProof
|
||||
}
|
||||
@@ -180,6 +180,31 @@ const blockHeadersBulk = {
|
||||
success: true,
|
||||
headers: [{ headers: blockHeaders }, { headers: blockHeaders }]
|
||||
}
|
||||
|
||||
const transactions = [
|
||||
{
|
||||
height: 603416,
|
||||
tx_hash: 'eef683d236d88e978bd406419f144057af3fe1b62ef59162941c1a9f05ded62c'
|
||||
},
|
||||
{
|
||||
height: 646894,
|
||||
tx_hash: '4c695fae636f3e8e2edc571d11756b880ccaae744390f3950d798ce7b5e25754'
|
||||
}
|
||||
]
|
||||
|
||||
const transactionsBulk = {
|
||||
success: true,
|
||||
transactions: [
|
||||
{
|
||||
transactions,
|
||||
address: 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||
},
|
||||
{
|
||||
transactions,
|
||||
address: 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||
}
|
||||
]
|
||||
}
|
||||
module.exports = {
|
||||
utxos,
|
||||
utxosArray,
|
||||
@@ -190,5 +215,7 @@ module.exports = {
|
||||
txDetailsBulk,
|
||||
blockHeaders,
|
||||
blockHeadersBulk,
|
||||
balances
|
||||
balances,
|
||||
transactions,
|
||||
transactionsBulk
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user