diff --git a/src/utxo.js b/src/utxo.js index 8bc61f1..bd95a43 100644 --- a/src/utxo.js +++ b/src/utxo.js @@ -404,8 +404,18 @@ class UTXO { if (!thisUtxo.isSlp) { thisUtxo.txid = thisUtxo.tx_hash thisUtxo.vout = thisUtxo.tx_pos - thisUtxo.isSlp = false thisUtxo.address = addr + + // Check the transaction to see if its a 'null' token, ignored by + // the indexer. + const txData = await this.psfSlpIndexer.tx(thisUtxo.tx_hash) + // console.log(`txData: ${JSON.stringify(txData, null, 2)}`) + if (txData.txData.isValidSlp === null) { + thisUtxo.isSlp = null + } else { + thisUtxo.isSlp = false + } + // console.log(`thisUtxo.isSlp: ${thisUtxo.isSlp}`) } } @@ -438,7 +448,7 @@ class UTXO { return outObj } catch (err) { - // console.error('Error in bchjs.utxo.get2(): ', err) + console.error('Error in bchjs.Utxo.get(): ', err) if (err.error) throw new Error(err.error) throw err diff --git a/test/integration/chains/bchn/utxo-integration.js b/test/integration/chains/bchn/utxo-integration.js index 9089900..8df4c74 100644 --- a/test/integration/chains/bchn/utxo-integration.js +++ b/test/integration/chains/bchn/utxo-integration.js @@ -5,7 +5,8 @@ const assert = require('chai').assert const BCHJS = require('../../../../src/bch-js') -const bchjs = new BCHJS() +// const bchjs = new BCHJS() +const bchjs = new BCHJS({ restURL: 'http://192.168.2.129:3000/v5/' }) describe('#UTXO', () => { beforeEach(async () => { @@ -199,7 +200,7 @@ describe('#UTXO', () => { // 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 NFTs and minting batons', async () => { + it('should handle minting batons', async () => { const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj' const result = await bchjs.Utxo.get(addr) @@ -218,6 +219,15 @@ describe('#UTXO', () => { assert.isAbove(result.bchUtxos.length, 0) assert.equal(result.slpUtxos.type1.tokens.length, 0) }) + + it('should handle Group NFTs', async () => { + const addr = 'bitcoincash:qrnghwrfgccf3s5e9wnglzxegcnhje9rkcwv2eka33' + + const result = await bchjs.Utxo.get(addr) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.isAbove(result.nullUtxos.length, 0) + }) }) }) diff --git a/test/unit/utxo-unit.js b/test/unit/utxo-unit.js index 52ef883..8c9f4d6 100644 --- a/test/unit/utxo-unit.js +++ b/test/unit/utxo-unit.js @@ -249,6 +249,10 @@ describe('#utxo', () => { sandbox .stub(bchjs.Utxo.psfSlpIndexer, 'balance') .resolves(mockData.psfSlpIndexerUtxos01) + sandbox + .stub(bchjs.Utxo.psfSlpIndexer, 'tx') + .resolves({ txData: { isValidSlp: false } }) + // Mock function to return the same input. Good enough for this test. sandbox.stub(bchjs.Utxo, 'hydrateTokenData').resolves(x => x) @@ -278,6 +282,9 @@ describe('#utxo', () => { sandbox .stub(bchjs.Utxo.electrumx, 'utxo') .resolves(mockData.fulcrumUtxos02) + sandbox + .stub(bchjs.Utxo.psfSlpIndexer, 'tx') + .resolves({ txData: { isValidSlp: false } }) // Force psf-slp-indexer to return no UTXOs sandbox