@psf/bch-js 6.2.11 → 6.2.14
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/slp/nft1.js +1 -1
- package/src/utxo.js +38 -11
- package/test/integration/chains/bchn/utxo-integration.js +15 -7
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
|
@@ -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,10 +83,8 @@ 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)}`)
|
|
@@ -105,13 +103,23 @@ 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.nft.tokens.length, 0)
|
|
115
123
|
})
|
|
116
124
|
})
|
|
117
125
|
})
|