@psf/bch-js 7.1.11 → 7.1.12

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": "7.1.11",
3
+ "version": "7.1.12",
4
4
  "type": "module",
5
5
  "description": "A JavaScript library for working with Bitcoin Cash and SLP Tokens",
6
6
  "author": "Chris Troutner <chris.troutner@gmail.com>",
@@ -15,10 +15,11 @@
15
15
  "test:integration": "npm run test:integration:local:noauth",
16
16
  "test:integration:fullstack:free": "export RESTURL=https://bch.fullstack.cash/v6 && mocha --timeout 60000 test/integration/",
17
17
  "test:integration:fullstack:x402": "export RESTURL=https://x402-bch.fullstack.cash/v6 && export BCHJSWIF=L1eYaneXDDXy8VDig4Arwe8wYHbhtsA5wuQvwsKwhaYeneoZuKG4 && mocha --timeout 120000 test/integration/",
18
- "test:integration:local:noauth": "export RESTURL=http://localhost:5942/v6 && mocha --timeout 30000 test/integration/",
18
+ "test:integration:fullstack:auth": "export RESTURL=http://dev.fullstack.cash/v6 && export BCHJSBEARERTOKEN=test01 && mocha --timeout 30000 test/integration/",
19
+ "test:integration:local:noauth": "export RESTURL=http://192.168.1.65:5942/v6 && mocha --timeout 30000 test/integration/",
19
20
  "test:integration:local:auth": "export RESTURL=http://192.168.1.115:5942/v6 && export BCHJSBEARERTOKEN=temp01 && mocha --timeout 30000 test/integration/",
20
21
  "test:integration:local:x402": "export RESTURL=http://localhost:5942/v6 && export BCHJSWIF=L1eYaneXDDXy8VDig4Arwe8wYHbhtsA5wuQvwsKwhaYeneoZuKG4 && mocha --timeout 1200000 test/integration/",
21
- "test:integration:decatur": "export RESTURL=http://192.168.2.127:5942/v6 && mocha --timeout 30000 test/integration/",
22
+ "test:integration:decatur": "export RESTURL=http://192.168.1.65:5942/v6 && mocha --timeout 30000 test/integration/",
22
23
  "coverage": "nyc --reporter=html mocha --timeout 25000 test/unit/",
23
24
  "docs": "./node_modules/.bin/apidoc -i src/ -o docs && ./fix-docs-contrast.sh",
24
25
  "lint": "standard --env mocha --fix"
package/src/blockchain.js CHANGED
@@ -47,8 +47,11 @@ class Blockchain {
47
47
  )
48
48
  return response.data
49
49
  } catch (error) {
50
- if (error.response && error.response.data) throw error.response.data
51
- else throw error
50
+ if (error.response && error.response.data) {
51
+ const errorData = error.response.data
52
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
53
+ throw new Error(errorMessage)
54
+ } else throw error
52
55
  }
53
56
  }
54
57
 
@@ -105,8 +108,11 @@ class Blockchain {
105
108
  )
106
109
  return response.data
107
110
  } catch (error) {
108
- if (error.response && error.response.data) throw error.response.data
109
- else throw error
111
+ if (error.response && error.response.data) {
112
+ const errorData = error.response.data
113
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
114
+ throw new Error(errorMessage)
115
+ } else throw error
110
116
  }
111
117
  }
112
118
 
@@ -155,8 +161,11 @@ class Blockchain {
155
161
  )
156
162
  return response.data
157
163
  } catch (error) {
158
- if (error.response && error.response.data) throw error.response.data
159
- else throw error
164
+ if (error.response && error.response.data) {
165
+ const errorData = error.response.data
166
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
167
+ throw new Error(errorMessage)
168
+ } else throw error
160
169
  }
161
170
  }
162
171
 
