@psf/bch-js 6.2.10 → 6.2.13
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 +6 -2
- package/package.json +1 -1
- package/src/slp/nft1.js +1 -1
- package/src/utxo.js +39 -12
- package/test/integration/chains/bchn/utxo-integration.js +17 -8
package/README.md
CHANGED
|
@@ -107,11 +107,15 @@ This open source software is developed and maintained by the [Permissionless Sof
|
|
|
107
107
|
</div>
|
|
108
108
|
|
|
109
109
|
|
|
110
|
-
## IPFS Releases
|
|
110
|
+
## IPFS & Radicle Releases
|
|
111
111
|
|
|
112
112
|
Copies of this repository are also published on [IPFS](https://ipfs.io).
|
|
113
113
|
|
|
114
|
-
-
|
|
114
|
+
- v6.2.10: `bafybeifsioj3ba77u2763nsyuzq53gtbdxsnqpoipvdl4immj6ytznjaoy`
|
|
115
|
+
- (with dependencies, node v14.18.2 and npm v8.8.0): `bafybeihfendd4oj6uxvvecm7sluobwwhpb5wdcxhvhmx56e667nxdncd4a`
|
|
116
|
+
|
|
117
|
+
They are also posted to the Radicle:
|
|
118
|
+
- v6.2.10: `rad:git:hnrkkroqnbfwj6uxpfjuhspoxnfm4i8e6oqwy`
|
|
115
119
|
|
|
116
120
|
## License
|
|
117
121
|
|
package/package.json
CHANGED
package/src/slp/nft1.js
CHANGED
|
@@ -147,7 +147,7 @@ class Nft1 {
|
|
|
147
147
|
// Loop through the tokenUtxos array and find the minting baton.
|
|
148
148
|
let mintBatonUtxo
|
|
149
149
|
for (let i = 0; i < tokenUtxos.length; i++) {
|
|
150
|
-
if (tokenUtxos[i].utxoType === 'minting-baton') {
|
|
150
|
+
if (tokenUtxos[i].utxoType === 'minting-baton' || tokenUtxos[i].type === 'baton') {
|
|
151
151
|
mintBatonUtxo = tokenUtxos[i]
|
|
152
152
|
}
|
|
153
153
|
}
|
package/src/utxo.js
CHANGED
|
@@ -92,7 +92,7 @@ class UTXO {
|
|
|
92
92
|
// Get SLP UTXOs from the psf-slp-indexer
|
|
93
93
|
try {
|
|
94
94
|
const slpUtxoData = await this.psfSlpIndexer.balance(addr)
|
|
95
|
-
|
|
95
|
+
console.log(`slpUtxoData: ${JSON.stringify(slpUtxoData, null, 2)}`)
|
|
96
96
|
|
|
97
97
|
slpUtxos = slpUtxoData.balance.utxos
|
|
98
98
|
} catch (err) {
|
|
@@ -125,6 +125,7 @@ class UTXO {
|
|
|
125
125
|
thisUtxo.qty = thisSlpUtxo.qty
|
|
126
126
|
thisUtxo.tokenId = thisSlpUtxo.tokenId
|
|
127
127
|
thisUtxo.address = thisSlpUtxo.address
|
|
128
|
+
thisUtxo.tokenType = thisSlpUtxo.tokenType
|
|
128
129
|
|
|
129
130
|
break
|
|
130
131
|
}
|
|
@@ -151,19 +152,37 @@ class UTXO {
|
|
|
151
152
|
|
|
152
153
|
// Get token UTXOs
|
|
153
154
|
let type1TokenUtxos = utxos.filter(
|
|
154
|
-
x => x.isSlp === true && x.type === 'token'
|
|
155
|
+
x => x.isSlp === true && x.type === 'token' && x.tokenType === 1
|
|
155
156
|
)
|
|
156
157
|
|
|
157
158
|
// Hydrate the UTXOs with additional token data.
|
|
158
159
|
type1TokenUtxos = await this.hydrateTokenData(type1TokenUtxos)
|
|
159
160
|
|
|
160
|
-
// Collect and hydrate any baton UTXOs
|
|
161
|
+
// Collect and hydrate any type1 baton UTXOs
|
|
161
162
|
const bchUtxos = utxos.filter(x => x.isSlp === false)
|
|
162
163
|
let type1BatonUtxos = utxos.filter(
|
|
163
|
-
x => x.isSlp === true && x.type === 'baton'
|
|
164
|
+
x => x.isSlp === true && x.type === 'baton' && x.tokenType === 1
|
|
164
165
|
)
|
|
165
166
|
type1BatonUtxos = await this.hydrateTokenData(type1BatonUtxos)
|
|
166
167
|
|
|
168
|
+
// Collect and hydrate NFT Group tokens
|
|
169
|
+
let nftGroupTokenUtxos = utxos.filter(
|
|
170
|
+
x => x.isSlp === true && x.type === 'token' && x.tokenType === 129
|
|
171
|
+
)
|
|
172
|
+
nftGroupTokenUtxos = await this.hydrateTokenData(nftGroupTokenUtxos)
|
|
173
|
+
|
|
174
|
+
// Collect and hydrate any Group baton UTXOs
|
|
175
|
+
let groupBatonUtxos = utxos.filter(
|
|
176
|
+
x => x.isSlp === true && x.type === 'baton' && x.tokenType === 129
|
|
177
|
+
)
|
|
178
|
+
groupBatonUtxos = await this.hydrateTokenData(groupBatonUtxos)
|
|
179
|
+
|
|
180
|
+
// Collect and hydrate NFT child tokens
|
|
181
|
+
let nftChildTokenUtxos = utxos.filter(
|
|
182
|
+
x => x.isSlp === true && x.type === 'token' && x.tokenType === 65
|
|
183
|
+
)
|
|
184
|
+
nftChildTokenUtxos = await this.hydrateTokenData(nftChildTokenUtxos)
|
|
185
|
+
|
|
167
186
|
// Isolate any UTXOs that are marked null by the SLP indexer.
|
|
168
187
|
const nullUtxos = utxos.filter(x => x.isSlp === null)
|
|
169
188
|
|
|
@@ -175,7 +194,13 @@ class UTXO {
|
|
|
175
194
|
tokens: type1TokenUtxos,
|
|
176
195
|
mintBatons: type1BatonUtxos
|
|
177
196
|
},
|
|
178
|
-
|
|
197
|
+
group: {
|
|
198
|
+
tokens: nftGroupTokenUtxos,
|
|
199
|
+
mintBatons: groupBatonUtxos
|
|
200
|
+
},
|
|
201
|
+
nft: {
|
|
202
|
+
tokens: nftChildTokenUtxos
|
|
203
|
+
}
|
|
179
204
|
},
|
|
180
205
|
nullUtxos
|
|
181
206
|
}
|
|
@@ -229,14 +254,16 @@ class UTXO {
|
|
|
229
254
|
thisUtxo.documentHash = genData[0].tokenData.documentHash
|
|
230
255
|
thisUtxo.decimals = genData[0].tokenData.decimals
|
|
231
256
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
257
|
+
if (thisUtxo.type !== 'baton') {
|
|
258
|
+
// Calculate the real token quantity
|
|
259
|
+
const qty = new BigNumber(thisUtxo.qty).dividedBy(
|
|
260
|
+
10 ** parseInt(thisUtxo.decimals)
|
|
261
|
+
)
|
|
262
|
+
thisUtxo.qtyStr = qty.toString()
|
|
237
263
|
|
|
238
|
-
|
|
239
|
-
|
|
264
|
+
// tokenQty is property expected by SLP.tokentype1.js library
|
|
265
|
+
thisUtxo.tokenQty = thisUtxo.qtyStr
|
|
266
|
+
}
|
|
240
267
|
}
|
|
241
268
|
|
|
242
269
|
return utxoAry
|
|
@@ -83,13 +83,11 @@ describe('#UTXO', () => {
|
|
|
83
83
|
assert.equal(result.slpUtxos.type1.mintBatons.length, 0)
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
it('should handle minting batons', async () => {
|
|
89
|
-
const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj'
|
|
86
|
+
it('should handle Type1 minting batons', async () => {
|
|
87
|
+
const addr = 'simpleledger:qz5l5yzz9r09hw9aadcz53elp2knx6gyg5qk3s8md7'
|
|
90
88
|
|
|
91
89
|
const result = await bchjs.Utxo.get(addr)
|
|
92
|
-
|
|
90
|
+
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
93
91
|
|
|
94
92
|
// Assert that minting batons are correctly identified.
|
|
95
93
|
assert.isAbove(result.slpUtxos.type1.mintBatons.length, 0)
|
|
@@ -105,13 +103,24 @@ describe('#UTXO', () => {
|
|
|
105
103
|
assert.equal(result.slpUtxos.type1.tokens.length, 0)
|
|
106
104
|
})
|
|
107
105
|
|
|
108
|
-
it('should
|
|
109
|
-
const addr = 'bitcoincash:
|
|
106
|
+
it('should filter Group tokens and mint batons', async () => {
|
|
107
|
+
const addr = 'bitcoincash:qzeqcrpe5fcnslv8rfqjq4gh4gzdwytmdc4qmh0ztv'
|
|
110
108
|
|
|
111
109
|
const result = await bchjs.Utxo.get(addr)
|
|
112
110
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
113
111
|
|
|
114
|
-
assert.
|
|
112
|
+
assert.isAbove(result.slpUtxos.group.tokens.length, 0)
|
|
113
|
+
assert.isAbove(result.slpUtxos.group.mintBatons.length, 0)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('should filter NFTs', async () => {
|
|
117
|
+
const addr = 'simpleledger:qq7vp2kvejsql898a2760kuq6xz00h0a5vuwu9lywu'
|
|
118
|
+
|
|
119
|
+
const result = await bchjs.Utxo.get(addr)
|
|
120
|
+
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
121
|
+
|
|
122
|
+
// assert.isAbove(result.slpUtxos.group.tokens.length, 0)
|
|
123
|
+
// assert.isAbove(result.slpUtxos.group.mintBatons.length, 0)
|
|
115
124
|
})
|
|
116
125
|
})
|
|
117
126
|
})
|