mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ca014e160 | ||
|
|
233e210131 | ||
|
|
e55d421f13 | ||
|
|
1b1bf36a89 | ||
|
|
8de5399818 | ||
|
|
4f4984a982 | ||
|
|
d9fc84f136 | ||
|
|
d444666dec | ||
|
|
c8f3649004 | ||
|
|
ee876ce8e4 | ||
|
|
fbd02802f0 | ||
|
|
6e72879103 | ||
|
|
2817300ad6 | ||
|
|
4aa7cad552 | ||
|
|
5a9401aeb1 | ||
|
|
0ae02790a2 | ||
|
|
4d3adab9e0 | ||
|
|
91f06b6311 | ||
|
|
2fc175d818 | ||
|
|
731861cb1d | ||
|
|
9a01f5ffe6 | ||
|
|
c62c515474 | ||
|
|
ab198b958e | ||
|
|
2618008247 | ||
|
|
df27ba2063 | ||
|
|
f19e70ae40 | ||
|
|
63fa97c998 | ||
|
|
61b1b8ebdf | ||
|
|
de6c19e877 | ||
|
|
66efb76f94 | ||
|
|
1250a40ff0 | ||
|
|
6786ca9ee5 |
@@ -1,19 +1,48 @@
|
|||||||
FROM christroutner/ct-base-ubuntu
|
FROM ubuntu:20.04
|
||||||
MAINTAINER Chris Troutner <chris.troutner@gmail.com>
|
MAINTAINER Chris Troutner <chris.troutner@gmail.com>
|
||||||
|
|
||||||
RUN apt-get update -y
|
#Update the OS and install any OS packages needed.
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y sudo git curl nano gnupg wget
|
||||||
|
|
||||||
|
#Install Node and NPM
|
||||||
|
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
|
||||||
|
RUN bash nodesource_setup.sh
|
||||||
|
RUN apt-get install -y nodejs build-essential
|
||||||
|
|
||||||
|
#Create the user 'safeuser' and add them to the sudo group.
|
||||||
|
RUN useradd -ms /bin/bash safeuser
|
||||||
|
RUN adduser safeuser sudo
|
||||||
|
|
||||||
|
#Set password to 'abcd8765' change value below if you want a different password
|
||||||
|
RUN echo safeuser:abcd8765 | chpasswd
|
||||||
|
|
||||||
|
#Set the working directory to be the users home directory
|
||||||
|
WORKDIR /home/safeuser
|
||||||
|
|
||||||
|
#Setup NPM for non-root global install (like on a mac)
|
||||||
|
RUN mkdir /home/safeuser/.npm-global
|
||||||
|
RUN chown -R safeuser .npm-global
|
||||||
|
RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile
|
||||||
|
RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'"
|
||||||
|
|
||||||
|
# Update to the latest version of npm.
|
||||||
|
# Working with npm@7.21.1
|
||||||
|
RUN npm install -g npm
|
||||||
|
|
||||||
|
#FROM christroutner/ct-base-ubuntu
|
||||||
|
#MAINTAINER Chris Troutner <chris.troutner@gmail.com>
|
||||||
|
|
||||||
|
#RUN apt-get update -y
|
||||||
|
|
||||||
#Set the working directory to be the home directory
|
#Set the working directory to be the home directory
|
||||||
WORKDIR /home/safeuser
|
#WORKDIR /home/safeuser
|
||||||
|
|
||||||
# Switch to user account.
|
# Switch to user account.
|
||||||
USER safeuser
|
USER safeuser
|
||||||
# Prep 'sudo' commands.
|
# Prep 'sudo' commands.
|
||||||
#RUN echo 'abcd8765' | sudo -S pwd
|
#RUN echo 'abcd8765' | sudo -S pwd
|
||||||
|
|
||||||
# Install Redis. TODO: Make this a separate container.
|
|
||||||
|
|
||||||
|
|
||||||
# Clone the repository
|
# Clone the repository
|
||||||
WORKDIR /home/safeuser
|
WORKDIR /home/safeuser
|
||||||
RUN git clone https://github.com/Permissionless-Software-Foundation/bch-api
|
RUN git clone https://github.com/Permissionless-Software-Foundation/bch-api
|
||||||
|
|||||||
Generated
+15724
-273
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -14,7 +14,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./src/app.js",
|
"start": "node ./src/app.js",
|
||||||
"dev": "nodemon ./dist/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",
|
"lint": "standard --env mocha --fix",
|
||||||
"test-v4": "export NETWORK=mainnet && nyc --reporter=text mocha --exit --timeout 60000 test/v4/",
|
"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/",
|
"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",
|
"test:integration:nft": "mocha --timeout 25000 -g '#nft' test/v4/integration/nft.js",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/",
|
"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: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/"
|
"test:temp2": "export NETWORK=mainnet && mocha -g '#utxosBulk' --exit --timeout 30000 test/v5/"
|
||||||
},
|
},
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
"node": ">=10.15.1"
|
"node": ">=10.15.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@psf/bch-js": "^4.18.0",
|
"@psf/bch-js": "^4.20.7",
|
||||||
"apidoc": "^0.26.0",
|
"apidoc": "^0.26.0",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"bitcore-lib-cash": "^8.23.1",
|
"bitcore-lib-cash": "^8.23.1",
|
||||||
@@ -86,6 +86,6 @@
|
|||||||
},
|
},
|
||||||
"apidoc": {
|
"apidoc": {
|
||||||
"title": "bch-api",
|
"title": "bch-api",
|
||||||
"url": "https://api.fullstack.cash/v4"
|
"url": "https://api.fullstack.cash/v5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ const xpubV5 = require('./routes/v5/xpub')
|
|||||||
const ElectrumXV5 = require('./routes/v5/electrumx')
|
const ElectrumXV5 = require('./routes/v5/electrumx')
|
||||||
const EncryptionV5 = require('./routes/v5/encryption')
|
const EncryptionV5 = require('./routes/v5/encryption')
|
||||||
const PriceV5 = require('./routes/v5/price')
|
const PriceV5 = require('./routes/v5/price')
|
||||||
|
const JWTV5 = require('./routes/v5/jwt')
|
||||||
// const Ninsight = require('./routes/v5/ninsight')
|
// const Ninsight = require('./routes/v5/ninsight')
|
||||||
|
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
@@ -80,6 +81,7 @@ const encryptionv5 = new EncryptionV5()
|
|||||||
const pricev5 = new PriceV5()
|
const pricev5 = new PriceV5()
|
||||||
const utilV5 = new UtilV5({ electrumx: electrumxv5 })
|
const utilV5 = new UtilV5({ electrumx: electrumxv5 })
|
||||||
const dsproofV5 = new DSProofV5()
|
const dsproofV5 = new DSProofV5()
|
||||||
|
const jwtV5 = new JWTV5()
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.locals.env = process.env
|
app.locals.env = process.env
|
||||||
@@ -189,6 +191,7 @@ app.use(`/${v5prefix}/` + 'encryption', encryptionv5.router)
|
|||||||
app.use(`/${v5prefix}/` + 'price', pricev5.router)
|
app.use(`/${v5prefix}/` + 'price', pricev5.router)
|
||||||
app.use(`/${v5prefix}/` + 'util', utilV5.router)
|
app.use(`/${v5prefix}/` + 'util', utilV5.router)
|
||||||
app.use(`/${v5prefix}/` + 'dsproof', dsproofV5.router)
|
app.use(`/${v5prefix}/` + 'dsproof', dsproofV5.router)
|
||||||
|
app.use(`/${v5prefix}/` + 'jwt', jwtV5.router)
|
||||||
|
|
||||||
// const ninsight = new Ninsight()
|
// const ninsight = new Ninsight()
|
||||||
app.use(`/${v5prefix}/` + 'ninsight', ninsight.router)
|
app.use(`/${v5prefix}/` + 'ninsight', ninsight.router)
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
// req.locals.jwtToken property.
|
// req.locals.jwtToken property.
|
||||||
const getTokenFromHeaders = (req, res, next) => {
|
const getTokenFromHeaders = (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
// console.log('req.headers: ', req.headers)
|
||||||
|
|
||||||
// Only executes if the authorization header exists.
|
// Only executes if the authorization header exists.
|
||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
// Retrieve the auth string from the header object.
|
// Retrieve the auth string from the header object.
|
||||||
|
|||||||
@@ -220,11 +220,18 @@ class RateLimits {
|
|||||||
// it will return the 'res' object with an error status and message, which
|
// it will return the 'res' object with an error status and message, which
|
||||||
// should be returned by the middleware.
|
// should be returned by the middleware.
|
||||||
async trackRateLimits (req, res, jwtToken) {
|
async trackRateLimits (req, res, jwtToken) {
|
||||||
|
const debugInfo = {
|
||||||
|
jwtToken,
|
||||||
|
userObj: req.body.usrObj,
|
||||||
|
locals: req.locals
|
||||||
|
}
|
||||||
|
|
||||||
// Anonymous rate limits are used by default.
|
// Anonymous rate limits are used by default.
|
||||||
let pointsToConsume = ANON_LIMITS
|
let pointsToConsume = ANON_LIMITS
|
||||||
// console.log('pointsToConsume: ', pointsToConsume)
|
// console.log('pointsToConsume: ', pointsToConsume)
|
||||||
|
|
||||||
let key = req.ip // Use the IP address as the key, by default.
|
let key = req.ip // Use the IP address as the key, by default.
|
||||||
|
debugInfo.ip = req.ip
|
||||||
|
|
||||||
// console.log('jwtToken: ', jwtToken)
|
// console.log('jwtToken: ', jwtToken)
|
||||||
|
|
||||||
@@ -236,8 +243,10 @@ class RateLimits {
|
|||||||
|
|
||||||
// Preferentially use the decoded ID in the JWT payload, as the key.
|
// Preferentially use the decoded ID in the JWT payload, as the key.
|
||||||
key = decoded.id
|
key = decoded.id
|
||||||
|
debugInfo.id = key
|
||||||
|
|
||||||
pointsToConsume = decoded.pointsToConsume
|
pointsToConsume = decoded.pointsToConsume
|
||||||
|
debugInfo.pointsToConsume = pointsToConsume
|
||||||
}
|
}
|
||||||
// console.log(`rate limit key: ${key}`)
|
// console.log(`rate limit key: ${key}`)
|
||||||
|
|
||||||
@@ -261,6 +270,10 @@ class RateLimits {
|
|||||||
res.locals.rateLimitTriggered = true
|
res.locals.rateLimitTriggered = true
|
||||||
// console.log('res.locals: ', res.locals)
|
// console.log('res.locals: ', res.locals)
|
||||||
|
|
||||||
|
// console.log(
|
||||||
|
// `rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}`
|
||||||
|
// )
|
||||||
|
|
||||||
// Rate limited was triggered
|
// Rate limited was triggered
|
||||||
res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
|
||||||
return res.json({
|
return res.json({
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class Price {
|
|||||||
|
|
||||||
this.priceUrl = 'https://api.coinbase.com/v2/exchange-rates?currency=BCH'
|
this.priceUrl = 'https://api.coinbase.com/v2/exchange-rates?currency=BCH'
|
||||||
this.coinexPriceUrl =
|
this.coinexPriceUrl =
|
||||||
'https://api.coinex.com/v1/market/ticker?market=bchausdt'
|
'https://api.coinex.com/v1/market/ticker?market=xecusdt'
|
||||||
|
|
||||||
this.bchCoinexPriceUrl =
|
this.bchCoinexPriceUrl =
|
||||||
'https://api.coinex.com/v1/market/ticker?market=bchusdt'
|
'https://api.coinex.com/v1/market/ticker?market=bchusdt'
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
Electrum API route
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const express = require('express')
|
||||||
|
const router = express.Router()
|
||||||
|
const axios = require('axios')
|
||||||
|
const util = require('util')
|
||||||
|
// const bitcore = require('bitcore-lib-cash')
|
||||||
|
|
||||||
|
// const ElectrumCash = require('electrum-cash').ElectrumClient
|
||||||
|
// const ElectrumCash = require('/home/trout/work/personal/electrum-cash/electrum.js').Client // eslint-disable-line
|
||||||
|
|
||||||
|
const wlogger = require('../../../util/winston-logging')
|
||||||
|
const config = require('../../../../config')
|
||||||
|
|
||||||
|
const RouteUtils = require('../../../util/route-utils')
|
||||||
|
const routeUtils = new RouteUtils()
|
||||||
|
|
||||||
|
// const BCHJS = require("@psf/bch-js");
|
||||||
|
// const bchjs = new BCHJS();
|
||||||
|
|
||||||
|
let _this
|
||||||
|
|
||||||
|
class BcashSlp {
|
||||||
|
constructor () {
|
||||||
|
this.config = config
|
||||||
|
this.axios = axios
|
||||||
|
this.routeUtils = routeUtils
|
||||||
|
// this.bchjs = bchjs;
|
||||||
|
// _this.bitcore = bitcore
|
||||||
|
|
||||||
|
this.bcashServer = process.env.BCASH_SERVER
|
||||||
|
if (!this.bcashServer) {
|
||||||
|
// console.warn('FULCRUM_API env var not set. Can not connect to Fulcrum indexer.')
|
||||||
|
throw new Error(
|
||||||
|
'BCASH_SERVER env var not set. Can not connect to bcash full node.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.router = router
|
||||||
|
this.router.get('/', this.root)
|
||||||
|
this.router.get('/utxos/:address', this.getUtxos)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} /bcash/utxos/{addr} Get utxos for a single address.
|
||||||
|
* @apiName UTXOs for a single address
|
||||||
|
* @apiGroup bcash
|
||||||
|
* @apiDescription Returns an object with UTXOs associated with an address.
|
||||||
|
* This UTXOs will be hydrated with token information.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @apiExample Example usage:
|
||||||
|
* curl -X GET "https://api.fullstack.cash/v5/bcash/utxos/bitcoincash:qr69kyzha07dcecrsvjwsj4s6slnlq4r8c30lxnur3" -H "accept: application/json"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// GET handler for single balance
|
||||||
|
async getUtxos (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.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Customize this function below here for bcash, based on this gist:
|
||||||
|
// https://gist.github.com/christroutner/dcb25a895900e557d7b43341ee85fa79
|
||||||
|
|
||||||
|
wlogger.debug(
|
||||||
|
'Executing electrumx/getUtxos with this address: ',
|
||||||
|
cashAddr
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get data from ElectrumX server.
|
||||||
|
const response = await _this.axios.get(
|
||||||
|
`${_this.fulcrumApi}electrumx/utxos/${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/getUtxos().', err)
|
||||||
|
|
||||||
|
return _this.errorHandler(err, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DRY error handler.
|
||||||
|
errorHandler (err, res) {
|
||||||
|
// Attempt to decode the error message.
|
||||||
|
const { msg, status } = _this.routeUtils.decodeError(err)
|
||||||
|
// console.log('errorHandler msg: ', msg)
|
||||||
|
// console.log('errorHandler status: ', status)
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
res.status(status)
|
||||||
|
return res.json({ success: false, error: msg })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle error patterns specific to this route.
|
||||||
|
if (err.message) {
|
||||||
|
res.status(400)
|
||||||
|
return res.json({ success: false, error: err.message })
|
||||||
|
}
|
||||||
|
|
||||||
|
// If error can be handled, return the stack trace
|
||||||
|
res.status(500)
|
||||||
|
return res.json({ error: util.inspect(err) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root API endpoint. Simply acknowledges that it exists.
|
||||||
|
root (req, res, next) {
|
||||||
|
return res.json({ status: 'bcash-slp' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BcashSlp
|
||||||
@@ -34,6 +34,7 @@ class Electrum {
|
|||||||
|
|
||||||
this.fulcrumApi = process.env.FULCRUM_API
|
this.fulcrumApi = process.env.FULCRUM_API
|
||||||
if (!this.fulcrumApi) {
|
if (!this.fulcrumApi) {
|
||||||
|
// console.warn('FULCRUM_API env var not set. Can not connect to Fulcrum indexer.')
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'FULCRUM_API env var not set. Can not connect to Fulcrum indexer.'
|
'FULCRUM_API env var not set. Can not connect to Fulcrum indexer.'
|
||||||
)
|
)
|
||||||
@@ -451,11 +452,13 @@ class Electrum {
|
|||||||
const response = await _this.axios.get(
|
const response = await _this.axios.get(
|
||||||
`${_this.fulcrumApi}electrumx/tx/data/${txid}`
|
`${_this.fulcrumApi}electrumx/tx/data/${txid}`
|
||||||
)
|
)
|
||||||
// console.log(`_transactionDetailsFromElectrum(): ${JSON.stringify(electrumResponse, null, 2)}`)
|
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
|
||||||
|
|
||||||
res.status(200)
|
res.status(200)
|
||||||
return res.json(response.data)
|
return res.json(response.data)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log('err: ', err)
|
||||||
|
|
||||||
// Write out error to error log.
|
// Write out error to error log.
|
||||||
wlogger.error('Error in elecrumx.js/getTransactionDetails().', err)
|
wlogger.error('Error in elecrumx.js/getTransactionDetails().', err)
|
||||||
|
|
||||||
@@ -1085,6 +1088,9 @@ class Electrum {
|
|||||||
errorHandler (err, res) {
|
errorHandler (err, res) {
|
||||||
// Attempt to decode the error message.
|
// Attempt to decode the error message.
|
||||||
const { msg, status } = _this.routeUtils.decodeError(err)
|
const { msg, status } = _this.routeUtils.decodeError(err)
|
||||||
|
// console.log('errorHandler msg: ', msg)
|
||||||
|
// console.log('errorHandler status: ', status)
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
res.status(status)
|
res.status(status)
|
||||||
return res.json({ success: false, error: msg })
|
return res.json({ success: false, error: msg })
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const routeUtils = new RouteUtils()
|
|||||||
const BCHJS = require('@psf/bch-js')
|
const BCHJS = require('@psf/bch-js')
|
||||||
const restURL = process.env.LOCAL_RESTURL
|
const restURL = process.env.LOCAL_RESTURL
|
||||||
? process.env.LOCAL_RESTURL
|
? process.env.LOCAL_RESTURL
|
||||||
: 'https://api.fullstack.cash/v4/'
|
: 'https://api.fullstack.cash/v5/'
|
||||||
const bchjs = new BCHJS({ restURL })
|
const bchjs = new BCHJS({ restURL })
|
||||||
|
|
||||||
let _this
|
let _this
|
||||||
@@ -76,7 +76,7 @@ class Encryption {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getPublicKey (req, res, next) {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class Blockchain {
|
|||||||
this.router.get('/verifyTxOutProof/:proof', this.verifyTxOutProofSingle)
|
this.router.get('/verifyTxOutProof/:proof', this.verifyTxOutProofSingle)
|
||||||
this.router.post('/verifyTxOutProof', this.verifyTxOutProofBulk)
|
this.router.post('/verifyTxOutProof', this.verifyTxOutProofBulk)
|
||||||
this.router.post('/getBlock', this.getBlock)
|
this.router.post('/getBlock', this.getBlock)
|
||||||
|
this.router.get('/getBlockHash/:height', this.getBlockHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
root (req, res, next) {
|
root (req, res, next) {
|
||||||
@@ -81,7 +82,7 @@ class Blockchain {
|
|||||||
* block chain.
|
* block chain.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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
|
* @apiSuccess {String} bestBlockHash 000000000000000002bc884334336d99c9a9c616670a9244c6a8c1fc35aa91a1
|
||||||
*/
|
*/
|
||||||
@@ -112,7 +113,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns an object containing various state info regarding blockchain processing.
|
* @apiDescription Returns an object containing various state info regarding blockchain processing.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 {Object} object Object containing data
|
||||||
* @apiSuccess {String} object.chain "main"
|
* @apiSuccess {String} object.chain "main"
|
||||||
@@ -156,7 +157,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns the number of blocks in the longest blockchain.
|
* @apiDescription Returns the number of blocks in the longest blockchain.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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
|
* @apiSuccess {Number} bestBlockCount 587665
|
||||||
*/
|
*/
|
||||||
@@ -189,7 +190,7 @@ class Blockchain {
|
|||||||
* returns an Object with information about blockheader hash.
|
* returns an Object with information about blockheader hash.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 {String} hash block hash
|
||||||
* @apiParam {Boolean} verbose Return verbose data
|
* @apiParam {Boolean} verbose Return verbose data
|
||||||
@@ -250,7 +251,7 @@ class Blockchain {
|
|||||||
* returns an Object with information about blockheader hash.
|
* returns an Object with information about blockheader hash.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 {String} hash block hash
|
||||||
* @apiParam {Boolean} verbose Return verbose data
|
* @apiParam {Boolean} verbose Return verbose data
|
||||||
@@ -342,7 +343,7 @@ class Blockchain {
|
|||||||
* including the main chain as well as orphaned branches.
|
* including the main chain as well as orphaned branches.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getChainTips (req, res, next) {
|
||||||
@@ -373,7 +374,7 @@ class Blockchain {
|
|||||||
* power on the network.
|
* power on the network.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getDifficulty (req, res, next) {
|
||||||
@@ -405,7 +406,7 @@ class Blockchain {
|
|||||||
* mempool (unconfirmed)
|
* mempool (unconfirmed)
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getMempoolEntrySingle (req, res, next) {
|
||||||
@@ -443,7 +444,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns mempool data for multiple transactions
|
* @apiDescription Returns mempool data for multiple transactions
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getMempoolEntryBulk (req, res, next) {
|
||||||
try {
|
try {
|
||||||
@@ -516,7 +517,7 @@ class Blockchain {
|
|||||||
* against the 25 ancestor chain-limit.
|
* against the 25 ancestor chain-limit.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getMempoolAncestorsSingle (req, res, next) {
|
||||||
@@ -558,7 +559,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns details on the active state of the TX memory pool.
|
* @apiDescription Returns details on the active state of the TX memory pool.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getMempoolInfo (req, res, next) {
|
||||||
@@ -588,7 +589,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns details on the active state of the TX memory pool.
|
* @apiDescription Returns details on the active state of the TX memory pool.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 +601,7 @@ class Blockchain {
|
|||||||
* of string transaction ids.
|
* of string transaction ids.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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
|
* @apiParam {Boolean} verbose Return verbose data
|
||||||
*
|
*
|
||||||
@@ -636,7 +637,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns details about an unspent transaction output.
|
* @apiDescription Returns details about an unspent transaction output.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 {String} txid Transaction id (required)
|
||||||
* @apiParam {Number} n Output number (required)
|
* @apiParam {Number} n Output number (required)
|
||||||
@@ -693,7 +694,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns details about an unspent transaction output (UTXO).
|
* @apiDescription Returns details about an unspent transaction output (UTXO).
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 {String} txid Transaction id (required)
|
||||||
* @apiParam {Number} vout of transaction (required)
|
* @apiParam {Number} vout of transaction (required)
|
||||||
@@ -747,7 +748,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns a hex-encoded proof that 'txid' was included in a block.
|
* @apiDescription Returns a hex-encoded proof that 'txid' was included in a block.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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)
|
* @apiParam {String} txid Transaction id (required)
|
||||||
*
|
*
|
||||||
@@ -946,7 +947,7 @@ class Blockchain {
|
|||||||
* @apiDescription Returns block details
|
* @apiDescription Returns block details
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 {String} blockhash Block hash (required)
|
||||||
* @apiParam {Number} verbosity Default 1 (optional)
|
* @apiParam {Number} verbosity Default 1 (optional)
|
||||||
@@ -984,6 +985,47 @@ class Blockchain {
|
|||||||
return _this.errorHandler(err, res)
|
return _this.errorHandler(err, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /blockchain/getBlockHash/ Get block hash
|
||||||
|
* @apiName getBlockHash
|
||||||
|
* @apiGroup Blockchain
|
||||||
|
* @apiDescription Returns the hash of a block, given its block height.
|
||||||
|
*
|
||||||
|
* @apiExample Example usage:
|
||||||
|
* curl -X GET "https://api.fullstack.cash/v5/blockchain/getBlockHash/544444" -H "accept: application/json"
|
||||||
|
*
|
||||||
|
* @apiParam {String} height Block height (required)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async getBlockHash (req, res, next) {
|
||||||
|
try {
|
||||||
|
// Validate input parameter
|
||||||
|
const height = req.params.height
|
||||||
|
if (!height || height === '') {
|
||||||
|
res.status(400)
|
||||||
|
return res.json({ error: 'height can not be empty' })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Axios options
|
||||||
|
const options = _this.routeUtils.getAxiosOptions()
|
||||||
|
|
||||||
|
options.data.id = 'getblockhash'
|
||||||
|
options.data.method = 'getblockhash'
|
||||||
|
options.data.params = [parseInt(height)]
|
||||||
|
|
||||||
|
const response = await _this.axios.request(options)
|
||||||
|
|
||||||
|
return res.json(response.data.result)
|
||||||
|
} catch (err) {
|
||||||
|
// Write out error to error log.
|
||||||
|
// logger.error(`Error in rawtransactions/decodeRawTransaction: `, err)
|
||||||
|
wlogger.error('Error in blockchain.js/getBlockHash()', err)
|
||||||
|
|
||||||
|
return _this.errorHandler(err, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Blockchain
|
module.exports = Blockchain
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class Control {
|
|||||||
* @apiDescription RPC call which gets basic full node information.
|
* @apiDescription RPC call which gets basic full node information.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getNetworkInfo (req, res, next) {
|
||||||
@@ -75,42 +75,6 @@ class Control {
|
|||||||
return _this.errorHandler(error, res)
|
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
|
module.exports = Control
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class Mining {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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:
|
* @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:
|
* @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) {
|
async decodeRawTransactionSingle (req, res, next) {
|
||||||
try {
|
try {
|
||||||
@@ -103,7 +103,7 @@ class RawTransactions {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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:
|
* @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:
|
* @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:
|
* @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) {
|
async getRawTransactionBulk (req, res, next) {
|
||||||
@@ -375,7 +375,7 @@ class RawTransactions {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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:
|
* @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:
|
* @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.priceUrl = 'https://api.coinbase.com/v2/exchange-rates?currency=BCH'
|
||||||
this.coinexPriceUrl =
|
this.coinexPriceUrl =
|
||||||
'https://api.coinex.com/v1/market/ticker?market=bchausdt'
|
'https://api.coinex.com/v1/market/ticker?market=xecusdt'
|
||||||
|
|
||||||
this.bchCoinexPriceUrl =
|
this.bchCoinexPriceUrl =
|
||||||
'https://api.coinex.com/v1/market/ticker?market=bchusdt'
|
'https://api.coinex.com/v1/market/ticker?market=bchusdt'
|
||||||
@@ -64,7 +64,7 @@ class Price {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getUSD (req, res, next) {
|
||||||
@@ -96,7 +96,7 @@ class Price {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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
|
// Get rates for several different currencies
|
||||||
@@ -129,7 +129,7 @@ class Price {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getBCHAUSD (req, res, next) {
|
||||||
@@ -163,7 +163,7 @@ class Price {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
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.
|
// Instantiate a local copy of bch-js using the local REST API server.
|
||||||
const LOCAL_RESTURL = process.env.LOCAL_RESTURL
|
const LOCAL_RESTURL = process.env.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('@psf/bch-js')
|
||||||
// const BCHJS = require('../../../../bch-js')
|
// const BCHJS = require('../../../../bch-js')
|
||||||
@@ -51,10 +51,10 @@ const rawTransactions = new RawTransactions()
|
|||||||
// Setup REST and TREST URLs used by slpjs
|
// Setup REST and TREST URLs used by slpjs
|
||||||
// Dev note: this allows for unit tests to mock the URL.
|
// Dev note: this allows for unit tests to mock the URL.
|
||||||
if (!process.env.REST_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) {
|
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
|
let _this
|
||||||
@@ -181,7 +181,7 @@ class Slp {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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:
|
* @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) {
|
async getSlpWhitelist (req, res, next) {
|
||||||
@@ -1321,7 +1321,7 @@ class Slp {
|
|||||||
* /slp/whitelist endpoint.
|
* /slp/whitelist endpoint.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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.
|
* /slp/whitelist endpoint.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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:
|
* @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:
|
* @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:
|
* @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.
|
* (1 or 2) will also be returned.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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.
|
* not been confirmed.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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.
|
* SLP tokens.
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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:
|
* @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) {
|
async getStatus (req, res, next) {
|
||||||
@@ -2239,7 +2239,7 @@ class Slp {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getNftChildren (req, res, next) {
|
||||||
@@ -2315,7 +2315,7 @@ class Slp {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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) {
|
async getNftGroup (req, res, next) {
|
||||||
|
|||||||
+6
-412
@@ -14,27 +14,8 @@ util.inspect.defaultOptions = { depth: 1 }
|
|||||||
|
|
||||||
const BCHJS = require('@psf/bch-js')
|
const BCHJS = require('@psf/bch-js')
|
||||||
const bchjs = new BCHJS()
|
const bchjs = new BCHJS()
|
||||||
// const BCHJS_TESTNET = 'https://testnet.bchjs.cash/v4/'
|
|
||||||
|
|
||||||
// const bchjsHTTP = axios.create({
|
// let _this
|
||||||
// baseURL: process.env.RPC_BASEURL
|
|
||||||
// })
|
|
||||||
|
|
||||||
// const username = process.env.RPC_USERNAME
|
|
||||||
// const password = process.env.RPC_PASSWORD
|
|
||||||
|
|
||||||
// const requestConfig = {
|
|
||||||
// method: 'post',
|
|
||||||
// auth: {
|
|
||||||
// username: username,
|
|
||||||
// password: password
|
|
||||||
// },
|
|
||||||
// data: {
|
|
||||||
// jsonrpc: '1.0'
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
let _this
|
|
||||||
|
|
||||||
class UtilRoute {
|
class UtilRoute {
|
||||||
constructor (utilConfig) {
|
constructor (utilConfig) {
|
||||||
@@ -58,9 +39,9 @@ class UtilRoute {
|
|||||||
this.router.get('/', this.root)
|
this.router.get('/', this.root)
|
||||||
this.router.get('/validateAddress/:address', this.validateAddressSingle)
|
this.router.get('/validateAddress/:address', this.validateAddressSingle)
|
||||||
this.router.post('/validateAddress', this.validateAddressBulk)
|
this.router.post('/validateAddress', this.validateAddressBulk)
|
||||||
this.router.post('/sweep', this.sweepWif)
|
// this.router.post('/sweep', this.sweepWif)
|
||||||
|
|
||||||
_this = this
|
// _this = this
|
||||||
}
|
}
|
||||||
|
|
||||||
root (req, res, next) {
|
root (req, res, next) {
|
||||||
@@ -75,7 +56,7 @@ class UtilRoute {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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 +105,8 @@ class UtilRoute {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @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/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/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"],"from": 1, "to": 5}'
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -214,393 +195,6 @@ class UtilRoute {
|
|||||||
return res.json({ error: util.inspect(err) })
|
return res.json({ error: util.inspect(err) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @api {post} /util/sweep Sweep BCH and tokens
|
|
||||||
* @apiName Sweep BCH and tokens from a paper wallet
|
|
||||||
* @apiGroup Util
|
|
||||||
* @apiDescription This function can be used to check the BCH balance of a
|
|
||||||
* paper wallet. It can also be used to sweep BCH and tokens from a paper
|
|
||||||
* wallet and send them to a destination address.
|
|
||||||
*
|
|
||||||
* Note: It does not yet support multiple token classes on the same paper wallet.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @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"}'
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
async sweepWif (req, res, next) {
|
|
||||||
try {
|
|
||||||
// Validate input
|
|
||||||
const wif = req.body.wif
|
|
||||||
const toAddr = req.body.toAddr
|
|
||||||
const balanceOnly = req.body.balanceOnly
|
|
||||||
|
|
||||||
if (typeof wif !== 'string' || wif.length !== 52) {
|
|
||||||
res.status(400)
|
|
||||||
return res.json({
|
|
||||||
error: 'WIF needs to a proper compressed WIF starting with K or L'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!balanceOnly) {
|
|
||||||
// Only throw error if balanceOnly is false or undefined.
|
|
||||||
if (!toAddr || toAddr === '') {
|
|
||||||
res.status(400)
|
|
||||||
return res.json({ error: 'address can not be empty' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wlogger.debug('Executing util/sweepWif with this address: ', toAddr)
|
|
||||||
|
|
||||||
// Generate a private and public key pair from the WIF.
|
|
||||||
const ecPair = bchjs.ECPair.fromWIF(wif)
|
|
||||||
const fromAddr = bchjs.ECPair.toCashAddress(ecPair)
|
|
||||||
|
|
||||||
// Get a balance on the public address
|
|
||||||
const balances = await _this.electrumx._balanceFromElectrumx(fromAddr)
|
|
||||||
// console.log(`balances: ${JSON.stringify(balances, null, 2)}`)
|
|
||||||
|
|
||||||
// Total balance is the sum of the confirmed and unconfirmed balance.
|
|
||||||
const totalBalance = balances.confirmed + balances.unconfirmed
|
|
||||||
|
|
||||||
// Exit if balance is zero.
|
|
||||||
if (isNaN(totalBalance) || totalBalance === 0) {
|
|
||||||
res.status(422)
|
|
||||||
return res.json({ error: 'No balance found at BCH address.' })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if this is a balance-only call.
|
|
||||||
if (balanceOnly) {
|
|
||||||
res.status(200)
|
|
||||||
return res.json(totalBalance)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all UTXOs help by the address.
|
|
||||||
const utxos = await _this.electrumx._utxosFromElectrumx(fromAddr)
|
|
||||||
// console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
|
||||||
|
|
||||||
const tokenUtxos = []
|
|
||||||
const bchUtxos = []
|
|
||||||
|
|
||||||
// Exit if there are no UTXOs.
|
|
||||||
if (utxos.length === 0) {
|
|
||||||
res.status(422)
|
|
||||||
return res.json({ error: 'No utxos found.' })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out which UTXOs are associated with SLP tokens.
|
|
||||||
const isTokenUtxo = await _this.bchjs.SLP.Utils.tokenUtxoDetails(utxos)
|
|
||||||
// console.log(`isTokenUtxo: ${JSON.stringify(isTokenUtxo, null, 2)}`)
|
|
||||||
|
|
||||||
// Separate the bch and token UTXOs.
|
|
||||||
for (let i = 0; i < utxos.length; i++) {
|
|
||||||
// Filter based on isTokenUtxo.
|
|
||||||
if (!isTokenUtxo[i]) bchUtxos.push(utxos[i])
|
|
||||||
else tokenUtxos.push(isTokenUtxo[i])
|
|
||||||
}
|
|
||||||
// console.log(
|
|
||||||
// `bchUtxos.length: ${bchUtxos.length}, tokenUtxos.length: ${tokenUtxos.length}`
|
|
||||||
// )
|
|
||||||
|
|
||||||
// Throw error if no BCH to move tokens.
|
|
||||||
if (bchUtxos.length === 0 && tokenUtxos.length > 0) {
|
|
||||||
res.status(422)
|
|
||||||
return res.json({
|
|
||||||
error:
|
|
||||||
'Tokens found, but no BCH UTXOs found. Add BCH to wallet to move tokens.'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log(`tokenUtxos: ${JSON.stringify(tokenUtxos, null, 2)}`)
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
ecPair,
|
|
||||||
utxos,
|
|
||||||
fromAddr,
|
|
||||||
toAddr,
|
|
||||||
bchUtxos,
|
|
||||||
tokenUtxos
|
|
||||||
}
|
|
||||||
|
|
||||||
let hex
|
|
||||||
|
|
||||||
// Choose the sweeping algorithm, based on if there are tokens or not.
|
|
||||||
if (tokenUtxos.length === 0) hex = await _this._sweepBCH(options)
|
|
||||||
else hex = await _this._sweepTokens(options, bchUtxos, tokenUtxos)
|
|
||||||
// console.log(`hex: ${hex}`)
|
|
||||||
|
|
||||||
// Throw error if there is more than one token class.
|
|
||||||
|
|
||||||
// Generate a transaction to move tokens and BCH.
|
|
||||||
|
|
||||||
// Broadcast the transaction.
|
|
||||||
const txid = _this.bchjs.RawTransactions.sendRawTransaction([hex])
|
|
||||||
|
|
||||||
res.status(200)
|
|
||||||
return res.json(txid)
|
|
||||||
} catch (err) {
|
|
||||||
// Attempt to decode the error message.
|
|
||||||
const { msg, status } = routeUtils.decodeError(err)
|
|
||||||
if (msg) {
|
|
||||||
res.status(status)
|
|
||||||
return res.json({ error: msg })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Catch the specific case of multiple tokens.
|
|
||||||
if (
|
|
||||||
err.message &&
|
|
||||||
err.message.indexOf('Multiple token classes detected') > -1
|
|
||||||
) {
|
|
||||||
res.status(422)
|
|
||||||
return res.json({ error: err.message })
|
|
||||||
}
|
|
||||||
|
|
||||||
wlogger.error('Error in util.js/sweepWif().', err)
|
|
||||||
console.error('Error in util.js/sweepWif().', err)
|
|
||||||
|
|
||||||
res.status(500)
|
|
||||||
return res.json({ error: err.message })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sweep BCH only from a private WIF.
|
|
||||||
async _sweepBCH (options) {
|
|
||||||
try {
|
|
||||||
// const wif = flags.wif
|
|
||||||
// const toAddr = flags.address
|
|
||||||
|
|
||||||
const ecPair = options.ecPair
|
|
||||||
const toAddr = options.toAddr
|
|
||||||
|
|
||||||
// const fromAddr = this.BITBOX.ECPair.toCashAddress(ecPair)
|
|
||||||
//
|
|
||||||
// // Get the UTXOs for that address.
|
|
||||||
// let utxos = await this.BITBOX.Blockbook.utxo(fromAddr)
|
|
||||||
// console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
|
||||||
|
|
||||||
let utxos = options.utxos
|
|
||||||
|
|
||||||
// Ensure all utxos have the satoshis property.
|
|
||||||
utxos = utxos.map((x) => {
|
|
||||||
x.satoshis = Number(x.value)
|
|
||||||
return x
|
|
||||||
})
|
|
||||||
// console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
|
||||||
|
|
||||||
// instance of transaction builder
|
|
||||||
let transactionBuilder
|
|
||||||
if (options.testnet) {
|
|
||||||
transactionBuilder = new _this.bchjs.TransactionBuilder('testnet')
|
|
||||||
} else transactionBuilder = new _this.bchjs.TransactionBuilder()
|
|
||||||
|
|
||||||
let originalAmount = 0
|
|
||||||
|
|
||||||
// Loop through all UTXOs.
|
|
||||||
for (let i = 0; i < utxos.length; i++) {
|
|
||||||
const utxo = utxos[i]
|
|
||||||
|
|
||||||
originalAmount = originalAmount + utxo.value
|
|
||||||
|
|
||||||
transactionBuilder.addInput(utxo.tx_hash, utxo.tx_pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalAmount < 546) {
|
|
||||||
throw new Error(
|
|
||||||
'Original amount less than the dust limit. Not enough BCH to send.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get byte count to calculate fee. paying 1 sat/byte
|
|
||||||
const byteCount = _this.bchjs.BitcoinCash.getByteCount(
|
|
||||||
{ P2PKH: utxos.length },
|
|
||||||
{ P2PKH: 1 }
|
|
||||||
)
|
|
||||||
const fee = Math.ceil(1.1 * byteCount)
|
|
||||||
|
|
||||||
// amount to send to receiver. It's the original amount - 1 sat/byte for tx size
|
|
||||||
const sendAmount = originalAmount - fee
|
|
||||||
|
|
||||||
// add output w/ address and amount to send
|
|
||||||
transactionBuilder.addOutput(
|
|
||||||
_this.bchjs.Address.toLegacyAddress(toAddr),
|
|
||||||
sendAmount
|
|
||||||
)
|
|
||||||
|
|
||||||
// Loop through each input and sign
|
|
||||||
let redeemScript
|
|
||||||
for (var i = 0; i < utxos.length; i++) {
|
|
||||||
const utxo = utxos[i]
|
|
||||||
|
|
||||||
transactionBuilder.sign(
|
|
||||||
i,
|
|
||||||
ecPair,
|
|
||||||
redeemScript,
|
|
||||||
transactionBuilder.hashTypes.SIGHASH_ALL,
|
|
||||||
utxo.value
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// build tx
|
|
||||||
const tx = transactionBuilder.build()
|
|
||||||
|
|
||||||
// output rawhex
|
|
||||||
const hex = tx.toHex()
|
|
||||||
return hex
|
|
||||||
} catch (err) {
|
|
||||||
wlogger.error('Error in util.js/sweepBCH().')
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sweep BCH and tokens from a WIF.
|
|
||||||
async _sweepTokens (options) {
|
|
||||||
try {
|
|
||||||
// const { ecPair, utxos, fromAddr, toAddr, bchUtxos, tokenUtxos } = options
|
|
||||||
const { ecPair, utxos, toAddr, bchUtxos, tokenUtxos } = options
|
|
||||||
|
|
||||||
// Input validation
|
|
||||||
if (!Array.isArray(bchUtxos) || bchUtxos.length === 0) {
|
|
||||||
throw new Error('bchUtxos need to be an array with one UTXO.')
|
|
||||||
}
|
|
||||||
if (!Array.isArray(tokenUtxos) || tokenUtxos.length === 0) {
|
|
||||||
throw new Error('tokenUtxos need to be an array with one UTXO.')
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (flags.testnet)
|
|
||||||
// this.BITBOX = new config.BCHLIB({ restURL: config.TESTNET_REST })
|
|
||||||
|
|
||||||
// console.log(`tokenUtxos: ${JSON.stringify(tokenUtxos, null, 2)}`)
|
|
||||||
|
|
||||||
// Ensure there is only one class of token in the wallet. Throw an error if
|
|
||||||
// there is more than one.
|
|
||||||
const tokenId = tokenUtxos[0].tokenId
|
|
||||||
const otherTokens = tokenUtxos.filter((x) => x.tokenId !== tokenId)
|
|
||||||
if (otherTokens.length > 0) {
|
|
||||||
throw new Error(
|
|
||||||
'Multiple token classes detected. This function only supports a single class of token.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// instance of transaction builder
|
|
||||||
let transactionBuilder
|
|
||||||
if (options.testnet) {
|
|
||||||
transactionBuilder = new _this.bchjs.TransactionBuilder('testnet')
|
|
||||||
} else transactionBuilder = new _this.bchjs.TransactionBuilder()
|
|
||||||
|
|
||||||
// Combine all the UTXOs into a single array.
|
|
||||||
const allUtxos = utxos
|
|
||||||
// console.log(`allUtxos: ${JSON.stringify(allUtxos, null, 2)}`)
|
|
||||||
|
|
||||||
// Loop through all UTXOs.
|
|
||||||
let originalAmount = 0
|
|
||||||
for (let i = 0; i < allUtxos.length; i++) {
|
|
||||||
const utxo = allUtxos[i]
|
|
||||||
|
|
||||||
originalAmount = originalAmount + utxo.value
|
|
||||||
|
|
||||||
transactionBuilder.addInput(utxo.tx_hash, utxo.tx_pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalAmount < 300) {
|
|
||||||
throw new Error(
|
|
||||||
'Not enough BCH to send. Send more BCH to the wallet to pay miner fees.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get byte count to calculate fee. paying 1 sat
|
|
||||||
// Note: This may not be totally accurate. Just guessing on the byteCount size.
|
|
||||||
// const byteCount = this.BITBOX.BitcoinCash.getByteCount(
|
|
||||||
// { P2PKH: 3 },
|
|
||||||
// { P2PKH: 5 }
|
|
||||||
// )
|
|
||||||
// //console.log(`byteCount: ${byteCount}`)
|
|
||||||
// const satoshisPerByte = 1.1
|
|
||||||
// const txFee = Math.floor(satoshisPerByte * byteCount)
|
|
||||||
// console.log(`txFee: ${txFee} satoshis\n`)
|
|
||||||
const txFee = 500
|
|
||||||
|
|
||||||
// amount to send back to the sending address. It's the original amount - 1 sat/byte for tx size
|
|
||||||
const remainder = originalAmount - txFee - 546
|
|
||||||
if (remainder < 1) {
|
|
||||||
throw new Error('Selected UTXO does not have enough satoshis')
|
|
||||||
}
|
|
||||||
// console.log(`remainder: ${remainder}`)
|
|
||||||
|
|
||||||
// Tally up the quantity of tokens
|
|
||||||
let tokenQty = 0
|
|
||||||
for (let i = 0; i < tokenUtxos.length; i++) {
|
|
||||||
tokenQty += tokenUtxos[i].tokenQty
|
|
||||||
}
|
|
||||||
// console.log(`tokenQty: ${tokenQty}`)
|
|
||||||
|
|
||||||
// Generate the OP_RETURN entry for an SLP SEND transaction.
|
|
||||||
// console.log(`Generating op-return.`)
|
|
||||||
const {
|
|
||||||
script,
|
|
||||||
outputs
|
|
||||||
} = _this.bchjs.SLP.TokenType1.generateSendOpReturn(tokenUtxos, tokenQty)
|
|
||||||
// console.log(`token outputs: ${outputs}`)
|
|
||||||
|
|
||||||
// Since we are sweeping all tokens from the WIF, there generateOpReturn()
|
|
||||||
// function should only compute 1 token output. If it returns 2, then there
|
|
||||||
// is something unexpected happening.
|
|
||||||
if (outputs > 1) {
|
|
||||||
throw new Error(
|
|
||||||
'More than one class of token detected. Sweep feature not supported.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add OP_RETURN as first output.
|
|
||||||
const data = _this.bchjs.Script.encode(script)
|
|
||||||
transactionBuilder.addOutput(data, 0)
|
|
||||||
|
|
||||||
// Send dust transaction representing tokens being sent.
|
|
||||||
transactionBuilder.addOutput(
|
|
||||||
_this.bchjs.Address.toLegacyAddress(toAddr),
|
|
||||||
546
|
|
||||||
)
|
|
||||||
|
|
||||||
// Last output: send remaining BCH
|
|
||||||
transactionBuilder.addOutput(
|
|
||||||
_this.bchjs.Address.toLegacyAddress(toAddr),
|
|
||||||
remainder
|
|
||||||
)
|
|
||||||
// console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`)
|
|
||||||
|
|
||||||
// Sign each UTXO being consumed.
|
|
||||||
let redeemScript
|
|
||||||
for (let i = 0; i < allUtxos.length; i++) {
|
|
||||||
const thisUtxo = allUtxos[i]
|
|
||||||
// console.log(`thisUtxo: ${JSON.stringify(thisUtxo, null, 2)}`)
|
|
||||||
|
|
||||||
transactionBuilder.sign(
|
|
||||||
i,
|
|
||||||
ecPair,
|
|
||||||
redeemScript,
|
|
||||||
transactionBuilder.hashTypes.SIGHASH_ALL,
|
|
||||||
thisUtxo.value
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// build tx
|
|
||||||
const tx = transactionBuilder.build()
|
|
||||||
|
|
||||||
// output rawhex
|
|
||||||
const hex = tx.toHex()
|
|
||||||
// console.log(`Transaction raw hex: `)
|
|
||||||
// console.log(hex)
|
|
||||||
|
|
||||||
return hex
|
|
||||||
} catch (err) {
|
|
||||||
wlogger.error('Error in util.js/sweepBCH().')
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = UtilRoute
|
module.exports = UtilRoute
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ class RouteUtils {
|
|||||||
msg: '429 Too Many Requests',
|
msg: '429 Too Many Requests',
|
||||||
status: 429
|
status: 429
|
||||||
}
|
}
|
||||||
|
} else if (err.error.includes('Network error:')) {
|
||||||
|
return {
|
||||||
|
msg: err.error,
|
||||||
|
status: 503
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-12
@@ -30,25 +30,18 @@ const mockData = require('./mocks/electrumx-mock')
|
|||||||
const util = require('util')
|
const util = require('util')
|
||||||
util.inspect.defaultOptions = { depth: 1 }
|
util.inspect.defaultOptions = { depth: 1 }
|
||||||
|
|
||||||
// A wrapper for asserting that the correct response is returned when an error
|
if (!process.env.FULCRUM_API) process.env.FULCRUM_API = 'http://localhost'
|
||||||
// is expected.
|
|
||||||
// function expectRouteError (res, result, expectedError, code = 400) {
|
|
||||||
// assert.equal(res.statusCode, code, `HTTP status code ${code} expected.`)
|
|
||||||
//
|
|
||||||
// assert.property(result, 'error')
|
|
||||||
// assert.include(result.error, expectedError)
|
|
||||||
//
|
|
||||||
// assert.property(result, 'success')
|
|
||||||
// assert.equal(result.success, false)
|
|
||||||
// }
|
|
||||||
|
|
||||||
describe('#Electrumx', () => {
|
describe('#Electrumx', () => {
|
||||||
let req, res
|
let req, res
|
||||||
let sandbox
|
let sandbox
|
||||||
const electrumxRoute = new ElecrumxRoute()
|
const electrumxRoute = new ElecrumxRoute()
|
||||||
|
// let electrumxRoute
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
if (!process.env.TEST) process.env.TEST = 'unit'
|
if (!process.env.TEST) {
|
||||||
|
process.env.TEST = 'unit'
|
||||||
|
}
|
||||||
console.log(`Testing type is: ${process.env.TEST}`)
|
console.log(`Testing type is: ${process.env.TEST}`)
|
||||||
|
|
||||||
if (!process.env.NETWORK) process.env.NETWORK = 'testnet'
|
if (!process.env.NETWORK) process.env.NETWORK = 'testnet'
|
||||||
@@ -641,9 +634,25 @@ describe('#Electrumx', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should pass errors from electrum-cash to user', async () => {
|
it('should pass errors from electrum-cash to user', async () => {
|
||||||
|
if (process.env.TEST === 'unit') {
|
||||||
|
sandbox.stub(electrumxRoute.axios, 'get').rejects({
|
||||||
|
response: {
|
||||||
|
data: {
|
||||||
|
error: {
|
||||||
|
message: {
|
||||||
|
success: false,
|
||||||
|
error: 'Invalid tx hash'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
req.params.txid = '02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
|
req.params.txid = '02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c'
|
||||||
|
|
||||||
const result = await electrumxRoute.getTransactionDetails(req, res)
|
const result = await electrumxRoute.getTransactionDetails(req, res)
|
||||||
|
// console.log('result: ', result)
|
||||||
|
|
||||||
assert.property(result, 'error')
|
assert.property(result, 'error')
|
||||||
assert.include(result.error.error, 'Invalid tx hash')
|
assert.include(result.error.error, 'Invalid tx hash')
|
||||||
@@ -823,11 +832,28 @@ describe('#Electrumx', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should pass errors from electrum-cash to user', async () => {
|
it('should pass errors from electrum-cash to user', async () => {
|
||||||
|
if (process.env.TEST === 'unit') {
|
||||||
|
sandbox.stub(electrumxRoute.axios, 'post').rejects({
|
||||||
|
response: {
|
||||||
|
data: {
|
||||||
|
error: {
|
||||||
|
message: {
|
||||||
|
success: false,
|
||||||
|
error:
|
||||||
|
'the transaction was rejected by network rules.\n\nTX decode failed\n'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
req.body.txHex = mockData.txDetails.hex.substring(10)
|
req.body.txHex = mockData.txDetails.hex.substring(10)
|
||||||
const result = await electrumxRoute.broadcastTransaction(req, res)
|
const result = await electrumxRoute.broadcastTransaction(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
assert.equal(res.statusCode, 400, 'Expect 400 status code')
|
||||||
|
// assert.equal(res.statusCode, 503, 'Expect 503 status code')
|
||||||
|
|
||||||
assert.property(result, 'error')
|
assert.property(result, 'error')
|
||||||
assert.include(result.error.error, 'the transaction was rejected')
|
assert.include(result.error.error, 'the transaction was rejected')
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
TESTS FOR THE bcash/slp.js LIBRARY
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const chai = require('chai')
|
||||||
|
const assert = chai.assert
|
||||||
|
|
||||||
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
const BcashSlp = require('../../src/routes/v5/bcash/slp')
|
||||||
|
|
||||||
|
// Mocking data.
|
||||||
|
const { mockReq, mockRes } = require('./mocks/express-mocks')
|
||||||
|
// const mockData = require('./mocks/electrumx-mock')
|
||||||
|
|
||||||
|
// Used for debugging.
|
||||||
|
const util = require('util')
|
||||||
|
util.inspect.defaultOptions = { depth: 1 }
|
||||||
|
|
||||||
|
if (!process.env.BCASH_SERVER) process.env.BCASH_SERVER = 'http://localhost'
|
||||||
|
|
||||||
|
describe('#bcash-slp', () => {
|
||||||
|
let req, res
|
||||||
|
let sandbox
|
||||||
|
const bcashSlp = new BcashSlp()
|
||||||
|
// let electrumxRoute
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
if (!process.env.TEST) {
|
||||||
|
process.env.TEST = 'unit'
|
||||||
|
}
|
||||||
|
console.log(`Testing type is: ${process.env.TEST}`)
|
||||||
|
|
||||||
|
if (!process.env.NETWORK) process.env.NETWORK = 'testnet'
|
||||||
|
|
||||||
|
// Connect to electrumx servers if this is an integration test.
|
||||||
|
// if (process.env.TEST === 'integration') {
|
||||||
|
// await electrumxRoute.connect()
|
||||||
|
// console.log('Connected to ElectrumX server')
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
// console.log(`electrumxRoute.electrumx: `, electrumxRoute.electrumx)
|
||||||
|
// Disconnect from the electrumx server if this is an integration test.
|
||||||
|
// if (process.env.TEST === 'integration') {
|
||||||
|
// await electrumxRoute.disconnect()
|
||||||
|
// console.log('Disconnected from ElectrumX server')
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
|
||||||
|
// electrumxRoute = new ElecrumxRoute()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
sandbox.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
//
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#root', () => {
|
||||||
|
// root route handler.
|
||||||
|
const root = bcashSlp.root
|
||||||
|
|
||||||
|
it('should respond to GET for base route', async () => {
|
||||||
|
const result = root(req, res)
|
||||||
|
|
||||||
|
assert.equal(result.status, 'bcash-slp', 'Returns static string')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#getUtxos', () => {
|
||||||
|
it('should return UTXOs for an address, hydrated with SLP info', async () => {
|
||||||
|
// TODO: Add unit tests.
|
||||||
|
assert.isOk(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
+101
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
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.equal(result.error, 'jwt expired')
|
||||||
|
|
||||||
|
// 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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
+5
-212
@@ -19,7 +19,7 @@ const nock = require('nock') // HTTP mocking
|
|||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
// Local libraries
|
// Local libraries
|
||||||
const Electrumx = require('../../src/routes/v5/electrumx')
|
// const Electrumx = require('../../src/routes/v5/electrumx')
|
||||||
const UtilRoute = require('../../src/routes/v5/util')
|
const UtilRoute = require('../../src/routes/v5/util')
|
||||||
|
|
||||||
let originalEnvVars // Used during transition from integration to unit tests.
|
let originalEnvVars // Used during transition from integration to unit tests.
|
||||||
@@ -38,8 +38,8 @@ const utilRouteInst = new UtilRoute({ electrumx: {} })
|
|||||||
describe('#Util', () => {
|
describe('#Util', () => {
|
||||||
let req, res
|
let req, res
|
||||||
let sandbox
|
let sandbox
|
||||||
let electrumx
|
// let electrumx
|
||||||
let utilRoute
|
// let utilRoute
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// Save existing environment variables.
|
// Save existing environment variables.
|
||||||
@@ -59,7 +59,7 @@ describe('#Util', () => {
|
|||||||
process.env.RPC_PASSWORD = 'fakepassword'
|
process.env.RPC_PASSWORD = 'fakepassword'
|
||||||
}
|
}
|
||||||
|
|
||||||
electrumx = new Electrumx()
|
// electrumx = new Electrumx()
|
||||||
// await electrumx.connect()
|
// await electrumx.connect()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
sandbox = sinon.createSandbox()
|
sandbox = sinon.createSandbox()
|
||||||
|
|
||||||
utilRoute = new UtilRoute({ electrumx })
|
// utilRoute = new UtilRoute({ electrumx })
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -322,211 +322,4 @@ describe('#Util', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#sweepWif', () => {
|
|
||||||
it('should throw 400 if WIF is not included', async () => {
|
|
||||||
req.body = {}
|
|
||||||
|
|
||||||
const result = await utilRouteInst.sweepWif(req, res)
|
|
||||||
|
|
||||||
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
|
|
||||||
assert.include(
|
|
||||||
result.error,
|
|
||||||
'WIF needs to a proper compressed WIF starting with K or L',
|
|
||||||
'Proper error message'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should throw 400 if WIF is malformed', async () => {
|
|
||||||
req.body = {
|
|
||||||
wif: 'abc123'
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRouteInst.sweepWif(req, res)
|
|
||||||
|
|
||||||
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
|
|
||||||
assert.include(
|
|
||||||
result.error,
|
|
||||||
'WIF needs to a proper compressed WIF starting with K or L',
|
|
||||||
'Proper error message'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should throw 400 if destination address is not included', async () => {
|
|
||||||
req.body = {
|
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt'
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRouteInst.sweepWif(req, res)
|
|
||||||
|
|
||||||
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
|
|
||||||
assert.include(
|
|
||||||
result.error,
|
|
||||||
'address can not be empty',
|
|
||||||
'Proper error message'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Unit test only.
|
|
||||||
if (process.env.TEST === 'unit') {
|
|
||||||
it('should generate transaction for valid token sweep', async () => {
|
|
||||||
// Mock the RPC call for unit tests.
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_balanceFromElectrumx')
|
|
||||||
.resolves(mockData.mockBalance)
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_utxosFromElectrumx')
|
|
||||||
.resolves(mockData.mockUtxos)
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.SLP.Utils, 'tokenUtxoDetails')
|
|
||||||
.resolves(mockData.mockIsTokenUtxos)
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
|
||||||
// to the network.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.RawTransactions, 'sendRawTransaction')
|
|
||||||
.resolves('test-txid')
|
|
||||||
|
|
||||||
req.body = {
|
|
||||||
wif: 'L1wAGEN721LHDoiN8pLwwBb87bYrU6Gs21UPcCRR7LjKypQyVaCq',
|
|
||||||
toAddr: 'bitcoincash:qp2g4cnekxsjspccmtvh5k73mczz6273js4mjr353r'
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRoute.sweepWif(req, res)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.equal(result, 'test-txid')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should return balance if balance-only is true', async () => {
|
|
||||||
// Mock the RPC call for unit tests.
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_balanceFromElectrumx')
|
|
||||||
.resolves(mockData.mockBalance)
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
|
||||||
// to the network.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.RawTransactions, 'sendRawTransaction')
|
|
||||||
.resolves('test-txid')
|
|
||||||
|
|
||||||
req.body = {
|
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
|
||||||
balanceOnly: true
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRoute.sweepWif(req, res)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.isNumber(result)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should generate transaction for valid BCH-only sweep', async () => {
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_balanceFromElectrumx')
|
|
||||||
.resolves(mockData.mockBalance)
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_utxosFromElectrumx')
|
|
||||||
.resolves(mockData.mockUtxos)
|
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.SLP.Utils, 'tokenUtxoDetails')
|
|
||||||
.resolves([false, false])
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
|
||||||
// to the network.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.RawTransactions, 'sendRawTransaction')
|
|
||||||
.resolves('test-txid')
|
|
||||||
|
|
||||||
req.body = {
|
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
|
||||||
toAddr: 'bitcoincash:qz2qn6zt4qmacf4r6c0e2pdcqsgnkxaa3ql2xpee6p'
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRoute.sweepWif(req, res)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.equal(result, 'test-txid')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should throw 422 error if no non-token UTXOs', async () => {
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_balanceFromElectrumx')
|
|
||||||
.resolves(mockData.mockBalance)
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_utxosFromElectrumx')
|
|
||||||
.resolves(mockData.mockUtxos)
|
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.SLP.Utils, 'tokenUtxoDetails')
|
|
||||||
.resolves(mockData.tokensOnly)
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
|
||||||
// to the network.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.RawTransactions, 'sendRawTransaction')
|
|
||||||
.resolves('test-txid')
|
|
||||||
|
|
||||||
req.body = {
|
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
|
||||||
toAddr: 'bitcoincash:qz2qn6zt4qmacf4r6c0e2pdcqsgnkxaa3ql2xpee6p'
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRoute.sweepWif(req, res)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.equal(res.statusCode, 422)
|
|
||||||
assert.property(result, 'error')
|
|
||||||
assert.include(
|
|
||||||
result.error,
|
|
||||||
'Tokens found, but no BCH UTXOs found. Add BCH to wallet to move tokens'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should detect and throw error for multiple token classes', async () => {
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_balanceFromElectrumx')
|
|
||||||
.resolves(mockData.mockBalance)
|
|
||||||
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.electrumx, '_utxosFromElectrumx')
|
|
||||||
.resolves(mockData.mockThreeUtxos)
|
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.SLP.Utils, 'tokenUtxoDetails')
|
|
||||||
.resolves(mockData.multipleTokens)
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
|
||||||
// to the network.
|
|
||||||
sandbox
|
|
||||||
.stub(utilRoute.bchjs.RawTransactions, 'sendRawTransaction')
|
|
||||||
.resolves('test-txid')
|
|
||||||
|
|
||||||
req.body = {
|
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
|
||||||
toAddr: 'bitcoincash:qz2qn6zt4qmacf4r6c0e2pdcqsgnkxaa3ql2xpee6p'
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await utilRoute.sweepWif(req, res)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.equal(res.statusCode, 422)
|
|
||||||
assert.property(result, 'error')
|
|
||||||
assert.include(
|
|
||||||
result.error,
|
|
||||||
'Multiple token classes detected. This function only supports a single class of token'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user