@psf/bch-js 6.4.2 → 6.4.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 +2 -2
- package/src/address.js +3 -3
- package/src/electrumx.js +5 -0
- package/src/psf-slp-indexer.js +3 -2
- package/src/utxo.js +5 -2
- package/test/integration/chains/abc/psf-slp-indexer-integration.js +38 -0
- package/test/integration/chains/abc/utxo-integration.js +12 -14
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psf/bch-js",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.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": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test": "nyc mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
|
|
13
13
|
"test:integration": "npm run test:integration:bchn",
|
|
14
14
|
"test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 -g '#nft1' test/integration/chains/bchn/slp.js",
|
|
15
|
-
"test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v5/ &&
|
|
15
|
+
"test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v5/ && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/abc/",
|
|
16
16
|
"test:integration:bchn": "export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
|
|
17
17
|
"test:integration:bchn:slpdb": "export TESTSLP=1 && export RESTURL=https://bchn.fullstack.cash/v5/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
|
|
18
18
|
"test:integration:local:abc": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/",
|
package/src/address.js
CHANGED
|
@@ -166,11 +166,11 @@ class Address {
|
|
|
166
166
|
*
|
|
167
167
|
* @apiExample Example usage:
|
|
168
168
|
* // mainnet
|
|
169
|
-
* bchjs.Address.
|
|
170
|
-
* //
|
|
169
|
+
* bchjs.Address.toEtokenAddress('bitcoincash:qq50d800hgunr8u4trz3uuppspk3mds0dy9978plt2')
|
|
170
|
+
* // etoken:qq50d800hgunr8u4trz3uuppspk3mds0dyug2v69da
|
|
171
171
|
*
|
|
172
172
|
* // mainnet no prefix
|
|
173
|
-
* bchjs.Address.
|
|
173
|
+
* bchjs.Address.toEtokenAddress('bitcoincash:qq50d800hgunr8u4trz3uuppspk3mds0dy9978plt2', false)
|
|
174
174
|
* // qq50d800hgunr8u4trz3uuppspk3mds0dyug2v69da
|
|
175
175
|
*
|
|
176
176
|
*/
|
package/src/electrumx.js
CHANGED
|
@@ -7,6 +7,7 @@ const axios = require('axios')
|
|
|
7
7
|
|
|
8
8
|
// Local libraries.
|
|
9
9
|
const Blockchain = require('./blockchain')
|
|
10
|
+
// const Address = require('./address')
|
|
10
11
|
|
|
11
12
|
// let _this
|
|
12
13
|
|
|
@@ -32,7 +33,9 @@ class ElectrumX {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
// Encapsulate dependencies
|
|
35
37
|
this.blockchain = new Blockchain(config)
|
|
38
|
+
// this.address = new Address(config)
|
|
36
39
|
|
|
37
40
|
// _this = this
|
|
38
41
|
}
|
|
@@ -104,6 +107,8 @@ class ElectrumX {
|
|
|
104
107
|
*/
|
|
105
108
|
async utxo (address) {
|
|
106
109
|
try {
|
|
110
|
+
// console.log(`electrumx.js/utxo() restURL: ${this.restURL}`)
|
|
111
|
+
|
|
107
112
|
// Handle single address.
|
|
108
113
|
if (typeof address === 'string') {
|
|
109
114
|
const response = await axios.get(
|
package/src/psf-slp-indexer.js
CHANGED
|
@@ -194,6 +194,7 @@ class PsfSlpIndexer {
|
|
|
194
194
|
* }
|
|
195
195
|
* }
|
|
196
196
|
*
|
|
197
|
+
*
|
|
197
198
|
*/
|
|
198
199
|
|
|
199
200
|
async tokenStats (tokenId, withTxHistory = false) {
|
|
@@ -420,7 +421,7 @@ class PsfSlpIndexer {
|
|
|
420
421
|
* }
|
|
421
422
|
*
|
|
422
423
|
*/
|
|
423
|
-
async getTokenData (tokenId) {
|
|
424
|
+
async getTokenData (tokenId, withTxHistory = false) {
|
|
424
425
|
try {
|
|
425
426
|
const url = `${this.restURL}psf/slp/token/data`
|
|
426
427
|
// console.log(`url: ${url}`)
|
|
@@ -430,7 +431,7 @@ class PsfSlpIndexer {
|
|
|
430
431
|
const response = await axios.post(
|
|
431
432
|
// 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
|
|
432
433
|
url,
|
|
433
|
-
{ tokenId },
|
|
434
|
+
{ tokenId, withTxHistory },
|
|
434
435
|
this.axiosOptions
|
|
435
436
|
)
|
|
436
437
|
return response.data
|
package/src/utxo.js
CHANGED
|
@@ -82,7 +82,10 @@ class UTXO {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// Ensure the address is a BCH address.
|
|
85
|
-
|
|
85
|
+
let addr = address
|
|
86
|
+
if (!addr.includes('ecash')) {
|
|
87
|
+
addr = this.slp.Address.toCashAddress(address)
|
|
88
|
+
}
|
|
86
89
|
|
|
87
90
|
// Get the UTXOs associated with the address.
|
|
88
91
|
const utxoData = await this.electrumx.utxo(addr)
|
|
@@ -209,7 +212,7 @@ class UTXO {
|
|
|
209
212
|
|
|
210
213
|
return outObj
|
|
211
214
|
} catch (err) {
|
|
212
|
-
console.error('Error in bchjs.Utxo.get()')
|
|
215
|
+
console.error('Error in bchjs.Utxo.get(): ', err)
|
|
213
216
|
|
|
214
217
|
if (err.error) throw new Error(err.error)
|
|
215
218
|
throw err
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Integration tests for the psf-slp-indexer.js library, specific to the eCash
|
|
3
|
+
blockchain.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Global npm libraries
|
|
7
|
+
const assert = require('chai').assert
|
|
8
|
+
|
|
9
|
+
// Local libraries
|
|
10
|
+
const BCHJS = require('../../../../src/bch-js')
|
|
11
|
+
let bchjs
|
|
12
|
+
|
|
13
|
+
describe('#psf-slp-indexer', () => {
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
// Introduce a delay so that the BVT doesn't trip the rate limits.
|
|
16
|
+
if (process.env.IS_USING_FREE_TIER) await sleep(3000)
|
|
17
|
+
|
|
18
|
+
bchjs = new BCHJS()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe('#balance', () => {
|
|
22
|
+
it('should get token balance for an ecash address', async () => {
|
|
23
|
+
const addr = 'ecash:qr5c4hfy52zn87484cucvzle5pljz0gtr5vhtw9z09'
|
|
24
|
+
|
|
25
|
+
const result = await bchjs.PsfSlpIndexer.balance(addr)
|
|
26
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
27
|
+
|
|
28
|
+
assert.property(result.balance, 'utxos')
|
|
29
|
+
assert.property(result.balance, 'txs')
|
|
30
|
+
assert.property(result.balance, 'balances')
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Promise-based sleep function
|
|
36
|
+
function sleep (ms) {
|
|
37
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
38
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Integration tests for the utxo.js library.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const assert = require('chai').assert
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const BCHJS = require('../../../../src/bch-js')
|
|
8
|
+
const bchjs = new BCHJS()
|
|
9
9
|
|
|
10
10
|
describe('#UTXO', () => {
|
|
11
11
|
beforeEach(async () => {
|
|
@@ -14,25 +14,23 @@ describe('#UTXO', () => {
|
|
|
14
14
|
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
/*
|
|
18
17
|
describe('#get', () => {
|
|
19
18
|
it('should get hydrated and filtered UTXOs for an address', async () => {
|
|
20
|
-
|
|
21
|
-
const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
19
|
+
const addr = 'ecash:qr5c4hfy52zn87484cucvzle5pljz0gtr5vhtw9z09'
|
|
20
|
+
// const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
22
21
|
|
|
23
22
|
const result = await bchjs.Utxo.get(addr)
|
|
24
23
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
25
24
|
|
|
26
|
-
assert.isArray(result)
|
|
27
|
-
assert.property(result
|
|
28
|
-
assert.property(result
|
|
29
|
-
assert.property(result
|
|
30
|
-
assert.property(result
|
|
31
|
-
assert.isArray(result
|
|
32
|
-
assert.isArray(result
|
|
25
|
+
// assert.isArray(result)
|
|
26
|
+
assert.property(result, 'address')
|
|
27
|
+
assert.property(result, 'bchUtxos')
|
|
28
|
+
assert.property(result, 'nullUtxos')
|
|
29
|
+
assert.property(result, 'slpUtxos')
|
|
30
|
+
assert.isArray(result.bchUtxos)
|
|
31
|
+
assert.isArray(result.nullUtxos)
|
|
33
32
|
})
|
|
34
33
|
})
|
|
35
|
-
*/
|
|
36
34
|
})
|
|
37
35
|
|
|
38
36
|
function sleep (ms) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Integration tests for the psf-slp-indexer.js library
|
|
2
|
+
Integration tests for the psf-slp-indexer.js library, specific to the BCH
|
|
3
|
+
blockchain.
|
|
3
4
|
*/
|
|
4
5
|
|
|
6
|
+
// Global npm libraries
|
|
5
7
|
const assert = require('chai').assert
|
|
6
8
|
|
|
9
|
+
// Local libraries
|
|
7
10
|
const BCHJS = require('../../../../src/bch-js')
|
|
8
11
|
let bchjs
|
|
9
12
|
|
|
@@ -142,6 +145,15 @@ describe('#psf-slp-indexer', () => {
|
|
|
142
145
|
assert.isString(result.immutableData)
|
|
143
146
|
assert.isString(result.mutableData)
|
|
144
147
|
})
|
|
148
|
+
|
|
149
|
+
it('should get token data with a transaction history', async () => {
|
|
150
|
+
const tokenId = '43eddfb11c9941edffb8c8815574bb0a43969a7b1de39ad14cd043eaa24fd38d'
|
|
151
|
+
|
|
152
|
+
const result = await bchjs.PsfSlpIndexer.getTokenData(tokenId, true)
|
|
153
|
+
// console.log('result: ', result)
|
|
154
|
+
|
|
155
|
+
assert.isArray(result.genesisData.txs)
|
|
156
|
+
})
|
|
145
157
|
})
|
|
146
158
|
})
|
|
147
159
|
|