@@ -189,8 +198,11 @@ class Blockchain {
189
198
  console.log('Error in bch-js/blockchain.js/getBlockCount()')
190
199
  console.log('blockchain.js restURL: ', this.restURL)
191
200
 
192
- if (error.response && error.response.data) throw error.response.data
193
- else throw error
201
+ if (error.response && error.response.data) {
202
+ const errorData = error.response.data
203
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
204
+ throw new Error(errorMessage)
205
+ } else throw error
194
206
  }
195
207
  }
196
208
 
@@ -222,8 +234,11 @@ class Blockchain {
222
234
  )
223
235
  return response.data
224
236
  } catch (error) {
225
- if (error.response && error.response.data) throw error.response.data
226
- else throw error
237
+ if (error.response && error.response.data) {
238
+ const errorData = error.response.data
239
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
240
+ throw new Error(errorMessage)
241
+ } else throw error
227
242
  }
228
243
  }
229
244
 
@@ -287,8 +302,13 @@ class Blockchain {
287
302
 
288
303
  throw new Error('Input hash must be a string or array of strings.')
289
304
  } catch (error) {
290
- if (error.response && error.response.data) throw error.response.data
291
- else throw error
305
+ // console.log('Error in bch-js/blockchain.js/getBlockHeader() error: ', error)
306
+
307
+ if (error.response && error.response.data) {
308
+ const errorData = error.response.data
309
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
310
+ throw new Error(errorMessage)
311
+ } else throw error
292
312
  }
293
313
  }
294
314
 
@@ -330,8 +350,11 @@ class Blockchain {
330
350
  )
331
351
  return response.data
332
352
  } catch (error) {
333
- if (error.response && error.response.data) throw error.response.data
334
- else throw error
353
+ if (error.response && error.response.data) {
354
+ const errorData = error.response.data
355
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
356
+ throw new Error(errorMessage)
357
+ } else throw error
335
358
  }
336
359
  }
337
360
 
@@ -362,8 +385,11 @@ class Blockchain {
362
385
  )
363
386
  return response.data
364
387
  } catch (error) {
365
- if (error.response && error.response.data) throw error.response.data
366
- else throw error
388
+ if (error.response && error.response.data) {
389
+ const errorData = error.response.data
390
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
391
+ throw new Error(errorMessage)
392
+ } else throw error
367
393
  }
368
394
  }
369
395
 
@@ -378,8 +404,11 @@ class Blockchain {
378
404
  )
379
405
  return response.data
380
406
  } catch (error) {
381
- if (error.response && error.response.data) throw error.response.data
382
- else throw error
407
+ if (error.response && error.response.data) {
408
+ const errorData = error.response.data
409
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
410
+ throw new Error(errorMessage)
411
+ } else throw error
383
412
  }
384
413
  }
385
414
 
@@ -393,8 +422,11 @@ class Blockchain {
393
422
  )
394
423
  return response.data
395
424
  } catch (error) {
396
- if (error.response && error.response.data) throw error.response.data
397
- else throw error
425
+ if (error.response && error.response.data) {
426
+ const errorData = error.response.data
427
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
428
+ throw new Error(errorMessage)
429
+ } else throw error
398
430
  }
399
431
  }
400
432
 
@@ -505,8 +537,11 @@ class Blockchain {
505
537
 
506
538
  throw new Error('Input must be a string or array of strings.')
507
539
  } catch (error) {
508
- if (error.response && error.response.data) throw error.response.data
509
- else throw error
540
+ if (error.response && error.response.data) {
541
+ const errorData = error.response.data
542
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
543
+ throw new Error(errorMessage)
544
+ } else throw error
510
545
  }
511
546
  }
512
547
 
@@ -541,8 +576,11 @@ class Blockchain {
541
576
  )
542
577
  return response.data
543
578
  } catch (error) {
544
- if (error.response && error.response.data) throw error.response.data
545
- else throw error
579
+ if (error.response && error.response.data) {
580
+ const errorData = error.response.data
581
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
582
+ throw new Error(errorMessage)
583
+ } else throw error
546
584
  }
547
585
  }
548
586
 
