diff --git a/src/utxo.js b/src/utxo.js index a393372..95abe9c 100644 --- a/src/utxo.js +++ b/src/utxo.js @@ -92,7 +92,7 @@ class UTXO { // Get SLP UTXOs from the psf-slp-indexer try { const slpUtxoData = await this.psfSlpIndexer.balance(addr) - // console.log(`slpUtxoData: ${JSON.stringify(slpUtxoData, null, 2)}`) + console.log(`slpUtxoData: ${JSON.stringify(slpUtxoData, null, 2)}`) slpUtxos = slpUtxoData.balance.utxos } catch (err) { @@ -158,10 +158,10 @@ class UTXO { // Hydrate the UTXOs with additional token data. type1TokenUtxos = await this.hydrateTokenData(type1TokenUtxos) - // Collect and hydrate any baton UTXOs + // Collect and hydrate any type1 baton UTXOs const bchUtxos = utxos.filter(x => x.isSlp === false) let type1BatonUtxos = utxos.filter( - x => x.isSlp === true && x.type === 'baton' + x => x.isSlp === true && x.type === 'baton' && x.tokenType === 1 ) type1BatonUtxos = await this.hydrateTokenData(type1BatonUtxos) @@ -171,6 +171,12 @@ class UTXO { ) nftGroupTokenUtxos = await this.hydrateTokenData(nftGroupTokenUtxos) + // Collect and hydrate any Group baton UTXOs + let groupBatonUtxos = utxos.filter( + x => x.isSlp === true && x.type === 'baton' && x.tokenType === 129 + ) + groupBatonUtxos = await this.hydrateTokenData(groupBatonUtxos) + // Collect and hydrate NFT child tokens let nftChildTokenUtxos = utxos.filter( x => x.isSlp === true && x.type === 'token' && x.tokenType === 65 @@ -190,12 +196,11 @@ class UTXO { }, group: { tokens: nftGroupTokenUtxos, - mintBatons: [] + mintBatons: groupBatonUtxos }, nft: { - tokens: nftChildTokenUtxos, - mintBatons: [] - } // Allocated for future support of NFT spec. + tokens: nftChildTokenUtxos + } }, nullUtxos } @@ -249,14 +254,16 @@ class UTXO { thisUtxo.documentHash = genData[0].tokenData.documentHash thisUtxo.decimals = genData[0].tokenData.decimals - // Calculate the real token quantity - const qty = new BigNumber(thisUtxo.qty).dividedBy( - 10 ** parseInt(thisUtxo.decimals) - ) - thisUtxo.qtyStr = qty.toString() + if (thisUtxo.type !== 'baton') { + // Calculate the real token quantity + const qty = new BigNumber(thisUtxo.qty).dividedBy( + 10 ** parseInt(thisUtxo.decimals) + ) + thisUtxo.qtyStr = qty.toString() - // tokenQty is property expected by SLP.tokentype1.js library - thisUtxo.tokenQty = thisUtxo.qtyStr + // tokenQty is property expected by SLP.tokentype1.js library + thisUtxo.tokenQty = thisUtxo.qtyStr + } } return utxoAry diff --git a/test/integration/chains/bchn/utxo-integration.js b/test/integration/chains/bchn/utxo-integration.js index ca77910..d4121bf 100644 --- a/test/integration/chains/bchn/utxo-integration.js +++ b/test/integration/chains/bchn/utxo-integration.js @@ -83,13 +83,11 @@ describe('#UTXO', () => { assert.equal(result.slpUtxos.type1.mintBatons.length, 0) }) - // TODO: NFTs are currently not identified as different than normal BCH UTXOs. - // The psf-slp-indexer needs to be updated to fix this issue. - it('should handle minting batons', async () => { - const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj' + it('should handle Type1 minting batons', async () => { + const addr = 'simpleledger:qz5l5yzz9r09hw9aadcz53elp2knx6gyg5qk3s8md7' const result = await bchjs.Utxo.get(addr) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) + console.log(`result: ${JSON.stringify(result, null, 2)}`) // Assert that minting batons are correctly identified. assert.isAbove(result.slpUtxos.type1.mintBatons.length, 0) @@ -105,15 +103,25 @@ describe('#UTXO', () => { assert.equal(result.slpUtxos.type1.tokens.length, 0) }) - it('should filter Group NFTs', async () => { - const addr = 'bitcoincash:qrnghwrfgccf3s5e9wnglzxegcnhje9rkcwv2eka33' + it('should filter Group tokens and mint batons', async () => { + const addr = 'bitcoincash:qzeqcrpe5fcnslv8rfqjq4gh4gzdwytmdc4qmh0ztv' const result = await bchjs.Utxo.get(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.equal(result.slpUtxos.group.tokens.length, 1) - // assert.equal(result.slpUtxos.) + assert.isAbove(result.slpUtxos.group.tokens.length, 0) + assert.isAbove(result.slpUtxos.group.mintBatons.length, 0) }) + + // it('should filter NFTs', async () => { + // const addr = 'bitcoincash:qq7vp2kvejsql898a2760kuq6xz00h0a5vs4h72ysz' + // + // const result = await bchjs.Utxo.get(addr) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + // + // // assert.isAbove(result.slpUtxos.group.tokens.length, 0) + // // assert.isAbove(result.slpUtxos.group.mintBatons.length, 0) + // }) }) })