mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a85a2a4ef | ||
|
|
443fb233ae | ||
|
|
553d6fd4b0 | ||
|
|
ab98bf05da | ||
|
|
6806b4a197 | ||
|
|
4ae74aed59 | ||
|
|
98e1a5b40f | ||
|
|
279c9b7bea | ||
|
|
56be614980 | ||
|
|
584037ebdd | ||
|
|
44230b73f7 | ||
|
|
b7f1eba6bd | ||
|
|
35bc3025d6 | ||
|
|
6f6531428a |
@@ -1,6 +1,5 @@
|
|||||||
# bch-api
|
# bch-api
|
||||||
|
|
||||||
[](https://greenkeeper.io/)
|
|
||||||
|
|
||||||
[](https://travis-ci.org/christroutner/bch-api)
|
[](https://travis-ci.org/christroutner/bch-api)
|
||||||
|
|
||||||
|
|||||||
@@ -11,5 +11,7 @@ export DATA="{\"ref\":\"$DEPLOY_SECRET\"}"
|
|||||||
|
|
||||||
curl -X POST http://fullstack.cash:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA
|
curl -X POST http://fullstack.cash:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA
|
||||||
curl -X POST http://fullstack.cash:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA
|
curl -X POST http://fullstack.cash:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA
|
||||||
|
curl -X POST http://$FREE_SERVER:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA
|
||||||
|
curl -X POST http://$FREE_SERVER:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA
|
||||||
|
|
||||||
echo "...Finished deploying to production."
|
echo "...Finished deploying to production."
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ USER safeuser
|
|||||||
|
|
||||||
# Clone the repository
|
# Clone the repository
|
||||||
WORKDIR /home/safeuser
|
WORKDIR /home/safeuser
|
||||||
RUN git clone https://github.com/christroutner/bch-api
|
RUN git clone https://github.com/Permissionless-Software-Foundation/bch-api
|
||||||
WORKDIR /home/safeuser/bch-api
|
WORKDIR /home/safeuser/bch-api
|
||||||
RUN npm install
|
RUN npm install --silent
|
||||||
|
|
||||||
# Generate documentation
|
# Generate documentation
|
||||||
RUN npm run docs
|
RUN npm run docs
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ USER safeuser
|
|||||||
|
|
||||||
# Clone the repository
|
# Clone the repository
|
||||||
WORKDIR /home/safeuser
|
WORKDIR /home/safeuser
|
||||||
RUN git clone https://github.com/christroutner/bch-api
|
RUN git clone https://github.com/Permissionless-Software-Foundation/bch-api
|
||||||
WORKDIR /home/safeuser/bch-api
|
WORKDIR /home/safeuser/bch-api
|
||||||
RUN npm install
|
RUN npm install --silent
|
||||||
|
|
||||||
# Generate documentation
|
# Generate documentation
|
||||||
RUN npm run docs
|
RUN npm run docs
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
"test": "npm run lint && npm run test-v3",
|
"test": "npm run lint && npm run test-v3",
|
||||||
"lint": "standard --env mocha --fix",
|
"lint": "standard --env mocha --fix",
|
||||||
"test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/",
|
"test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/",
|
||||||
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/a01-electrumx.js",
|
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/util.js",
|
||||||
"test:integration": "mocha test/v3/integration",
|
"test:integration": "mocha test/v3/integration",
|
||||||
"test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
|
"test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
|
|||||||
@@ -116,13 +116,20 @@ class RateLimits {
|
|||||||
let pointsToConsume = _this.calcPoints(decoded)
|
let pointsToConsume = _this.calcPoints(decoded)
|
||||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||||
|
|
||||||
|
// Retrieve the origin.
|
||||||
|
let origin = req.get('origin')
|
||||||
|
if (origin === undefined && key.indexOf('10.0.0.5') > -1) {
|
||||||
|
origin = 'slp-api'
|
||||||
|
}
|
||||||
|
wlogger.info(`origin: ${origin}`)
|
||||||
|
|
||||||
// If the request originates from one of the approved wallet apps, then
|
// If the request originates from one of the approved wallet apps, then
|
||||||
// apply paid-access rate limits.
|
// apply paid-access rate limits.
|
||||||
const origin = req.get('origin')
|
|
||||||
if (
|
if (
|
||||||
origin &&
|
origin &&
|
||||||
(origin.toString().indexOf('wallet.fullstack.cash') > -1 ||
|
(origin.toString().indexOf('wallet.fullstack.cash') > -1 ||
|
||||||
origin.toString().indexOf('sandbox.fullstack.cash') > -1)
|
origin.toString().indexOf('sandbox.fullstack.cash') > -1 ||
|
||||||
|
origin === 'slp-api')
|
||||||
) {
|
) {
|
||||||
pointsToConsume = 1
|
pointsToConsume = 1
|
||||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||||
|
|||||||
+31
-58
@@ -135,11 +135,12 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
nock(`${process.env.RPC_BASEURL}`)
|
nock(`${process.env.RPC_BASEURL}`)
|
||||||
.post(uri => uri.includes('/'))
|
.post((uri) => uri.includes('/'))
|
||||||
.reply(200, { result: mockData.mockAddress })
|
.reply(200, { result: mockData.mockAddress })
|
||||||
}
|
}
|
||||||
|
|
||||||
req.params.address = 'bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd'
|
req.params.address =
|
||||||
|
'bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd'
|
||||||
|
|
||||||
const result = await validateAddress(req, res)
|
const result = await validateAddress(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
@@ -255,7 +256,7 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
nock(`${process.env.RPC_BASEURL}`)
|
nock(`${process.env.RPC_BASEURL}`)
|
||||||
.post(uri => uri.includes('/'))
|
.post((uri) => uri.includes('/'))
|
||||||
.reply(200, { result: mockData.mockAddress })
|
.reply(200, { result: mockData.mockAddress })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +282,7 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
nock(`${process.env.RPC_BASEURL}`)
|
nock(`${process.env.RPC_BASEURL}`)
|
||||||
.post(uri => uri.includes('/'))
|
.post((uri) => uri.includes('/'))
|
||||||
.times(2)
|
.times(2)
|
||||||
.reply(200, { result: mockData.mockAddress })
|
.reply(200, { result: mockData.mockAddress })
|
||||||
}
|
}
|
||||||
@@ -356,17 +357,11 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockUtxos)
|
.resolves(mockData.mockUtxos)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
@@ -389,51 +384,41 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
assert.equal(result, 'test-txid')
|
assert.equal(result, 'test-txid')
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
it('should return balance if balance-only is true', async () => {
|
it('should return balance if balance-only is true', async () => {
|
||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
}
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
||||||
// to the network.
|
// to the network.
|
||||||
sandbox
|
sandbox
|
||||||
.stub(utilRouteInst.bchjs.RawTransactions, 'sendRawTransaction')
|
.stub(utilRouteInst.bchjs.RawTransactions, 'sendRawTransaction')
|
||||||
.resolves('test-txid')
|
.resolves('test-txid')
|
||||||
|
|
||||||
req.body = {
|
req.body = {
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
||||||
balanceOnly: true
|
balanceOnly: true
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await utilRouteInst.sweepWif(req, res)
|
const result = await utilRouteInst.sweepWif(req, res)
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
|
|
||||||
assert.isNumber(result)
|
assert.isNumber(result)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Unit tests only
|
// Unit tests only
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
it('should generate transaction for valid BCH-only sweep', async () => {
|
it('should generate transaction for valid BCH-only sweep', async () => {
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockUtxos)
|
.resolves(mockData.mockUtxos)
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
// Force token utxo to appear as regular BCH utxo.
|
||||||
@@ -460,17 +445,11 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
it('should throw 422 error if no non-token UTXOs', async () => {
|
it('should throw 422 error if no non-token UTXOs', async () => {
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockUtxos)
|
.resolves(mockData.mockUtxos)
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
// Force token utxo to appear as regular BCH utxo.
|
||||||
@@ -502,17 +481,11 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
it('should detect and throw error for multiple token classes', async () => {
|
it('should detect and throw error for multiple token classes', async () => {
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockThreeUtxos)
|
.resolves(mockData.mockThreeUtxos)
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
// Force token utxo to appear as regular BCH utxo.
|
||||||
|
|||||||
Reference in New Issue
Block a user