@@ -588,8 +626,11 @@ class Blockchain {
588
626
  )
589
627
  return response.data
590
628
  } catch (error) {
591
- if (error.response && error.response.data) throw error.response.data
592
- else throw error
629
+ if (error.response && error.response.data) {
630
+ const errorData = error.response.data
631
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
632
+ throw new Error(errorMessage)
633
+ } else throw error
593
634
  }
594
635
  }
595
636
 
@@ -642,8 +683,11 @@ class Blockchain {
642
683
 
643
684
  return response.data
644
685
  } catch (error) {
645
- if (error.response && error.response.data) throw error.response.data
646
- else throw error
686
+ if (error.response && error.response.data) {
687
+ const errorData = error.response.data
688
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
689
+ throw new Error(errorMessage)
690
+ } else throw error
647
691
  }
648
692
  }
649
693
 
@@ -709,8 +753,11 @@ class Blockchain {
709
753
 
710
754
  throw new Error('Input must be a string or array of strings.')
711
755
  } catch (error) {
712
- if (error.response && error.response.data) throw error.response.data
713
- else throw error
756
+ if (error.response && error.response.data) {
757
+ const errorData = error.response.data
758
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
759
+ throw new Error(errorMessage)
760
+ } else throw error
714
761
  }
715
762
  }
716
763
 
@@ -722,8 +769,11 @@ class Blockchain {
722
769
  )
723
770
  return response.data
724
771
  } catch (error) {
725
- if (error.response && error.response.data) throw error.response.data
726
- else throw error
772
+ if (error.response && error.response.data) {
773
+ const errorData = error.response.data
774
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
775
+ throw new Error(errorMessage)
776
+ } else throw error
727
777
  }
728
778
  }
729
779
 
@@ -735,8 +785,11 @@ class Blockchain {
735
785
  )
736
786
  return response.data
737
787
  } catch (error) {
738
- if (error.response && error.response.data) throw error.response.data
739
- else throw error
788
+ if (error.response && error.response.data) {
789
+ const errorData = error.response.data
790
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
791
+ throw new Error(errorMessage)
792
+ } else throw error
740
793
  }
741
794
  }
742
795
 
@@ -748,8 +801,11 @@ class Blockchain {
748
801
  )
749
802
  return response.data
750
803
  } catch (error) {
751
- if (error.response && error.response.data) throw error.response.data
752
- else throw error
804
+ if (error.response && error.response.data) {
805
+ const errorData = error.response.data
806
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
807
+ throw new Error(errorMessage)
808
+ } else throw error
753
809
  }
754
810
  }
755
811
 
@@ -816,8 +872,11 @@ class Blockchain {
816
872
 
817
873
  throw new Error('Input must be a string or array of strings.')
818
874
  } catch (error) {
819
- if (error.response && error.response.data) throw error.response.data
820
- else throw error
875
+ if (error.response && error.response.data) {
876
+ const errorData = error.response.data
877
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
878
+ throw new Error(errorMessage)
879
+ } else throw error
821
880
  }
822
881
  }
823
882
  }
package/src/dsproof.js CHANGED
@@ -62,8 +62,11 @@ class DSProof {
62
62
  )
63
63
  return response.data
64
64
  } catch (error) {
65
- if (error.response && error.response.data) throw error.response.data
66
- else throw error
65
+ if (error.response && error.response.data) {
66
+ const errorData = error.response.data
67
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
68
+ throw new Error(errorMessage)
69
+ } else throw error
67
70
  }
68
71
  }
69
72
  }
package/src/electrumx.js CHANGED
@@ -120,8 +120,11 @@ class ElectrumX {
120
120
 
121
121
  throw new Error('Input address must be a string or array of strings.')
122
122
  } catch (error) {
123
- if (error.response && error.response.data) throw error.response.data
124
- else throw error
123
+ if (error.response && error.response.data) {
124
+ const errorData = error.response.data
125
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
126
+ throw new Error(errorMessage)
127
+ } else throw error
125
128
  }
