mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
feat(txHistory): Renamed transactions endpoint to txHistory
This commit is contained in:
@@ -250,6 +250,7 @@ class BchAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the transaction history for an address.
|
||||
async getTransactions (address, sortOrder = 'DESCENDING', page = 0) {
|
||||
try {
|
||||
console.log('Executing getTransaction() bch adapter')
|
||||
@@ -263,7 +264,7 @@ class BchAdapter {
|
||||
}
|
||||
|
||||
const rpcData = {
|
||||
endpoint: 'transactions',
|
||||
endpoint: 'txHistory',
|
||||
address: address,
|
||||
sortOrder,
|
||||
page
|
||||
|
||||
@@ -271,10 +271,17 @@ class BchRESTControllerLib {
|
||||
|
||||
/**
|
||||
*
|
||||
* @api {post} /bch/transactions Transactions
|
||||
* @apiName Transactions
|
||||
* @api {post} /bch/txHistory TX History
|
||||
* @apiName TX History
|
||||
* @apiGroup REST 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.
|
||||
* - page: (optional) will return a 'page' of 100 results. Default is 0
|
||||
*
|
||||
* Given the 'addresses' property returns an array of objects
|
||||
* with the following properties
|
||||
@@ -289,7 +296,7 @@ class BchRESTControllerLib {
|
||||
* Note: For a single address pass the 'addresses' of string type
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -H "Content-Type: application/json" -X POST -d '{ "addresses": ["bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"] }' localhost:5001/bch/transactions
|
||||
* curl -H "Content-Type: application/json" -X POST -d '{ "address": "bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj" }' localhost:5001/bch/txHistory
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
@@ -317,9 +324,10 @@ class BchRESTControllerLib {
|
||||
* "error": "Unprocessable Entity"
|
||||
* }
|
||||
*/
|
||||
async transactions (ctx) {
|
||||
async txHistory (ctx) {
|
||||
try {
|
||||
console.log('transactions REST API handler called.')
|
||||
console.log(`body: ${JSON.stringify(ctx.request.body, null, 2)}`)
|
||||
|
||||
const addr = ctx.request.body.address
|
||||
const sortOrder = ctx.request.body.sortOrder
|
||||
|
||||
@@ -56,7 +56,7 @@ class BchRouter {
|
||||
this.router.post('/balance', this.postBalance)
|
||||
this.router.post('/utxos', this.postUtxos)
|
||||
this.router.post('/broadcast', this.postBroadcast)
|
||||
this.router.post('/transactions', this.postTransactions)
|
||||
this.router.post('/txHistory', this.postTxHistory)
|
||||
this.router.post('/transaction', this.postTransaction)
|
||||
this.router.post('/pubkey', this.postPubKey)
|
||||
|
||||
@@ -85,9 +85,8 @@ class BchRouter {
|
||||
await _this.bchRESTController.broadcast(ctx, next)
|
||||
}
|
||||
|
||||
async postTransactions (ctx, next) {
|
||||
console.log('Calling _this.bchRESTController.transactions()')
|
||||
await _this.bchRESTController.transactions(ctx, next)
|
||||
async postTxHistory (ctx, next) {
|
||||
await _this.bchRESTController.txHistory(ctx, next)
|
||||
}
|
||||
|
||||
async postTransaction (ctx, next) {
|
||||
|
||||
+93
-93
@@ -28,23 +28,23 @@ describe('#BCH E2E Tests', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#balance', () => {
|
||||
it('should get the balance for an address', async () => {
|
||||
const body = {
|
||||
addresses: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/balance`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.success, true)
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.property(result.data, 'balance')
|
||||
assert.property(result.data.balance, 'confirmed')
|
||||
assert.property(result.data.balance, 'unconfirmed')
|
||||
})
|
||||
})
|
||||
// describe('#balance', () => {
|
||||
// it('should get the balance for an address', async () => {
|
||||
// const body = {
|
||||
// addresses: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/balance`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.success, true)
|
||||
// assert.equal(result.data.status, 200)
|
||||
// assert.property(result.data, 'balance')
|
||||
// assert.property(result.data.balance, 'confirmed')
|
||||
// assert.property(result.data.balance, 'unconfirmed')
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('#utxos', () => {
|
||||
it('should get UTXOs for an address', async () => {
|
||||
@@ -62,68 +62,68 @@ describe('#BCH E2E Tests', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#broadcast', () => {
|
||||
it('should attempt to broadcast a transaction', async () => {
|
||||
const body = {
|
||||
hex: '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
|
||||
}
|
||||
// describe('#broadcast', () => {
|
||||
// it('should attempt to broadcast a transaction', async () => {
|
||||
// const body = {
|
||||
// hex: '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/broadcast`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.status, 422)
|
||||
// assert.equal(result.data.success, false)
|
||||
// assert.equal(result.data.message, 'Missing inputs')
|
||||
// assert.equal(result.data.endpoint, 'broadcast')
|
||||
// })
|
||||
// })
|
||||
//
|
||||
// describe('#pubkey', () => {
|
||||
// it('should return "not found" if pubkey is not on chain', async () => {
|
||||
// const body = {
|
||||
// address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/pubkey`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.success, true)
|
||||
// assert.equal(result.data.status, 200)
|
||||
// assert.equal(result.data.endpoint, 'pubkey')
|
||||
// assert.equal(result.data.pubkey.success, false)
|
||||
// assert.equal(result.data.pubkey.publicKey, 'not found')
|
||||
// })
|
||||
//
|
||||
// it('should get a public key for an address', async () => {
|
||||
// const body = {
|
||||
// address: 'bitcoincash:qznxh6yegf7nfrsd0zeksed4jcqzvg7tzqlcqw3v97'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/pubkey`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.success, true)
|
||||
// assert.equal(result.data.status, 200)
|
||||
// assert.equal(result.data.endpoint, 'pubkey')
|
||||
// assert.equal(result.data.pubkey.success, true)
|
||||
// assert.equal(
|
||||
// result.data.pubkey.publicKey,
|
||||
// '03ebd6d6aae05da1c5905445e3886b30f6a31b26a88de5980de236bd22380fa942'
|
||||
// )
|
||||
// })
|
||||
// })
|
||||
|
||||
const url = `${SERVER}/bch/broadcast`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.status, 422)
|
||||
assert.equal(result.data.success, false)
|
||||
assert.equal(result.data.message, 'Missing inputs')
|
||||
assert.equal(result.data.endpoint, 'broadcast')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#pubkey', () => {
|
||||
it('should return "not found" if pubkey is not on chain', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/pubkey`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.success, true)
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.equal(result.data.endpoint, 'pubkey')
|
||||
assert.equal(result.data.pubkey.success, false)
|
||||
assert.equal(result.data.pubkey.publicKey, 'not found')
|
||||
})
|
||||
|
||||
it('should get a public key for an address', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qznxh6yegf7nfrsd0zeksed4jcqzvg7tzqlcqw3v97'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/pubkey`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.success, true)
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.equal(result.data.endpoint, 'pubkey')
|
||||
assert.equal(result.data.pubkey.success, true)
|
||||
assert.equal(
|
||||
result.data.pubkey.publicKey,
|
||||
'03ebd6d6aae05da1c5905445e3886b30f6a31b26a88de5980de236bd22380fa942'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#transactions', () => {
|
||||
describe('#txHistory', () => {
|
||||
it('should get transaction history for an address, and sort by default in descending order.', async () => {
|
||||
const address = 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v'
|
||||
const body = {
|
||||
address
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const url = `${SERVER}/bch/txHistory`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
@@ -145,7 +145,7 @@ describe('#BCH E2E Tests', () => {
|
||||
sortOrder: 'ASCENDING'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const url = `${SERVER}/bch/txHistory`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
@@ -164,7 +164,7 @@ describe('#BCH E2E Tests', () => {
|
||||
address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const url = `${SERVER}/bch/txHistory`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
@@ -178,7 +178,7 @@ describe('#BCH E2E Tests', () => {
|
||||
page: 1
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const url = `${SERVER}/bch/txHistory`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
@@ -187,22 +187,22 @@ describe('#BCH E2E Tests', () => {
|
||||
})
|
||||
})
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
||||
// 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')
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user