mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(Transaction.get()): Handling coinbase txs
This commit is contained in:
@@ -288,6 +288,8 @@ class PsfSlpIndexer {
|
|||||||
*/
|
*/
|
||||||
async tx (txid) {
|
async tx (txid) {
|
||||||
try {
|
try {
|
||||||
|
// console.log('txid: ', txid)
|
||||||
|
|
||||||
// Handle single address.
|
// Handle single address.
|
||||||
if (typeof txid === 'string') {
|
if (typeof txid === 'string') {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
@@ -295,8 +297,11 @@ class PsfSlpIndexer {
|
|||||||
{ txid },
|
{ txid },
|
||||||
this.axiosOptions
|
this.axiosOptions
|
||||||
)
|
)
|
||||||
|
// console.log('response: ', response)
|
||||||
|
|
||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Input txid must be a string.')
|
throw new Error('Input txid must be a string.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.log('error: ', error)
|
// console.log('error: ', error)
|
||||||
@@ -316,6 +321,7 @@ class PsfSlpIndexer {
|
|||||||
|
|
||||||
// Check if this txid belongs to a blacklisted token.
|
// Check if this txid belongs to a blacklisted token.
|
||||||
const isInBlacklist = await this.checkBlacklist(txid)
|
const isInBlacklist = await this.checkBlacklist(txid)
|
||||||
|
// console.log('isInBlacklist: ', isInBlacklist)
|
||||||
|
|
||||||
// Get the TX Details from the full node.
|
// Get the TX Details from the full node.
|
||||||
const txDetails = await this.rawTransaction.getTxData(txid)
|
const txDetails = await this.rawTransaction.getTxData(txid)
|
||||||
|
|||||||
+15
-6
@@ -381,6 +381,8 @@ class RawTransactions {
|
|||||||
// Appends the BCH address to the inputs of the transaction.
|
// Appends the BCH address to the inputs of the transaction.
|
||||||
async getTxData (txid) {
|
async getTxData (txid) {
|
||||||
try {
|
try {
|
||||||
|
// console.log('getTxData() txid: ', txid)
|
||||||
|
|
||||||
if (typeof txid !== 'string') {
|
if (typeof txid !== 'string') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Input to raw-transaction.js/getTxData() must be a string containg a TXID.'
|
'Input to raw-transaction.js/getTxData() must be a string containg a TXID.'
|
||||||
@@ -391,17 +393,24 @@ class RawTransactions {
|
|||||||
const txDetails = await this.getRawTransaction(txid, true)
|
const txDetails = await this.getRawTransaction(txid, true)
|
||||||
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
|
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
|
||||||
|
|
||||||
const inAddrs = await this._getInputAddrs(txDetails)
|
try {
|
||||||
// console.log(`inAddrs: ${JSON.stringify(inAddrs, null, 2)}`)
|
const inAddrs = await this._getInputAddrs(txDetails)
|
||||||
|
// console.log(`inAddrs: ${JSON.stringify(inAddrs, null, 2)}`)
|
||||||
|
|
||||||
// Add the input address to the transaction data.
|
// Add the input address to the transaction data.
|
||||||
for (let i = 0; i < inAddrs.length; i++) {
|
for (let i = 0; i < inAddrs.length; i++) {
|
||||||
txDetails.vin[i].address = inAddrs[i].address
|
txDetails.vin[i].address = inAddrs[i].address
|
||||||
txDetails.vin[i].value = inAddrs[i].value
|
txDetails.vin[i].value = inAddrs[i].value
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Coinbase transactions will throw an error. Just ignore them and
|
||||||
|
// pass back the raw transaction data.
|
||||||
|
/* exit quietly */
|
||||||
}
|
}
|
||||||
|
|
||||||
return txDetails
|
return txDetails
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// console.log('error: ', error)
|
||||||
if (error.error) throw new Error(error.error)
|
if (error.error) throw new Error(error.error)
|
||||||
|
|
||||||
// This case handles rate limit errors.
|
// This case handles rate limit errors.
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class Transaction {
|
|||||||
* })()
|
* })()
|
||||||
*/
|
*/
|
||||||
async get (txid) {
|
async get (txid) {
|
||||||
|
// console.log('transaction.get() txid: ', txid)
|
||||||
return await this.psfSlpIndexer.tx(txid)
|
return await this.psfSlpIndexer.tx(txid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,5 +24,14 @@ describe('#Transaction', () => {
|
|||||||
assert.property(result.txData, 'vout')
|
assert.property(result.txData, 'vout')
|
||||||
assert.equal(result.txData.isValidSlp, false)
|
assert.equal(result.txData.isValidSlp, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should handle a coinbase transaction', async () => {
|
||||||
|
const txid = 'cca1d2dd3a533d2f501448dec03face2cb2814afd59a533a611e9a2909f2302b'
|
||||||
|
|
||||||
|
const details = await bchjs.Transaction.get(txid)
|
||||||
|
// console.log(`details: ${JSON.stringify(details, null, 2)}`)
|
||||||
|
|
||||||
|
assert.property(details.txData, 'txid')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user