fix(transaction): Refactored transaction

This commit is contained in:
Chris Troutner
2022-01-28 15:49:54 -08:00
parent 744cf60f90
commit 817b40c489
3 changed files with 53 additions and 46 deletions
+3 -3
View File
@@ -296,7 +296,7 @@ class BchAdapter {
}
}
async getTransaction (txid) {
async getTransaction (txids) {
try {
// Throw an error if this IPFS node has not yet made a connection to a
// wallet service provider.
@@ -308,7 +308,7 @@ class BchAdapter {
const rpcData = {
endpoint: 'transaction',
txid
txids
}
// Generate a UUID for the call.
@@ -317,7 +317,7 @@ class BchAdapter {
// Generate a JSON RPC command.
const cmd = this.jsonrpc.request(rpcId, 'bch', rpcData)
const cmdStr = JSON.stringify(cmd)
// console.log('cmdStr: ', cmdStr)
console.log('cmdStr: ', cmdStr)
// Send the RPC command to selected wallet service.
const thisNode = this.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode
+7 -7
View File
@@ -342,8 +342,8 @@ class BchRESTControllerLib {
* @api {post} /bch/transaction Transaction
* @apiName Transaction
* @apiGroup REST BCH
* @apiDescription Get data about a specific transaction.
* Given a transaction id this endpoint will return an object
* @apiDescription Get data about specific transactions.
* Given an array of transaction IDs this endpoint will return an array of objects
* with the following properties
*
* - txid: "" - Transaction ID
@@ -361,11 +361,11 @@ class BchRESTControllerLib {
* - isValidSLPTx: - Determines if the transaction was under SLP
*
* @apiExample Example usage:
* curl -H "Content-Type: application/json" -X POST -d '{ "txid": "01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b" }' localhost:5001/bch/transaction
* curl -H "Content-Type: application/json" -X POST -d '{ "txids": ["01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b"] }' localhost:5001/bch/transaction
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* [{
* "txid":"01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b",
* "hash":"01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b",
* "version":1,
@@ -414,7 +414,7 @@ class BchRESTControllerLib {
* "time":1568338904,
* "blocktime":1568338904,
* "isValidSLPTx":false
* }
* }]
*
* @apiError UnprocessableEntity Missing required parameters
*
@@ -427,9 +427,9 @@ class BchRESTControllerLib {
*/
async transaction (ctx) {
try {
const txid = ctx.request.body.txid
const txids = ctx.request.body.txids
const data = await this.adapters.bch.getTransaction(txid)
const data = await this.adapters.bch.getTransaction(txids)
// console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
ctx.body = data
+43 -36
View File
@@ -159,43 +159,50 @@ describe('#BCH E2E Tests', () => {
assert.isAbove(result.data.txs[1].height, result.data.txs[0].height)
})
it('should paginate an address with deep tx history', async () => {
const body = {
address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
}
// it('should paginate an address with deep tx history', async () => {
// const body = {
// address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
// }
//
// const url = `${SERVER}/bch/transactions`
// const result = await axios.post(url, body)
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
//
// // Assert there is no more than 100 entries
// assert.isBelow(result.data.txs.length, 101)
// })
const url = `${SERVER}/bch/transactions`
const result = await axios.post(url, body)
console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
// Assert there is no more than 100 entries
assert.isBelow(result.data.txs.length, 101)
})
it('should get the second page of results', async () => {
const body = {
address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d',
page: 1
}
const url = `${SERVER}/bch/transactions`
const result = await axios.post(url, body)
console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
})
// it('should get the second page of results', async () => {
// const body = {
// address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d',
// page: 1
// }
//
// const url = `${SERVER}/bch/transactions`
// const result = await axios.post(url, body)
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
//
// // Assert there is no more than 100 entries
// assert.isBelow(result.data.txs.length, 101)
// })
})
// describe('#transaction', () => {
// it('should get transaction details for a txid', async () => {
// const body = {
// txid: '01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b'
// }
//
// const url = `${SERVER}/bch/transaction`
// const result = await axios.post(url, body)
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
//
// assert.property(result.data, 'txid')
// assert.property(result.data, 'vin')
// })
// })
describe('#transaction', () => {
it('should get transaction details for a txid', async () => {
const body = {
txids: [
'01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b'
]
}
const url = `${SERVER}/bch/transaction`
const result = await axios.post(url, body)
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
assert.equal(result.data.status, 200)
assert.isArray(result.data.txData)
assert.property(result.data.txData[0].txData, 'txid')
assert.property(result.data.txData[0].txData, 'vin')
})
})
})