126
129
  }
127
130
 
@@ -204,8 +207,11 @@ class ElectrumX {
204
207
 
205
208
  throw new Error('Input address must be a string or array of strings.')
206
209
  } catch (error) {
207
- if (error.response && error.response.data) throw error.response.data
208
- else throw error
210
+ if (error.response && error.response.data) {
211
+ const errorData = error.response.data
212
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
213
+ throw new Error(errorMessage)
214
+ } else throw error
209
215
  }
210
216
  }
211
217
 
@@ -305,8 +311,11 @@ class ElectrumX {
305
311
  throw new Error('Input address must be a string or array of strings.')
306
312
  } catch (error) {
307
313
  // console.log('Error in transactions(): ', error)
308
- if (error.response && error.response.data) throw error.response.data
309
- else throw error
314
+ if (error.response && error.response.data) {
315
+ const errorData = error.response.data
316
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
317
+ throw new Error(errorMessage)
318
+ } else throw error
310
319
  }
311
320
  }
312
321
 
@@ -397,8 +406,11 @@ class ElectrumX {
397
406
 
398
407
  throw new Error('Input address must be a string or array of strings.')
399
408
  } catch (error) {
400
- if (error.response && error.response.data) throw error.response.data
401
- else throw error
409
+ if (error.response && error.response.data) {
410
+ const errorData = error.response.data
411
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
412
+ throw new Error(errorMessage)
413
+ } else throw error
402
414
  }
403
415
  }
404
416
 
@@ -453,9 +465,13 @@ class ElectrumX {
453
465
  } catch (error) {
454
466
  // console.log("error: ", error)
455
467
  if (error.response && error.response.data) {
456
- if (error.response && error.response.data) {
457
- throw new Error(error.response.data.error)
458
- } else throw error.response.data
468
+ const errorData = error.response.data
469
+ if (errorData.error) {
470
+ throw new Error(errorData.error)
471
+ } else {
472
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.message || JSON.stringify(errorData))
473
+ throw new Error(errorMessage)
474
+ }
459
475
  } else {
460
476
  throw error
461
477
  }
@@ -555,8 +571,11 @@ class ElectrumX {
555
571
 
556
572
  throw new Error('Input txId must be a string or array of strings.')
557
573
  } catch (error) {
558
- if (error.response && error.response.data) throw error.response.data
559
- else throw error
574
+ if (error.response && error.response.data) {
575
+ const errorData = error.response.data
576
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
577
+ throw new Error(errorMessage)
578
+ } else throw error
560
579
  }
561
580
  }
562
581
 
@@ -595,8 +614,11 @@ class ElectrumX {
595
614
 
596
615
  throw new Error('Input txHex must be a string.')
597
616
  } catch (error) {
598
- if (error.response && error.response.data) throw error.response.data
599
- else throw error
617
+ if (error.response && error.response.data) {
618
+ const errorData = error.response.data
619
+ const errorMessage = typeof errorData === 'string' ? errorData : (errorData.error || errorData.message || JSON.stringify(errorData))
620
+ throw new Error(errorMessage)
621
+ } else throw error
600
622
  }
601
623
  }
602
624
 
@@ -103,8 +103,8 @@ describe('#blockchain', () => {
103
103
  console.log(`result: ${util.inspect(result)}`)
104
104
  assert.equal(true, false, 'Unexpected result!')
105
105
  } catch (err) {
106
- assert.hasAnyKeys(err, ['error'])
107
- assert.include(err.error, 'Array too large')
106
+ assert.instanceOf(err, Error)
107
+ assert.include(err.message, 'Array too large')
108
108
  }
109
109
  })
110
110
  })
@@ -171,8 +171,8 @@ describe('#blockchain', () => {
171
171
  assert.equal(true, false, 'Unexpected result!')
172
172
  } catch (err) {
173
173
  // console.log(`err: ${util.inspect(err)}`)
174
- assert.hasAnyKeys(err, ['error'])
175
- assert.include(err.error, 'Transaction not in mempool')
174
+ assert.instanceOf(err, Error)
175
+ assert.include(err.message, 'Transaction not in mempool')
176
176
  }
177
177
  })
