@psf/bch-js 6.2.4 → 6.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psf/bch-js",
3
- "version": "6.2.4",
3
+ "version": "6.2.5",
4
4
  "description": "A JavaScript library for working with Bitcoin Cash, eCash, and SLP Tokens",
5
5
  "author": "Chris Troutner <chris.troutner@gmail.com>",
6
6
  "contributors": [
@@ -288,6 +288,8 @@ class PsfSlpIndexer {
288
288
  */
289
289
  async tx (txid) {
290
290
  try {
291
+ // console.log('txid: ', txid)
292
+
291
293
  // Handle single address.
292
294
  if (typeof txid === 'string') {
293
295
  const response = await axios.post(
@@ -295,8 +297,11 @@ class PsfSlpIndexer {
295
297
  { txid },
296
298
  this.axiosOptions
297
299
  )
300
+ // console.log('response: ', response)
301
+
298
302
  return response.data
299
303
  }
304
+
300
305
  throw new Error('Input txid must be a string.')
301
306
  } catch (error) {
302
307
  // console.log('error: ', error)
@@ -316,6 +321,7 @@ class PsfSlpIndexer {
316
321
 
317
322
  // Check if this txid belongs to a blacklisted token.
318
323
  const isInBlacklist = await this.checkBlacklist(txid)
324
+ // console.log('isInBlacklist: ', isInBlacklist)
319
325
 
320
326
  // Get the TX Details from the full node.
321
327
  const txDetails = await this.rawTransaction.getTxData(txid)
@@ -381,6 +381,8 @@ class RawTransactions {
381
381
  // Appends the BCH address to the inputs of the transaction.
382
382
  async getTxData (txid) {
383
383
  try {
384
+ // console.log('getTxData() txid: ', txid)
385
+
384
386
  if (typeof txid !== 'string') {
385
387
  throw new Error(
386
388
  'Input to raw-transaction.js/getTxData() must be a string containg a TXID.'
@@ -391,17 +393,24 @@ class RawTransactions {
391
393
  const txDetails = await this.getRawTransaction(txid, true)
392
394
  // console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
393
395
 
394
- const inAddrs = await this._getInputAddrs(txDetails)
395
- // console.log(`inAddrs: ${JSON.stringify(inAddrs, null, 2)}`)
396
+ try {
397
+ const inAddrs = await this._getInputAddrs(txDetails)
398
+ // console.log(`inAddrs: ${JSON.stringify(inAddrs, null, 2)}`)
396
399
 
397
- // Add the input address to the transaction data.
398
- for (let i = 0; i < inAddrs.length; i++) {
399
- txDetails.vin[i].address = inAddrs[i].address
400
- txDetails.vin[i].value = inAddrs[i].value
400
+ // Add the input address to the transaction data.
401
+ for (let i = 0; i < inAddrs.length; i++) {
402
+ txDetails.vin[i].address = inAddrs[i].address
403
+ txDetails.vin[i].value = inAddrs[i].value
404
+ }
405
+ } catch (err) {
406
+ // Coinbase transactions will throw an error. Just ignore them and
407
+ // pass back the raw transaction data.
408
+ /* exit quietly */
401
409
  }
402
410
 
403
411
  return txDetails
404
412
  } catch (error) {
413
+ // console.log('error: ', error)
405
414
  if (error.error) throw new Error(error.error)
406
415
 
407
416
  // This case handles rate limit errors.
@@ -41,6 +41,7 @@ class Transaction {
41
41
  * })()
42
42
  */
43
43
  async get (txid) {
44
+ // console.log('transaction.get() txid: ', txid)
44
45
  return await this.psfSlpIndexer.tx(txid)
45
46
  }
46
47
 
@@ -24,5 +24,14 @@ describe('#Transaction', () => {
24
24
  assert.property(result.txData, 'vout')
25
25
  assert.equal(result.txData.isValidSlp, false)
26
26
  })
27
+
28
+ it('should handle a coinbase transaction', async () => {
29
+ const txid = 'cca1d2dd3a533d2f501448dec03face2cb2814afd59a533a611e9a2909f2302b'
30
+
31
+ const details = await bchjs.Transaction.get(txid)
32
+ // console.log(`details: ${JSON.stringify(details, null, 2)}`)
33
+
34
+ assert.property(details.txData, 'txid')
35
+ })
27
36
  })
28
37
  })