Merge pull request #197 from Permissionless-Software-Foundation/ct-unstable

fix(psf-slp-indexer getAddress): Letting ecash addrs pass through
This commit is contained in:
Chris Troutner
2022-07-10 18:26:46 -07:00
committed by GitHub
3 changed files with 44 additions and 21 deletions
+1 -1
View File
@@ -42,6 +42,6 @@ logs/*
docs/*
docker/mainnet/start-local-mainnet.sh
docker/testnet/start-local-testnet.sh
start-local-bchn.sh
!logs/README.md
+22 -20
View File
@@ -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(
+21
View File
@@ -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 () => {