178
178
  })
@@ -241,8 +241,8 @@ describe('#blockchain', () => {
241
241
  console.log(`result: ${util.inspect(result)}`)
242
242
  assert.equal(true, false, 'Unexpected result!')
243
243
  } catch (err) {
244
- assert.hasAnyKeys(err, ['error'])
245
- assert.include(err.error, 'Array too large')
244
+ assert.instanceOf(err, Error)
245
+ assert.include(err.message, 'Array too large')
246
246
  }
247
247
  })
248
248
  })
@@ -73,8 +73,8 @@ describe('#ElectrumX', () => {
73
73
  // console.log(`result: ${util.inspect(result)}`)
74
74
  assert.equal(true, false, 'Unexpected result!')
75
75
  } catch (err) {
76
- assert.hasAnyKeys(err, ['error'])
77
- assert.include(err.error, 'Array too large')
76
+ assert.instanceOf(err, Error)
77
+ assert.include(err.message, 'Array too large')
78
78
  }
79
79
  })
80
80
  })
@@ -129,8 +129,8 @@ describe('#ElectrumX', () => {
129
129
 
130
130
  assert.equal(true, false, 'Unexpected result!')
131
131
  } catch (err) {
132
- assert.hasAnyKeys(err, ['error'])
133
- assert.include(err.error, 'Array too large')
132
+ assert.instanceOf(err, Error)
133
+ assert.include(err.message, 'Array too large')
134
134
  }
135
135
  })
136
136
  })
@@ -187,8 +187,8 @@ describe('#ElectrumX', () => {
187
187
 
188
188
  assert.equal(true, false, 'Unexpected result!')
189
189
  } catch (err) {
190
- assert.hasAnyKeys(err, ['error'])
191
- assert.include(err.error, 'Array too large')
190
+ assert.instanceOf(err, Error)
191
+ assert.include(err.message, 'Array too large')
192
192
  }
193
193
  })
194
194
  })
@@ -250,8 +250,8 @@ describe('#ElectrumX', () => {
250
250
  // console.log(`result: ${util.inspect(result)}`)
251
251
  assert.equal(true, false, 'Unexpected result!')
252
252
  } catch (err) {
253
- assert.hasAnyKeys(err, ['error'])
254
- assert.include(err.error, 'Array too large')
253
+ assert.instanceOf(err, Error)
254
+ assert.include(err.message, 'Array too large')
255
255
  }
256
256
  })
257
257
  })
@@ -345,8 +345,8 @@ describe('#ElectrumX', () => {
345
345
  // console.log(`result: ${util.inspect(result)}`)
346
346
  assert.equal(true, false, 'Unexpected result!')
347
347
  } catch (err) {
348
- assert.hasAnyKeys(err, ['error'])
349
- assert.include(err.error, 'Array too large')
348
+ assert.instanceOf(err, Error)
349
+ assert.include(err.message, 'Array too large')
350
350
  }
351
351
  })
352
352
  })
@@ -359,8 +359,9 @@ describe('#ElectrumX', () => {
359
359
  try {
360
360
  await bchjs.Electrumx.broadcast(txHex)
361
361
  } catch (err) {
362
+ // console.error('err: ', err)
362
363
  assert.include(
363
- err.error,
364
+ err.message,
364
365
  'the transaction was rejected by network rules'
365
366
  )
366
367
  }
@@ -93,7 +93,7 @@ describe('#Blockchain', () => {
93
93
  await bchjs.Blockchain.getBlock(blockhash)
94
94
  assert2.fail('Unexpected result')
95
95
  } catch (err) {
96
- assert2.include(err, 'Test Error')
96
+ assert2.include(err.message, 'Test Error')
97
97
  }
98
98
  })
99
99
  })