mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e793c2a8a9 | ||
|
|
1bf8e59097 | ||
|
|
105ecd6305 | ||
|
|
314040453b | ||
|
|
cbcf5c1d2b | ||
|
|
e881b68ca5 | ||
|
|
f54c69a664 | ||
|
|
319281c096 | ||
|
|
7dee8c0604 | ||
|
|
efbcbc5deb | ||
|
|
c742518612 | ||
|
|
6a0ed46413 | ||
|
|
5ea71bc89b | ||
|
|
84701e90dc | ||
|
|
34ed5ddc4c |
@@ -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.
|
# Allow node.js to make network calls to https using self-signed certificate.
|
||||||
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
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_PORT=6379
|
||||||
export REDIS_HOST=172.17.0.1
|
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.
|
# Allow node.js to make network calls to https using self-signed certificate.
|
||||||
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||||
|
|
||||||
|
# Mainnet Fulcrum / ElectrumX
|
||||||
|
export FULCRUM_URL=172.17.0.1
|
||||||
|
export FULCRUM_PORT=50002
|
||||||
|
|
||||||
# Redis DB
|
# Redis DB
|
||||||
export REDIS_PORT=6380
|
export REDIS_PORT=6380
|
||||||
export REDIS_HOST=172.17.0.1
|
export REDIS_HOST=172.17.0.1
|
||||||
|
|||||||
@@ -79,6 +79,21 @@ class Electrum {
|
|||||||
// Set the connection flag.
|
// Set the connection flag.
|
||||||
_this.isReady = true
|
_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('...Successfully connected to ElectrumX server.')
|
||||||
|
|
||||||
// console.log(`_this.isReady: ${_this.isReady}`)
|
// console.log(`_this.isReady: ${_this.isReady}`)
|
||||||
@@ -96,6 +111,9 @@ class Electrum {
|
|||||||
// Return immediately if the isReady flag is false.
|
// Return immediately if the isReady flag is false.
|
||||||
if (!_this.isReady) return true
|
if (!_this.isReady) return true
|
||||||
|
|
||||||
|
// Disable the reconnect timer.
|
||||||
|
clearInterval(_this.reconnectIntervalHandle)
|
||||||
|
|
||||||
// Disconnect from the server.
|
// Disconnect from the server.
|
||||||
await _this.electrumx.disconnect()
|
await _this.electrumx.disconnect()
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class Price {
|
|||||||
// Request options
|
// Request options
|
||||||
const opt = {
|
const opt = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
baseURL: this.coinexPriceUrl,
|
baseURL: _this.coinexPriceUrl,
|
||||||
timeout: 15000
|
timeout: 15000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-2
@@ -1251,7 +1251,9 @@ class Slp {
|
|||||||
const tokenRes = await _this.axios.request(opt)
|
const tokenRes = await _this.axios.request(opt)
|
||||||
// console.log(`tokenRes: ${util.inspect(tokenRes)}`)
|
// 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)
|
res.status(404)
|
||||||
return res.json({ error: 'TXID not found' })
|
return res.json({ error: 'TXID not found' })
|
||||||
}
|
}
|
||||||
@@ -1437,12 +1439,29 @@ class Slp {
|
|||||||
sendOutputs.push(string.toString())
|
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 = {
|
const obj = {
|
||||||
tokenInfo: {
|
tokenInfo: {
|
||||||
versionType: transaction.slp.detail.versionType,
|
versionType: transaction.slp.detail.versionType,
|
||||||
|
tokenName: transaction.slp.detail.name,
|
||||||
|
tokenTicker: transaction.slp.detail.symbol,
|
||||||
transactionType: transaction.slp.detail.transactionType,
|
transactionType: transaction.slp.detail.transactionType,
|
||||||
tokenIdHex: transaction.slp.detail.tokenIdHex,
|
tokenIdHex: transaction.slp.detail.tokenIdHex,
|
||||||
sendOutputs: sendOutputs
|
sendOutputs: sendOutputs,
|
||||||
|
sendInputsFull: sendInputs,
|
||||||
|
sendOutputsFull: transaction.slp.detail.outputs
|
||||||
},
|
},
|
||||||
tokenIsValid: transaction.slp.valid
|
tokenIsValid: transaction.slp.valid
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function expectRouteError (res, result, expectedError, code = 400) {
|
|||||||
assert.equal(result.success, false)
|
assert.equal(result.success, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('#ElectrumX Router', () => {
|
describe('#Electrumx', () => {
|
||||||
let req, res
|
let req, res
|
||||||
let sandbox
|
let sandbox
|
||||||
const electrumxRoute = new ElecrumxRoute()
|
const electrumxRoute = new ElecrumxRoute()
|
||||||
|
|||||||
@@ -821,6 +821,7 @@ describe('#BlockchainRouter', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getRawMempool()', () => {
|
describe('getRawMempool()', () => {
|
||||||
it('should throw 503 when network issues', async () => {
|
it('should throw 503 when network issues', async () => {
|
||||||
// Save the existing RPC URL.
|
// Save the existing RPC URL.
|
||||||
@@ -842,6 +843,7 @@ describe('#BlockchainRouter', () => {
|
|||||||
'Error message expected'
|
'Error message expected'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns proper error when downstream service stalls', async () => {
|
it('returns proper error when downstream service stalls', async () => {
|
||||||
// Mock the timeout error.
|
// Mock the timeout error.
|
||||||
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
|
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
|
||||||
@@ -856,6 +858,7 @@ describe('#BlockchainRouter', () => {
|
|||||||
'Error message expected'
|
'Error message expected'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns proper error when downstream service is down', async () => {
|
it('returns proper error when downstream service is down', async () => {
|
||||||
// Mock the timeout error.
|
// Mock the timeout error.
|
||||||
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' })
|
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.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
sandbox
|
sandbox
|
||||||
@@ -886,6 +889,7 @@ describe('#BlockchainRouter', () => {
|
|||||||
// Not sure what other assertions should be made here.
|
// Not sure what other assertions should be made here.
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getMempoolEntrySingle()', () => {
|
describe('getMempoolEntrySingle()', () => {
|
||||||
it('should throw 400 if txid is empty', async () => {
|
it('should throw 400 if txid is empty', async () => {
|
||||||
const result = await uut.getMempoolEntrySingle(req, res)
|
const result = await uut.getMempoolEntrySingle(req, res)
|
||||||
|
|||||||
Reference in New Issue
Block a user