@psf/bch-js 5.3.1 → 5.4.1
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 +5 -7
- package/src/bch-js.js +0 -2
- package/src/psf-slp-indexer.js +13 -11
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +12 -1
- package/test/integration/chains/bchn/utxo-integration.js +11 -126
- package/src/ipfs.js +0 -454
- package/test/integration/chains/abc/slp.js +0 -226
- package/test/integration/chains/bchn-no-wl-slpdb/rawtransaction.js +0 -71
- package/test/integration/chains/bchn-no-wl-slpdb/slp.js +0 -273
- package/test/integration/chains/bchn-no-wl-slpdb/utxo-integration.js +0 -105
- package/test/unit/ipfs.js +0 -443
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psf/bch-js",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"description": "The FullStack.cash JavaScript library for Bitcoin Cash and SLP Tokens",
|
|
5
5
|
"author": "Chris Troutner <chris.troutner@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -37,13 +37,11 @@
|
|
|
37
37
|
"url": "git+https://github.com/Permissionless-Software-Foundation/bch-js.git"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@psf/bip21": "2.0.1",
|
|
41
40
|
"@chris.troutner/bip32-utils": "1.0.5",
|
|
41
|
+
"@psf/bip21": "2.0.1",
|
|
42
42
|
"@psf/bitcoincash-ops": "2.0.0",
|
|
43
43
|
"@psf/bitcoincashjs-lib": "4.0.2",
|
|
44
44
|
"@psf/coininfo": "4.0.0",
|
|
45
|
-
"@uppy/core": "1.10.4",
|
|
46
|
-
"@uppy/tus": "1.5.12",
|
|
47
45
|
"axios": "^0.21.4",
|
|
48
46
|
"bc-bip68": "1.0.5",
|
|
49
47
|
"bchaddrjs-slp": "0.2.5",
|
|
@@ -65,7 +63,7 @@
|
|
|
65
63
|
"wif": "2.0.6"
|
|
66
64
|
},
|
|
67
65
|
"devDependencies": {
|
|
68
|
-
"apidoc": "0.
|
|
66
|
+
"apidoc": "^0.50.5",
|
|
69
67
|
"assert": "2.0.0",
|
|
70
68
|
"chai": "4.1.2",
|
|
71
69
|
"coveralls": "3.0.2",
|
|
@@ -77,10 +75,10 @@
|
|
|
77
75
|
"eslint-plugin-standard": "4.0.0",
|
|
78
76
|
"husky": "^4.3.8",
|
|
79
77
|
"lodash.clonedeep": "4.5.0",
|
|
80
|
-
"mocha": "9.1
|
|
78
|
+
"mocha": "^9.2.1",
|
|
81
79
|
"node-mocks-http": "1.7.0",
|
|
82
80
|
"nyc": "15.1.0",
|
|
83
|
-
"semantic-release": "
|
|
81
|
+
"semantic-release": "^19.0.2",
|
|
84
82
|
"sinon": "9.2.2",
|
|
85
83
|
"standard": "^16.0.4"
|
|
86
84
|
},
|
package/src/bch-js.js
CHANGED
|
@@ -28,7 +28,6 @@ const Script = require('./script')
|
|
|
28
28
|
const Price = require('./price')
|
|
29
29
|
const Schnorr = require('./schnorr')
|
|
30
30
|
const SLP = require('./slp/slp')
|
|
31
|
-
const IPFS = require('./ipfs')
|
|
32
31
|
const Encryption = require('./encryption')
|
|
33
32
|
const Utxo = require('./utxo')
|
|
34
33
|
const Transaction = require('./transaction')
|
|
@@ -111,7 +110,6 @@ class BCHJS {
|
|
|
111
110
|
this.SLP = new SLP(libConfig)
|
|
112
111
|
this.SLP.HDNode = this.HDNode
|
|
113
112
|
|
|
114
|
-
this.IPFS = new IPFS()
|
|
115
113
|
this.Utxo = new Utxo(libConfig)
|
|
116
114
|
this.Transaction = new Transaction(libConfig)
|
|
117
115
|
|
package/src/psf-slp-indexer.js
CHANGED
|
@@ -41,7 +41,7 @@ class PsfSlpIndexer {
|
|
|
41
41
|
this.rawTransaction = new RawTransaction(config)
|
|
42
42
|
this.slpUtils = new SlpUtils(config)
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
// _this = this
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -53,8 +53,8 @@ class PsfSlpIndexer {
|
|
|
53
53
|
* @apiExample Example usage:
|
|
54
54
|
* (async () => {
|
|
55
55
|
* try {
|
|
56
|
-
* let status = await bchjs.PsfSlpIndexer.status()
|
|
57
|
-
* console.log(status)
|
|
56
|
+
* let status = await bchjs.PsfSlpIndexer.status()
|
|
57
|
+
* console.log(status)
|
|
58
58
|
* } catch(error) {
|
|
59
59
|
* console.error(error)
|
|
60
60
|
* }
|
|
@@ -91,8 +91,8 @@ class PsfSlpIndexer {
|
|
|
91
91
|
* @apiExample Example usage:
|
|
92
92
|
* (async () => {
|
|
93
93
|
* try {
|
|
94
|
-
* let balance = await bchjs.PsfSlpIndexer.balance('bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n')
|
|
95
|
-
* console.log(balance)
|
|
94
|
+
* let balance = await bchjs.PsfSlpIndexer.balance('bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n')
|
|
95
|
+
* console.log(balance)
|
|
96
96
|
* } catch(error) {
|
|
97
97
|
* console.error(error)
|
|
98
98
|
* }
|
|
@@ -155,12 +155,14 @@ class PsfSlpIndexer {
|
|
|
155
155
|
* @apiName Token Stats
|
|
156
156
|
* @apiGroup PSF SLP
|
|
157
157
|
* @apiDescription Return list stats for a single slp token.
|
|
158
|
+
* The second input is a Boolean, which determins the the transaction history
|
|
159
|
+
* of the token is included in the returned data. The default is false.
|
|
158
160
|
*
|
|
159
161
|
* @apiExample Example usage:
|
|
160
162
|
* (async () => {
|
|
161
163
|
* try {
|
|
162
|
-
* let tokenStats = await bchjs.PsfSlpIndexer.tokenStats('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2')
|
|
163
|
-
* console.log(tokenStats)
|
|
164
|
+
* let tokenStats = await bchjs.PsfSlpIndexer.tokenStats('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2', true)
|
|
165
|
+
* console.log(tokenStats)
|
|
164
166
|
* } catch(error) {
|
|
165
167
|
* console.error(error)
|
|
166
168
|
* }
|
|
@@ -194,13 +196,13 @@ class PsfSlpIndexer {
|
|
|
194
196
|
*
|
|
195
197
|
*/
|
|
196
198
|
|
|
197
|
-
async tokenStats (tokenId) {
|
|
199
|
+
async tokenStats (tokenId, withTxHistory = false) {
|
|
198
200
|
try {
|
|
199
201
|
// Handle single address.
|
|
200
202
|
if (typeof tokenId === 'string') {
|
|
201
203
|
const response = await axios.post(
|
|
202
204
|
`${this.restURL}psf/slp/token`,
|
|
203
|
-
{ tokenId },
|
|
205
|
+
{ tokenId, withTxHistory },
|
|
204
206
|
this.axiosOptions
|
|
205
207
|
)
|
|
206
208
|
return response.data
|
|
@@ -221,8 +223,8 @@ class PsfSlpIndexer {
|
|
|
221
223
|
* @apiExample Example usage:
|
|
222
224
|
* (async () => {
|
|
223
225
|
* try {
|
|
224
|
-
* let txData = await bchjs.PsfSlpIndexer.tx('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2')
|
|
225
|
-
* console.log(txData)
|
|
226
|
+
* let txData = await bchjs.PsfSlpIndexer.tx('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2')
|
|
227
|
+
* console.log(txData)
|
|
226
228
|
* } catch(error) {
|
|
227
229
|
* console.error(error)
|
|
228
230
|
* }
|
|
@@ -40,13 +40,24 @@ describe('#psf-slp-indexer', () => {
|
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
describe('#tokenStats', () => {
|
|
43
|
-
it('should get stats on a token', async () => {
|
|
43
|
+
it('should get stats on a token, without tx history', async () => {
|
|
44
44
|
const tokenId =
|
|
45
45
|
'38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0'
|
|
46
46
|
|
|
47
47
|
const result = await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
48
48
|
// console.log('result: ', result)
|
|
49
49
|
|
|
50
|
+
assert.property(result.tokenData, 'documentUri')
|
|
51
|
+
assert.property(result.tokenData, 'totalBurned')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should get stats on a token, with tx history', async () => {
|
|
55
|
+
const tokenId =
|
|
56
|
+
'38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0'
|
|
57
|
+
|
|
58
|
+
const result = await bchjs.PsfSlpIndexer.tokenStats(tokenId, true)
|
|
59
|
+
// console.log('result: ', result)
|
|
60
|
+
|
|
50
61
|
assert.property(result.tokenData, 'documentUri')
|
|
51
62
|
assert.property(result.tokenData, 'txs')
|
|
52
63
|
assert.property(result.tokenData, 'totalBurned')
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
const assert = require('chai').assert
|
|
6
6
|
|
|
7
7
|
const BCHJS = require('../../../../src/bch-js')
|
|
8
|
-
|
|
9
|
-
const bchjs = new BCHJS({ restURL: 'http://192.168.2.129:3000/v5/' })
|
|
8
|
+
const bchjs = new BCHJS()
|
|
9
|
+
// const bchjs = new BCHJS({ restURL: 'http://192.168.2.129:3000/v5/' })
|
|
10
10
|
|
|
11
11
|
describe('#UTXO', () => {
|
|
12
12
|
beforeEach(async () => {
|
|
@@ -15,154 +15,39 @@ describe('#UTXO', () => {
|
|
|
15
15
|
if (process.env.IS_USING_FREE_TIER) await sleep(3000)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
if (process.env.TESTSLP) {
|
|
19
|
-
describe('#getOld', () => {
|
|
20
|
-
it('should get hydrated and filtered UTXOs for an address', async () => {
|
|
21
|
-
// const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
|
|
22
|
-
const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
23
|
-
|
|
24
|
-
const result = await bchjs.Utxo.getOld(addr)
|
|
25
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
26
|
-
|
|
27
|
-
assert.isArray(result)
|
|
28
|
-
assert.property(result[0], 'address')
|
|
29
|
-
assert.property(result[0], 'bchUtxos')
|
|
30
|
-
assert.property(result[0], 'nullUtxos')
|
|
31
|
-
assert.property(result[0], 'slpUtxos')
|
|
32
|
-
assert.isArray(result[0].bchUtxos)
|
|
33
|
-
assert.isArray(result[0].nullUtxos)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should handle an array of addresses', async () => {
|
|
37
|
-
const addr = [
|
|
38
|
-
'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9',
|
|
39
|
-
'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
const result = await bchjs.Utxo.getOld(addr)
|
|
43
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
44
|
-
|
|
45
|
-
assert.isArray(result)
|
|
46
|
-
assert.property(result[0], 'address')
|
|
47
|
-
assert.property(result[0], 'bchUtxos')
|
|
48
|
-
assert.property(result[0], 'nullUtxos')
|
|
49
|
-
assert.property(result[0], 'slpUtxos')
|
|
50
|
-
assert.isArray(result[0].bchUtxos)
|
|
51
|
-
assert.isArray(result[0].nullUtxos)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('should handle NFTs and minting batons', async () => {
|
|
55
|
-
const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj'
|
|
56
|
-
|
|
57
|
-
const result = await bchjs.Utxo.getOld(addr)
|
|
58
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
59
|
-
|
|
60
|
-
assert.isArray(result)
|
|
61
|
-
assert.property(result[0], 'address')
|
|
62
|
-
assert.property(result[0], 'bchUtxos')
|
|
63
|
-
assert.property(result[0], 'nullUtxos')
|
|
64
|
-
assert.property(result[0], 'slpUtxos')
|
|
65
|
-
assert.isArray(result[0].bchUtxos)
|
|
66
|
-
assert.isArray(result[0].nullUtxos)
|
|
67
|
-
|
|
68
|
-
assert.isArray(result[0].slpUtxos.type1.mintBatons)
|
|
69
|
-
assert.isArray(result[0].slpUtxos.type1.tokens)
|
|
70
|
-
assert.isArray(result[0].slpUtxos.nft.groupMintBatons)
|
|
71
|
-
assert.isArray(result[0].slpUtxos.nft.groupTokens)
|
|
72
|
-
assert.isArray(result[0].slpUtxos.nft.tokens)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should use the whitelist when flag is set', async () => {
|
|
76
|
-
const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
77
|
-
const useWhitelist = true
|
|
78
|
-
|
|
79
|
-
const result = await bchjs.Utxo.getOld(addr, useWhitelist)
|
|
80
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
81
|
-
|
|
82
|
-
assert.isArray(result)
|
|
83
|
-
assert.property(result[0], 'address')
|
|
84
|
-
assert.property(result[0], 'bchUtxos')
|
|
85
|
-
assert.property(result[0], 'nullUtxos')
|
|
86
|
-
assert.property(result[0], 'slpUtxos')
|
|
87
|
-
assert.isArray(result[0].bchUtxos)
|
|
88
|
-
assert.isArray(result[0].nullUtxos)
|
|
89
|
-
|
|
90
|
-
// Most token UTXOs should end up in the nullUtxos array.
|
|
91
|
-
assert.isAbove(result[0].bchUtxos.length, 0)
|
|
92
|
-
assert.isAbove(result[0].nullUtxos.length, 1)
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
describe('#findBiggestUtxo', () => {
|
|
97
|
-
it('should sort UTXOs from Electrumx', async () => {
|
|
98
|
-
const addr = 'bitcoincash:qq54fgjn3hz0357n8a6guy4demw9xfkjk5jcj0xr0z'
|
|
99
|
-
|
|
100
|
-
const electrumxUtxos = await bchjs.Electrumx.utxo(addr)
|
|
101
|
-
// console.log(`Electrumx utxos: ${JSON.stringify(electrumxUtxos, null, 2)}`)
|
|
102
|
-
|
|
103
|
-
const result = bchjs.Utxo.findBiggestUtxo(electrumxUtxos.utxos)
|
|
104
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
105
|
-
|
|
106
|
-
assert.property(result, 'satoshis')
|
|
107
|
-
assert.equal(result.satoshis, 800)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('should sort UTXOs from Utxos.get()', async () => {
|
|
111
|
-
const addr = 'bitcoincash:qq54fgjn3hz0357n8a6guy4demw9xfkjk5jcj0xr0z'
|
|
112
|
-
|
|
113
|
-
const utxos = await bchjs.Utxo.getOld(addr)
|
|
114
|
-
// console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
|
115
|
-
|
|
116
|
-
const result = bchjs.Utxo.findBiggestUtxo(utxos[0].bchUtxos)
|
|
117
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
118
|
-
|
|
119
|
-
assert.property(result, 'satoshis')
|
|
120
|
-
assert.equal(result.satoshis, 800)
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
18
|
describe('#hydrateTokenData', () => {
|
|
126
19
|
it('should hydrate token UTXOs', async () => {
|
|
127
20
|
const utxos = [
|
|
128
21
|
{
|
|
129
|
-
txid:
|
|
130
|
-
'384e1b8197e8de7d38f98317af2cf5f6bcb50007c46943b3498a6fab6e8aeb7c',
|
|
22
|
+
txid: '384e1b8197e8de7d38f98317af2cf5f6bcb50007c46943b3498a6fab6e8aeb7c',
|
|
131
23
|
vout: 1,
|
|
132
24
|
type: 'token',
|
|
133
25
|
qty: '10000000',
|
|
134
|
-
tokenId:
|
|
135
|
-
'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37',
|
|
26
|
+
tokenId: 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37',
|
|
136
27
|
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
137
28
|
},
|
|
138
29
|
{
|
|
139
|
-
txid:
|
|
140
|
-
'4fc789405d58ec612c69eba29aa56cf0c7f228349801114138424eb68df4479d',
|
|
30
|
+
txid: '4fc789405d58ec612c69eba29aa56cf0c7f228349801114138424eb68df4479d',
|
|
141
31
|
vout: 1,
|
|
142
32
|
type: 'token',
|
|
143
33
|
qty: '100000000',
|
|
144
|
-
tokenId:
|
|
145
|
-
'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
|
|
34
|
+
tokenId: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
|
|
146
35
|
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
147
36
|
},
|
|
148
37
|
{
|
|
149
|
-
txid:
|
|
150
|
-
'42054bba4d69bfe7801ece0cffc754194b04239034fdfe9dbe321ef76c9a2d93',
|
|
38
|
+
txid: '42054bba4d69bfe7801ece0cffc754194b04239034fdfe9dbe321ef76c9a2d93',
|
|
151
39
|
vout: 5,
|
|
152
40
|
type: 'token',
|
|
153
41
|
qty: '4764',
|
|
154
|
-
tokenId:
|
|
155
|
-
'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
42
|
+
tokenId: 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
156
43
|
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
157
44
|
},
|
|
158
45
|
{
|
|
159
|
-
txid:
|
|
160
|
-
'06938d0a0d15aa76524ffe61fe111d6d2b2ea9dd8dcd4c7c7744614ced370861',
|
|
46
|
+
txid: '06938d0a0d15aa76524ffe61fe111d6d2b2ea9dd8dcd4c7c7744614ced370861',
|
|
161
47
|
vout: 5,
|
|
162
48
|
type: 'token',
|
|
163
49
|
qty: '238',
|
|
164
|
-
tokenId:
|
|
165
|
-
'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
50
|
+
tokenId: 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
166
51
|
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
167
52
|
}
|
|
168
53
|
]
|
|
@@ -226,7 +111,7 @@ describe('#UTXO', () => {
|
|
|
226
111
|
const result = await bchjs.Utxo.get(addr)
|
|
227
112
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
228
113
|
|
|
229
|
-
assert.
|
|
114
|
+
assert.equal(result.nullUtxos.length, 0)
|
|
230
115
|
})
|
|
231
116
|
})
|
|
232
117
|
})
|