mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a260f7506a | ||
|
|
9684441d92 | ||
|
|
e793c2a8a9 | ||
|
|
1bf8e59097 | ||
|
|
105ecd6305 | ||
|
|
314040453b | ||
|
|
cbcf5c1d2b | ||
|
|
e881b68ca5 | ||
|
|
f54c69a664 | ||
|
|
319281c096 | ||
|
|
7dee8c0604 | ||
|
|
efbcbc5deb | ||
|
|
c742518612 | ||
|
|
6a0ed46413 | ||
|
|
5ea71bc89b |
@@ -17,7 +17,11 @@ export BLOCKBOOK_URL=https://172.17.0.1:9131/
|
||||
# Allow node.js to make network calls to https using self-signed certificate.
|
||||
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||
|
||||
# Redis DB
|
||||
# Mainnet Fulcrum / ElectrumX
|
||||
export FULCRUM_URL=172.17.0.1
|
||||
export FULCRUM_PORT=50002
|
||||
|
||||
# Redis DB - Used for rate limiting
|
||||
export REDIS_PORT=6379
|
||||
export REDIS_HOST=172.17.0.1
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ export BLOCKBOOK_URL=https://172.17.0.1:19131/
|
||||
# Allow node.js to make network calls to https using self-signed certificate.
|
||||
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||
|
||||
# Mainnet Fulcrum / ElectrumX
|
||||
export FULCRUM_URL=172.17.0.1
|
||||
export FULCRUM_PORT=50002
|
||||
|
||||
# Redis DB
|
||||
export REDIS_PORT=6380
|
||||
export REDIS_HOST=172.17.0.1
|
||||
|
||||
@@ -146,10 +146,9 @@ class RateLimits {
|
||||
// apply paid-access rate limits.
|
||||
if (
|
||||
origin &&
|
||||
(origin.toString().indexOf('wallet.fullstack.cash') > -1 ||
|
||||
origin.toString().indexOf('sandbox.fullstack.cash') > -1 ||
|
||||
(origin.toString().indexOf('fullstack.cash') > -1 ||
|
||||
origin.toString().indexOf('splitbch.com') > -1 ||
|
||||
origin === 'slp-api')
|
||||
origin.toString().indexOf('slp-api') > -1)
|
||||
) {
|
||||
pointsToConsume = 10
|
||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||
@@ -159,7 +158,6 @@ class RateLimits {
|
||||
if (
|
||||
// Comment out the line below when running bch-js e2e rate limit tests.
|
||||
key.toString().indexOf('::ffff:127.0.0.1') > -1 ||
|
||||
|
||||
// Do not comment out this line.
|
||||
key.toString().indexOf('172.17.') > -1
|
||||
) {
|
||||
|
||||
@@ -79,6 +79,21 @@ class Electrum {
|
||||
// Set the connection flag.
|
||||
_this.isReady = true
|
||||
|
||||
// Periodically check the connection. If it's not connected, attempt to
|
||||
// reconnect.
|
||||
_this.reconnectIntervalHandle = setInterval(async function () {
|
||||
const status = _this.electrumx.connection.status
|
||||
// console.log(`Electrumx status: ${status}`)
|
||||
|
||||
// 1 = connected. If we're not connected, attemp to reconnect.
|
||||
if (status !== 1) {
|
||||
wlogger.info(`Electrumx not connectes. Status: ${status}`)
|
||||
wlogger.info('Attempting to reconnect...')
|
||||
await _this.electrumx.connect()
|
||||
wlogger.info('...reconnected.')
|
||||
}
|
||||
}, 30000)
|
||||
|
||||
console.log('...Successfully connected to ElectrumX server.')
|
||||
|
||||
// console.log(`_this.isReady: ${_this.isReady}`)
|
||||
@@ -96,6 +111,9 @@ class Electrum {
|
||||
// Return immediately if the isReady flag is false.
|
||||
if (!_this.isReady) return true
|
||||
|
||||
// Disable the reconnect timer.
|
||||
clearInterval(_this.reconnectIntervalHandle)
|
||||
|
||||
// Disconnect from the server.
|
||||
await _this.electrumx.disconnect()
|
||||
|
||||
|
||||
+21
-2
@@ -1251,7 +1251,9 @@ class Slp {
|
||||
const tokenRes = await _this.axios.request(opt)
|
||||
// console.log(`tokenRes: ${util.inspect(tokenRes)}`)
|
||||
|
||||
if (tokenRes.data.c.length === 0) {
|
||||
// Return 'not found' error if both the confirmed and unconfirmed
|
||||
// collections are empty.
|
||||
if (tokenRes.data.c.length === 0 && tokenRes.data.u.length === 0) {
|
||||
res.status(404)
|
||||
return res.json({ error: 'TXID not found' })
|
||||
}
|
||||
@@ -1437,12 +1439,29 @@ class Slp {
|
||||
sendOutputs.push(string.toString())
|
||||
})
|
||||
|
||||
// Because you are not using Insight API indexer, you do not get the
|
||||
// sending addresses from an indexer or from the node.
|
||||
// However, they are available from the SLPDB output.
|
||||
const tokenInputs = transaction.in
|
||||
// Collect the input addresses
|
||||
const sendInputs = []
|
||||
for (let i = 0; i < tokenInputs.length; i += 1) {
|
||||
const tokenInput = tokenInputs[i]
|
||||
const sendInput = {}
|
||||
sendInput.address = tokenInput.e.a
|
||||
sendInputs.push(sendInput)
|
||||
}
|
||||
|
||||
const obj = {
|
||||
tokenInfo: {
|
||||
versionType: transaction.slp.detail.versionType,
|
||||
tokenName: transaction.slp.detail.name,
|
||||
tokenTicker: transaction.slp.detail.symbol,
|
||||
transactionType: transaction.slp.detail.transactionType,
|
||||
tokenIdHex: transaction.slp.detail.tokenIdHex,
|
||||
sendOutputs: sendOutputs
|
||||
sendOutputs: sendOutputs,
|
||||
sendInputsFull: sendInputs,
|
||||
sendOutputsFull: transaction.slp.detail.outputs
|
||||
},
|
||||
tokenIsValid: transaction.slp.valid
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ function expectRouteError (res, result, expectedError, code = 400) {
|
||||
assert.equal(result.success, false)
|
||||
}
|
||||
|
||||
describe('#ElectrumX Router', () => {
|
||||
describe('#Electrumx', () => {
|
||||
let req, res
|
||||
let sandbox
|
||||
const electrumxRoute = new ElecrumxRoute()
|
||||
|
||||
@@ -821,6 +821,7 @@ describe('#BlockchainRouter', () => {
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('getRawMempool()', () => {
|
||||
it('should throw 503 when network issues', async () => {
|
||||
// Save the existing RPC URL.
|
||||
@@ -842,6 +843,7 @@ describe('#BlockchainRouter', () => {
|
||||
'Error message expected'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns proper error when downstream service stalls', async () => {
|
||||
// Mock the timeout error.
|
||||
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
|
||||
@@ -856,6 +858,7 @@ describe('#BlockchainRouter', () => {
|
||||
'Error message expected'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns proper error when downstream service is down', async () => {
|
||||
// Mock the timeout error.
|
||||
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' })
|
||||
@@ -871,7 +874,7 @@ describe('#BlockchainRouter', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should GET /getMempoolInfo', async () => {
|
||||
it('should GET /getRawMempool', async () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
sandbox
|
||||
@@ -886,6 +889,7 @@ describe('#BlockchainRouter', () => {
|
||||
// Not sure what other assertions should be made here.
|
||||
})
|
||||
})
|
||||
|
||||
describe('getMempoolEntrySingle()', () => {
|
||||
it('should throw 400 if txid is empty', async () => {
|
||||
const result = await uut.getMempoolEntrySingle(req, res)
|
||||
|
||||
Reference in New Issue
Block a user