mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
fix(psf-slp-indexer getAddress): Letting ecash addrs pass through
This commit is contained in:
@@ -97,27 +97,29 @@ class PsfSlpIndexer {
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure the input is a valid BCH address.
|
||||
try {
|
||||
_this.bchjs.SLP.Address.toCashAddress(address)
|
||||
} catch (err) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `Invalid BCH address. Double check your address is valid: ${address}`
|
||||
})
|
||||
}
|
||||
if (!address.includes('ecash')) {
|
||||
// Ensure the input is a valid BCH address.
|
||||
try {
|
||||
_this.bchjs.SLP.Address.toCashAddress(address)
|
||||
} catch (err) {
|
||||
res.status(400)
|
||||
return res.json({
|
||||
success: false,
|
||||
error: `Invalid BCH address. Double check your address is valid: ${address}`
|
||||
})
|
||||
}
|
||||
|
||||
// Prevent a common user error. Ensure they are using the correct network address.
|
||||
const cashAddr = _this.bchjs.SLP.Address.toCashAddress(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.'
|
||||
})
|
||||
// Prevent a common user error. Ensure they are using the correct network address.
|
||||
const cashAddr = _this.bchjs.SLP.Address.toCashAddress(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.'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const response = await _this.axios.post(
|
||||
|
||||
@@ -430,6 +430,27 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.isArray(balance.txs)
|
||||
assert.isArray(balance.balances)
|
||||
})
|
||||
|
||||
it('should GET data for ecash address', async function () {
|
||||
req.body.address =
|
||||
'ecash:qr5c4hfy52zn87484cucvzle5pljz0gtr5vhtw9z09'
|
||||
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
sandbox.stub(uut.axios, 'post').resolves({ data: mockData.balance })
|
||||
} else {
|
||||
return this.skip()
|
||||
}
|
||||
|
||||
const result = await uut.getAddress(req, res)
|
||||
const balance = result.balance
|
||||
assert.property(balance, 'utxos')
|
||||
assert.property(balance, 'txs')
|
||||
assert.property(balance, 'balances')
|
||||
assert.isArray(balance.utxos)
|
||||
assert.isArray(balance.txs)
|
||||
assert.isArray(balance.balances)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getStatus', async () => {
|
||||
|
||||
Reference in New Issue
Block a user