Compare commits

...
6 changed files with 110 additions and 7 deletions
+6
View File
@@ -28,6 +28,7 @@ export SLP_API_URL=http://10.0.0.5:5001/
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=172.17.0.1
export FULCRUM_PORT=50002
export FULCRUM_API=http://172.17.0.1:3001/v1/
# Redis DB - Used for rate limiting
export REDIS_PORT=6379
@@ -48,6 +49,9 @@ export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword
# that originate froma domain on the whitelist.
export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash
# Disable rate limits
export DO_NOT_USE_RATE_LIMITS=1
# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON.
# Requests use the ANON rate limit if they fail to pass in a JWT token.
# ANON = 20 requests per minute (RPM)
@@ -61,4 +65,6 @@ export LOG_MAX_SIZE=1m
#5d means store no more than 5 days
export LOG_MAX_FILES=5d
export BCASH_SERVER=http://localhost:3002/
npm start
+11 -5
View File
@@ -17,29 +17,32 @@ export RPC_PASSWORD=password
# SLPDB
export SLPDB_URL=http://172.17.0.1:13300/
export SLPDB_PASS=somelongpassword
export SLPDB_PASS=portlandisacityinoregon
export SLPDB_PASS_GP=portlandisacityinoregon
export SLPDB_PASS_WL=portlandisacityinoregon
# Use the same address as SLPDB_URL if you don't have a separate whitelist server.
export SLPDB_WHITELIST_URL=http://172.17.0.1:13300/
# slp-api alternative SLP validator using slp-validate:
# https://github.com/Permissionless-Software-Foundation/slp-api
export SLP_API_URL=http://10.0.0.5:5001/
export SLP_API_URL=https://slpapi-testnet3.fullstackslp.nl/
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=172.17.0.1
export FULCRUM_PORT=60002
export FULCRUM_API=http://172.17.0.1:3000/v1/
# Redis DB
export REDIS_PORT=6380
export REDIS_HOST=172.17.0.1
# JWT Token Secret
export TOKENSECRET=somelongsecretvalue
export TOKENSECRET=fridayharbor
# So that bch-api can call bch-js locally.
export LOCAL_RESTURL=http://127.0.0.1:3000/v4/
# Basic Authentication password (optional)
export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword
export PRO_PASS=thejaasjhehrakseuhakuhr
# Whitelisted domains. Automatically give pro-tier rate limit access to apps
# that originate froma domain on the whitelist.
@@ -50,6 +53,9 @@ export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash
# ANON = 20 requests per minute (RPM)
export ANON_RATE_LIMIT=50
# 10 = 100 RPM
export WHITELIST_RATE_LIMIT=10
export WHITELIST_RATE_LIMIT=1
export INTERNAL_RATE_LIMIT=100
npm start
+36
View File
@@ -36,6 +36,7 @@ class Price {
this.router.get('/rates', _this.getBCHRate)
this.router.get('/bchausd', _this.getBCHAUSD)
this.router.get('/bchusd', _this.getBCHUSD)
this.router.get('/getcurrencyinfo', this.getCurrencyInfo)
}
// DRY error handler.
@@ -56,6 +57,41 @@ class Price {
return res.json({ status: 'price' })
}
/**
* @api {get} /price/getcurrencyinfo Get information about the currency.
* @apiName getcurrencyinfo
* @apiGroup Price
* @apiDescription Returns an object containing the currency's ticker, satoshisperunit and decimals.
*
*
* @apiExample Example usage:
* curl -X GET "https://api.fullstack.cash/v5/price/getcurrencyinfo" -H "accept: application/json"
*
*
*/
async getCurrencyInfo (req, res, next) {
try {
const {
BitboxHTTP,
// username,
// password,
requestConfig
} = routeUtils.setEnvVars()
requestConfig.data.id = 'getcurrencyinfo'
requestConfig.data.method = 'getcurrencyinfo'
const response = await BitboxHTTP(requestConfig)
return res.json(response.data.result)
} catch (err) {
// Write out error to error log.
wlogger.error('Error in price.js/getCurrencyInfo().', err)
return _this.errorHandler(err, res)
}
}
/**
* @api {get} /price/usd Get the USD price of BCH
* @apiName Get the USD price of BCH
+10 -1
View File
@@ -11,7 +11,7 @@ const assert = require('chai').assert
const util = require('util')
util.inspect.defaultOptions = { depth: 1 }
const Price = require('../../../src/routes/v4/price')
const Price = require('../../../src/routes/v5/price')
const price = new Price()
const { mockReq, mockRes } = require('../mocks/express-mocks')
@@ -50,4 +50,13 @@ describe('#price', () => {
assert.isNumber(result.usd)
})
})
describe('#getCurrencyInfo', () => {
it('should get the full node currency settings', async () => {
const result = await price.getCurrencyInfo(req, res)
console.log(`result: ${util.inspect(result)}`)
assert.isNumber(result.satoshisperunit)
assert.isNumber(result.decimals)
})
})
})
+7
View File
@@ -235,7 +235,14 @@ const mockCoinexFeed = {
message: 'OK'
}
const mockCurrencyInfo = {
ticker: 'BCHA',
satoshisperunit: 100000000,
decimals: 8
}
module.exports = {
mockCoinbaseFeed,
mockCurrencyInfo,
mockCoinexFeed
}
+40 -1
View File
@@ -12,8 +12,9 @@
const chai = require('chai')
const assert = chai.assert
const sinon = require('sinon')
const nock = require('nock') // HTTP mocking
const Price = require('../../src/routes/v5/price')
let uut
// Mocking data.
@@ -31,6 +32,7 @@ describe('#PriceRouter', () => {
before(() => {
// Set default environment variables for unit tests.
if (!process.env.TEST) process.env.TEST = 'unit'
process.env.RPC_BASEURL = 'http://fakenode:fakeport'
})
// Setup the mocks before each test.
@@ -44,12 +46,19 @@ describe('#PriceRouter', () => {
req.body = {}
req.query = {}
// Activate nock if it's inactive.
if (!nock.isActive()) nock.activate()
sandbox = sinon.createSandbox()
uut = new Price()
})
afterEach(() => {
// Clean up HTTP mocks.
nock.cleanAll() // clear interceptor list.
nock.restore()
// Restore Sandbox
sandbox.restore()
})
@@ -343,4 +352,34 @@ describe('#PriceRouter', () => {
assert.isNumber(result.usd)
})
})
describe('#getCurrencyInfo', async () => {
it('should throw 500 when network issues', async () => {
await uut.getCurrencyInfo(req, res)
assert.isAbove(
res.statusCode,
499,
'HTTP status code 500 or greater expected.'
)
// console.log(res)
assert.include(
res.output.error,
'Network error: Could not communicate with full node or other external service'
)
})
it('should get the currency settings of the full node', async () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === 'unit') {
// intercept the RPC_BASEURL parameter
nock(`${process.env.RPC_BASEURL}`)
.post((uri) => uri.includes('/'))
.reply(200, { result: mockData.mockCurrencyInfo })
}
const result = await uut.getCurrencyInfo(req, res)
assert.hasAllKeys(result, ['ticker', 'satoshisperunit', 'decimals'])
})
})
})