mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-22 01:02:03 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6049c6566f | ||
|
|
99a52ec605 | ||
|
|
33e7bc2b52 | ||
|
|
a20f30ec1e | ||
|
|
b0b12c590c | ||
|
|
286092f2e3 | ||
|
|
5be93afc38 | ||
|
|
63cb107a25 | ||
|
|
c54fb73c7d | ||
|
|
8063c0e922 |
Generated
+7
-8
@@ -14,7 +14,7 @@
|
||||
"bcryptjs": "2.4.3",
|
||||
"glob": "7.1.6",
|
||||
"ipfs": "0.60.0",
|
||||
"ipfs-coord": "6.8.10",
|
||||
"ipfs-coord": "6.8.11",
|
||||
"ipfs-http-client": "55.0.0",
|
||||
"jsonrpc-lite": "2.2.0",
|
||||
"jsonwebtoken": "8.5.1",
|
||||
@@ -10463,10 +10463,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ipfs-coord": {
|
||||
"version": "6.8.10",
|
||||
"resolved": "http://94.130.170.209:4873/ipfs-coord/-/ipfs-coord-6.8.10.tgz",
|
||||
"integrity": "sha512-04nlX4AkfqLuuLzpMcHnpv++iOETLRkzFA2GfAmY90r99HynfHt3DypP6loVdAnD34iWgD+tLhKNQ7QQM7cgfQ==",
|
||||
"license": "MIT",
|
||||
"version": "6.8.11",
|
||||
"resolved": "https://registry.npmjs.org/ipfs-coord/-/ipfs-coord-6.8.11.tgz",
|
||||
"integrity": "sha512-tIfx94leAaz80R8y7nHvzIKrd61RBjWpRUDXLmWNFfhQaopeI+mZcqc63WdjPREv/oX2t/vOmFZ6iI4f3ZJbYQ==",
|
||||
"dependencies": {
|
||||
"axios": "0.21.4",
|
||||
"bch-encrypt-lib": "2.0.0",
|
||||
@@ -33955,9 +33954,9 @@
|
||||
}
|
||||
},
|
||||
"ipfs-coord": {
|
||||
"version": "6.8.10",
|
||||
"resolved": "http://94.130.170.209:4873/ipfs-coord/-/ipfs-coord-6.8.10.tgz",
|
||||
"integrity": "sha512-04nlX4AkfqLuuLzpMcHnpv++iOETLRkzFA2GfAmY90r99HynfHt3DypP6loVdAnD34iWgD+tLhKNQ7QQM7cgfQ==",
|
||||
"version": "6.8.11",
|
||||
"resolved": "https://registry.npmjs.org/ipfs-coord/-/ipfs-coord-6.8.11.tgz",
|
||||
"integrity": "sha512-tIfx94leAaz80R8y7nHvzIKrd61RBjWpRUDXLmWNFfhQaopeI+mZcqc63WdjPREv/oX2t/vOmFZ6iI4f3ZJbYQ==",
|
||||
"requires": {
|
||||
"axios": "0.21.4",
|
||||
"bch-encrypt-lib": "2.0.0",
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
"bcryptjs": "2.4.3",
|
||||
"glob": "7.1.6",
|
||||
"ipfs": "0.60.0",
|
||||
"ipfs-coord": "6.8.10",
|
||||
"ipfs-coord": "6.8.11",
|
||||
"ipfs-http-client": "55.0.0",
|
||||
"jsonrpc-lite": "2.2.0",
|
||||
"jsonwebtoken": "8.5.1",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
COMPOSE_PROJECT_NAME=bch-wallet-service
|
||||
@@ -48,9 +48,9 @@ class BCHRPC {
|
||||
|
||||
// Route the call based on the value of the method property.
|
||||
switch (endpoint) {
|
||||
case 'transactions':
|
||||
case 'txHistory':
|
||||
await this.rateLimit.limiter(rpcData.from)
|
||||
return await this.transactions(rpcData)
|
||||
return await this.txHistory(rpcData)
|
||||
|
||||
case 'balance':
|
||||
await this.rateLimit.limiter(rpcData.from)
|
||||
@@ -64,9 +64,9 @@ class BCHRPC {
|
||||
await this.rateLimit.limiter(rpcData.from)
|
||||
return await this.broadcast(rpcData)
|
||||
|
||||
case 'transaction':
|
||||
case 'txData':
|
||||
await this.rateLimit.limiter(rpcData.from)
|
||||
return await this.transaction(rpcData)
|
||||
return await this.txData(rpcData)
|
||||
|
||||
case 'pubkey':
|
||||
await this.rateLimit.limiter(rpcData.from)
|
||||
@@ -86,11 +86,14 @@ class BCHRPC {
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {JSON} /bch Transactions
|
||||
* @api {JSON} /bch TX History
|
||||
* @apiPermission public
|
||||
* @apiName Transactions
|
||||
* @apiName txHistory
|
||||
* @apiGroup JSON BCH
|
||||
* @apiDescription This endpoint wraps the bchjs.Electrumx.transactions([]) function.
|
||||
* It returns the transaction history for an address. This list of TXIDs is
|
||||
* sorted and paginated.
|
||||
*
|
||||
* There are three possible inputs:
|
||||
* - address: (required) the address to query for a transaction history
|
||||
* - sortOrder: (optional) will sort results in 'DECENDING' (default) or 'ASCENDING' order.
|
||||
@@ -112,7 +115,7 @@ class BCHRPC {
|
||||
* - status: - HTTP Status Code
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "transactions", "addresses": ["bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"], "sortOrder": "DESCENDING", "page": 0}}
|
||||
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "txHistory", "addresses": ["bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"], "sortOrder": "DESCENDING", "page": 0}}
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
@@ -135,7 +138,7 @@ class BCHRPC {
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
async transactions (rpcData) {
|
||||
async txHistory (rpcData) {
|
||||
try {
|
||||
// console.log('transactions rpcData: ', rpcData)
|
||||
|
||||
@@ -154,7 +157,7 @@ class BCHRPC {
|
||||
success: false,
|
||||
status: 422,
|
||||
message: err.message,
|
||||
endpoint: 'transactions'
|
||||
endpoint: 'txHistory'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -425,13 +428,14 @@ class BCHRPC {
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {JSON} /bch Transaction
|
||||
* @api {JSON} /bch Transaction Data
|
||||
* @apiPermission public
|
||||
* @apiName Transaction
|
||||
* @apiName txData
|
||||
* @apiGroup JSON BCH
|
||||
* @apiDescription Get expanded transaction data for an array of transaction
|
||||
* IDs. Each call is limited to 20 TXIDs or less.
|
||||
* Given a transaction the endpoint will return an object with the
|
||||
*
|
||||
* Given a transaction ID, the endpoint will return an object with the
|
||||
* following properties
|
||||
*
|
||||
* - jsonrpc: "" - jsonrpc version
|
||||
@@ -456,7 +460,7 @@ class BCHRPC {
|
||||
* - status: - HTTP Status Code
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "transaction", "txids": ["01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b"]}}
|
||||
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "txData", "txids": ["01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b"]}}
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
@@ -519,7 +523,7 @@ class BCHRPC {
|
||||
* }
|
||||
* }]
|
||||
*/
|
||||
async transaction (rpcData) {
|
||||
async txData (rpcData) {
|
||||
try {
|
||||
const retObj = await this.useCases.bch.getTxData(rpcData)
|
||||
return retObj
|
||||
@@ -532,7 +536,7 @@ class BCHRPC {
|
||||
success: false,
|
||||
status: 422,
|
||||
message: err.message,
|
||||
endpoint: 'transaction'
|
||||
endpoint: 'txData'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,13 @@ class JSONRPC {
|
||||
wlogger.info(
|
||||
`JSON RPC received from ${from}, ID: ${parsedData.payload.id}, type: ${parsedData.type}, method: ${parsedData.payload.method}`
|
||||
)
|
||||
|
||||
// Additional debugging for BCH.
|
||||
if (parsedData.payload.method === 'bch') {
|
||||
wlogger.info(
|
||||
`rpcData.payload: ${JSON.stringify(parsedData.payload, null, 2)}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Added the property "from" to the parsedData object;
|
||||
|
||||
@@ -76,7 +76,7 @@ class BCHUseCases {
|
||||
success: false,
|
||||
status: 422,
|
||||
message: err.message,
|
||||
endpoint: 'transactions'
|
||||
endpoint: 'txHistory'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class BCHUseCases {
|
||||
success: false,
|
||||
status: 422,
|
||||
message: 'Input txids must be an array of transaction IDs.',
|
||||
endpoint: 'transaction'
|
||||
endpoint: 'txData'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class BCHUseCases {
|
||||
success: false,
|
||||
status: 422,
|
||||
message: 'Array input must be 20 elements or less.',
|
||||
endpoint: 'transaction'
|
||||
endpoint: 'txData'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class BCHUseCases {
|
||||
const data = await this.bchjs.Transaction.get(thisTxid.toString())
|
||||
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
|
||||
txData.push(data)
|
||||
txData.push(data.txData)
|
||||
}
|
||||
|
||||
const retObj = {
|
||||
@@ -132,7 +132,7 @@ class BCHUseCases {
|
||||
success: false,
|
||||
status: 422,
|
||||
message: err.message,
|
||||
endpoint: 'transaction'
|
||||
endpoint: 'txData'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,15 +61,15 @@ describe('#BCHRPC', () => {
|
||||
})
|
||||
|
||||
describe('#bchRouter', () => {
|
||||
it('should route to the transactions method', async () => {
|
||||
it('should route to the txHistory method', async () => {
|
||||
// Mock dependencies
|
||||
sandbox.stub(uut, 'transactions').resolves(true)
|
||||
sandbox.stub(uut, 'txHistory').resolves(true)
|
||||
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const txCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transactions'
|
||||
endpoint: 'txHistory'
|
||||
})
|
||||
const jsonStr = JSON.stringify(txCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
@@ -137,15 +137,15 @@ describe('#BCHRPC', () => {
|
||||
assert.equal(result, true)
|
||||
})
|
||||
|
||||
it('should route to the transaction method', async () => {
|
||||
it('should route to the txData method', async () => {
|
||||
// Mock dependencies
|
||||
sandbox.stub(uut, 'transaction').resolves(true)
|
||||
sandbox.stub(uut, 'txData').resolves(true)
|
||||
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const rpcCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transaction'
|
||||
endpoint: 'txData'
|
||||
})
|
||||
const jsonStr = JSON.stringify(rpcCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
@@ -177,13 +177,13 @@ describe('#BCHRPC', () => {
|
||||
|
||||
it('should return 500 status on routing issue', async () => {
|
||||
// Mock dependencies
|
||||
sandbox.stub(uut, 'transactions').rejects(new Error('test error'))
|
||||
sandbox.stub(uut, 'txHistory').rejects(new Error('test error'))
|
||||
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const txCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transactions'
|
||||
endpoint: 'txHistory'
|
||||
})
|
||||
const jsonStr = JSON.stringify(txCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
@@ -194,24 +194,24 @@ describe('#BCHRPC', () => {
|
||||
assert.equal(result.success, false)
|
||||
assert.equal(result.status, 500)
|
||||
assert.equal(result.message, 'test error')
|
||||
assert.equal(result.endpoint, 'transactions')
|
||||
assert.equal(result.endpoint, 'txHistory')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#transactions', () => {
|
||||
describe('#txHistory', () => {
|
||||
it('should return data from bchjs', async () => {
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const txCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transactions',
|
||||
endpoint: 'txHistory',
|
||||
addresses: 'testAddr'
|
||||
})
|
||||
const jsonStr = JSON.stringify(txCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
|
||||
const response = await uut.transactions(rpcData)
|
||||
// console.log('response: ', response)
|
||||
const response = await uut.txHistory(rpcData)
|
||||
console.log('response: ', response)
|
||||
|
||||
assert.equal(response.success, true)
|
||||
assert.equal(response.status, 200)
|
||||
@@ -227,19 +227,19 @@ describe('#BCHRPC', () => {
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const txCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transactions',
|
||||
endpoint: 'txHistory',
|
||||
addresses: 'testAddr'
|
||||
})
|
||||
const jsonStr = JSON.stringify(txCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
|
||||
const response = await uut.transactions(rpcData)
|
||||
const response = await uut.txHistory(rpcData)
|
||||
// console.log('response: ', response)
|
||||
|
||||
assert.equal(response.success, false)
|
||||
assert.equal(response.status, 422)
|
||||
assert.equal(response.message, 'Invalid address')
|
||||
assert.equal(response.endpoint, 'transactions')
|
||||
assert.equal(response.endpoint, 'txHistory')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -387,19 +387,19 @@ describe('#BCHRPC', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#transaction', () => {
|
||||
describe('#txData', () => {
|
||||
it('should route data to the use-case library', async () => {
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const rpcCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transaction',
|
||||
endpoint: 'txData',
|
||||
txid: 'testData'
|
||||
})
|
||||
const jsonStr = JSON.stringify(rpcCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
|
||||
const response = await uut.transaction(rpcData)
|
||||
const response = await uut.txData(rpcData)
|
||||
// console.log('response: ', response)
|
||||
|
||||
assert.equal(response.success, true)
|
||||
@@ -416,19 +416,19 @@ describe('#BCHRPC', () => {
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const rpcCall = jsonrpc.request(id, 'bch', {
|
||||
endpoint: 'transaction',
|
||||
endpoint: 'txData',
|
||||
txid: 'testTxid'
|
||||
})
|
||||
const jsonStr = JSON.stringify(rpcCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
|
||||
const response = await uut.transaction(rpcData)
|
||||
const response = await uut.txData(rpcData)
|
||||
// console.log('response: ', response)
|
||||
|
||||
assert.equal(response.success, false)
|
||||
assert.equal(response.status, 422)
|
||||
assert.equal(response.message, 'Invalid data')
|
||||
assert.equal(response.endpoint, 'transaction')
|
||||
assert.equal(response.endpoint, 'txData')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ describe('#bch-use-case', () => {
|
||||
assert.equal(result.success, false)
|
||||
assert.equal(result.status, 422)
|
||||
assert.equal(result.message, 'Could not query Fulcrum indexer.')
|
||||
assert.equal(result.endpoint, 'transactions')
|
||||
assert.equal(result.endpoint, 'txHistory')
|
||||
})
|
||||
|
||||
it('should return error if there is an error', async () => {
|
||||
@@ -119,7 +119,7 @@ describe('#bch-use-case', () => {
|
||||
assert.equal(result.success, false)
|
||||
assert.equal(result.status, 422)
|
||||
assert.equal(result.message, 'test error')
|
||||
assert.equal(result.endpoint, 'transactions')
|
||||
assert.equal(result.endpoint, 'txHistory')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -159,7 +159,7 @@ describe('#bch-use-case', () => {
|
||||
|
||||
assert.equal(result.success, false)
|
||||
assert.equal(result.status, 422)
|
||||
assert.equal(result.endpoint, 'transaction')
|
||||
assert.equal(result.endpoint, 'txData')
|
||||
assert.equal(
|
||||
result.message,
|
||||
'Input txids must be an array of transaction IDs.'
|
||||
@@ -183,7 +183,7 @@ describe('#bch-use-case', () => {
|
||||
|
||||
assert.equal(result.success, false)
|
||||
assert.equal(result.status, 422)
|
||||
assert.equal(result.endpoint, 'transaction')
|
||||
assert.equal(result.endpoint, 'txData')
|
||||
assert.equal(result.message, 'Array input must be 20 elements or less.')
|
||||
})
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('#bch-use-case', () => {
|
||||
|
||||
assert.equal(result.success, false)
|
||||
assert.equal(result.status, 422)
|
||||
assert.equal(result.endpoint, 'transaction')
|
||||
assert.equal(result.endpoint, 'txData')
|
||||
assert.equal(result.message, 'test error')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user