@psf/bch-js 6.2.3 → 6.2.6
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/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@psf/bch-js)
|
|
4
4
|
[](https://npmjs.org/package/@psf/bch-js)
|
|
5
5
|
[](https://github.com/Permissionless-Software-Foundation/bch-js/blob/master/LICENSE.md)
|
|
6
|
-
[](https://github.com/feross/standard)
|
|
6
|
+
[](https://github.com/feross/standard) [](https://gitter.im/Permissionless-Software-Foundation/bch-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
7
7
|
|
|
8
8
|
[bch-js](https://www.npmjs.com/package/@psf/bch-js) is a JavaScript npm library for creating web and mobile apps that can interact with the Bitcoin Cash (BCH) blockchains. It can be used for free, but requires an account on [FullStack.cash](https://fullstack.cash) for increased rate limits. Learn more from [this article](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer) about Full Stack Bitcoin Cash development.
|
|
9
9
|
|
package/package.json
CHANGED
package/src/psf-slp-indexer.js
CHANGED
|
@@ -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)
|
package/src/raw-transactions.js
CHANGED
|
@@ -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
|
-
|
|
395
|
-
|
|
396
|
+
try {
|
|
397
|
+
const inAddrs = await this._getInputAddrs(txDetails)
|
|
398
|
+
// console.log(`inAddrs: ${JSON.stringify(inAddrs, null, 2)}`)
|
|
396
399
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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.
|
package/src/transaction.js
CHANGED
package/src/util.js
CHANGED
|
@@ -281,16 +281,17 @@ class Util {
|
|
|
281
281
|
|
|
282
282
|
// Array of blocks.
|
|
283
283
|
} else if (Array.isArray(address)) {
|
|
284
|
-
const
|
|
284
|
+
const options1 = {
|
|
285
285
|
method: 'POST',
|
|
286
286
|
url: `${this.restURL}util/validateAddress`,
|
|
287
287
|
data: {
|
|
288
288
|
addresses: address
|
|
289
|
-
},
|
|
290
|
-
headers: {
|
|
291
|
-
authorization: `Token ${this.apiToken}`
|
|
292
289
|
}
|
|
290
|
+
// headers: {
|
|
291
|
+
// authorization: `Token ${this.apiToken}`
|
|
292
|
+
// }
|
|
293
293
|
}
|
|
294
|
+
const options = Object.assign({}, options1, this.axiosOptions)
|
|
294
295
|
const response = await axios(options)
|
|
295
296
|
|
|
296
297
|
return response.data
|
|
@@ -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
|
})
|