From 88ae47cadeb9cb62567dac6da4b253e060644ecf Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 4 May 2022 17:44:53 -0700 Subject: [PATCH 1/4] fix(Utxo.get()): Adding prototype NFT filtering --- src/utxo.js | 24 +++++++++++++++++-- .../chains/bchn/utxo-integration.js | 5 ++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/utxo.js b/src/utxo.js index f873407..a393372 100644 --- a/src/utxo.js +++ b/src/utxo.js @@ -125,6 +125,7 @@ class UTXO { thisUtxo.qty = thisSlpUtxo.qty thisUtxo.tokenId = thisSlpUtxo.tokenId thisUtxo.address = thisSlpUtxo.address + thisUtxo.tokenType = thisSlpUtxo.tokenType break } @@ -151,7 +152,7 @@ class UTXO { // Get token UTXOs let type1TokenUtxos = utxos.filter( - x => x.isSlp === true && x.type === 'token' + x => x.isSlp === true && x.type === 'token' && x.tokenType === 1 ) // Hydrate the UTXOs with additional token data. @@ -164,6 +165,18 @@ class UTXO { ) type1BatonUtxos = await this.hydrateTokenData(type1BatonUtxos) + // Collect and hydrate NFT Group tokens + let nftGroupTokenUtxos = utxos.filter( + x => x.isSlp === true && x.type === 'token' && x.tokenType === 129 + ) + nftGroupTokenUtxos = await this.hydrateTokenData(nftGroupTokenUtxos) + + // Collect and hydrate NFT child tokens + let nftChildTokenUtxos = utxos.filter( + x => x.isSlp === true && x.type === 'token' && x.tokenType === 65 + ) + nftChildTokenUtxos = await this.hydrateTokenData(nftChildTokenUtxos) + // Isolate any UTXOs that are marked null by the SLP indexer. const nullUtxos = utxos.filter(x => x.isSlp === null) @@ -175,7 +188,14 @@ class UTXO { tokens: type1TokenUtxos, mintBatons: type1BatonUtxos }, - nft: {} // Allocated for future support of NFT spec. + group: { + tokens: nftGroupTokenUtxos, + mintBatons: [] + }, + nft: { + tokens: nftChildTokenUtxos, + mintBatons: [] + } // Allocated for future support of NFT spec. }, nullUtxos } diff --git a/test/integration/chains/bchn/utxo-integration.js b/test/integration/chains/bchn/utxo-integration.js index 883619d..ca77910 100644 --- a/test/integration/chains/bchn/utxo-integration.js +++ b/test/integration/chains/bchn/utxo-integration.js @@ -105,13 +105,14 @@ describe('#UTXO', () => { assert.equal(result.slpUtxos.type1.tokens.length, 0) }) - it('should handle Group NFTs', async () => { + it('should filter Group NFTs', async () => { const addr = 'bitcoincash:qrnghwrfgccf3s5e9wnglzxegcnhje9rkcwv2eka33' const result = await bchjs.Utxo.get(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.equal(result.nullUtxos.length, 0) + assert.equal(result.slpUtxos.group.tokens.length, 1) + // assert.equal(result.slpUtxos.) }) }) }) From 0504cf7b8d2598d90d5a2d104995c1973bd0a15f Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 5 May 2022 10:03:35 -0700 Subject: [PATCH 2/4] fix(Utxo.get()): Adding filtering for Group batons --- src/utxo.js | 35 +++++++++++-------- .../chains/bchn/utxo-integration.js | 26 +++++++++----- 2 files changed, 38 insertions(+), 23 deletions(-) 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) + // }) }) }) From 59e92adf0bf44210e9da2acdd7a517c14f492469 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 5 May 2022 10:43:40 -0700 Subject: [PATCH 3/4] fix(mintNFTGroupOpReturn()): Updating to use UTXOs from psf-slp-indexer --- src/slp/nft1.js | 2 +- .../chains/bchn/utxo-integration.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/slp/nft1.js b/src/slp/nft1.js index 1f52f9f..a41f1c6 100644 --- a/src/slp/nft1.js +++ b/src/slp/nft1.js @@ -147,7 +147,7 @@ class Nft1 { // Loop through the tokenUtxos array and find the minting baton. let mintBatonUtxo for (let i = 0; i < tokenUtxos.length; i++) { - if (tokenUtxos[i].utxoType === 'minting-baton') { + if (tokenUtxos[i].utxoType === 'minting-baton' || tokenUtxos[i].type === 'baton') { mintBatonUtxo = tokenUtxos[i] } } diff --git a/test/integration/chains/bchn/utxo-integration.js b/test/integration/chains/bchn/utxo-integration.js index d4121bf..3754b72 100644 --- a/test/integration/chains/bchn/utxo-integration.js +++ b/test/integration/chains/bchn/utxo-integration.js @@ -113,15 +113,15 @@ describe('#UTXO', () => { 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) - // }) + it('should filter NFTs', async () => { + const addr = 'simpleledger:qq7vp2kvejsql898a2760kuq6xz00h0a5vuwu9lywu' + + 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) + }) }) }) From 416e302ca53379aeae96146eac7ccd0a14a67e4e Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 5 May 2022 12:06:59 -0700 Subject: [PATCH 4/4] fix(Utxo.get()): Added additional integration tests --- src/utxo.js | 2 +- test/integration/chains/bchn/utxo-integration.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utxo.js b/src/utxo.js index 95abe9c..a92acdb 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) { diff --git a/test/integration/chains/bchn/utxo-integration.js b/test/integration/chains/bchn/utxo-integration.js index 3754b72..9bca943 100644 --- a/test/integration/chains/bchn/utxo-integration.js +++ b/test/integration/chains/bchn/utxo-integration.js @@ -87,7 +87,7 @@ describe('#UTXO', () => { 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) @@ -117,10 +117,9 @@ describe('#UTXO', () => { const addr = 'simpleledger:qq7vp2kvejsql898a2760kuq6xz00h0a5vuwu9lywu' const result = await bchjs.Utxo.get(addr) - console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // assert.isAbove(result.slpUtxos.group.tokens.length, 0) - // assert.isAbove(result.slpUtxos.group.mintBatons.length, 0) + assert.isAbove(result.slpUtxos.nft.tokens.length, 0) }) }) })