@psf/bch-js 6.4.2 → 6.4.3
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 +1 -1
- package/src/address.js +3 -3
- package/src/electrumx.js +5 -0
- 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 +4 -1
package/package.json
CHANGED
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/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
|
|