diff --git a/package-lock.json b/package-lock.json index ce172b8..ed027ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9952,11 +9952,6 @@ "node": ">=8" } }, - "node_modules/npm/node_modules/stringify-package": { - "version": "1.0.1", - "dev": true, - "license": "ISC" - }, "node_modules/npm/node_modules/strip-ansi": { "version": "6.0.1", "dev": true, @@ -21288,10 +21283,6 @@ "strip-ansi": "^6.0.1" } }, - "stringify-package": { - "version": "1.0.1", - "dev": true - }, "strip-ansi": { "version": "6.0.1", "bundled": true, diff --git a/src/price.js b/src/price.js index c571132..d8ef010 100644 --- a/src/price.js +++ b/src/price.js @@ -30,19 +30,19 @@ class Price { } // This endpoint is deprecated. Documentation removed. - async current (currency = 'usd') { - try { - const response = await this.axios.get( - `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}` - ) - // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) - - return response.data.price - } catch (err) { - if (err.response && err.response.data) throw err.response.data - else throw err - } - } + // async current (currency = 'usd') { + // try { + // const response = await this.axios.get( + // `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}` + // ) + // // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) + // + // return response.data.price + // } catch (err) { + // if (err.response && err.response.data) throw err.response.data + // else throw err + // } + // } /** * @api price.getUsd() getUsd() diff --git a/src/psf-slp-indexer.js b/src/psf-slp-indexer.js index 2e9f803..0130a22 100644 --- a/src/psf-slp-indexer.js +++ b/src/psf-slp-indexer.js @@ -442,6 +442,89 @@ class PsfSlpIndexer { else throw error } } + + /** + * @api PsfSlpIndexer.getTokenData2() getTokenData2() + * @apiName Token Data + * @apiGroup PSF SLP + * @apiDescription Get token icon and other media associated with a token. + * + * @apiExample Example usage: + * (async () => { + * try { + * let tokenData = await bchjs.PsfSlpIndexer.getTokenData2('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2') + * console.log(tokenData) + * } catch(error) { + * console.error(error) + * } + * })() + * + * { + * tokenStats: { + * type: 1, + * ticker: 'CTAIA006', + * name: 'CTAIA006 - AI Art by Chris Troutner', + * tokenId: '0e4543f820699294ab57e02ee2b1815a8bbc7b17a4333e4a138034e4b2324a61', + * documentUri: 'ipfs://bafybeia5yuq7rg6jmwquako7t277cwrobcunz7cumqrv4wn6bgfvthemku', + * documentHash: '78a00e9db312b8fff4e5c37cf592be83e6bab7f3bd5a54c9545bad5d4f3ee0f5', + * decimals: 0, + * mintBatonIsActive: false, + * tokensInCirculationBN: '1', + * tokensInCirculationStr: '1', + * blockCreated: 757507, + * totalBurned: '0', + * totalMinted: '1' + * }, + * mutableData: { + * tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png', + * fullSizedUrl: '', + * about: 'This NFT was created using the PSF Token Studio at https://nft-creator.fullstack.cash', + * userData: '' + * }, + * immutableData: { + * issuer: 'http://psfoundation.cash', + * website: 'https://nft-creator.fullstack.cash', + * dateCreated: '9/12/2022, 5:17:38 PM', + * userData: '{\n' + + * ' "title": "CTAIA006 - AI Art by Chris Troutner",\n' + + * ' "about": "AI generated art. Generated from DALL-E at https://labs.openai.com",\n' + + * ' "prompt": "whale swimming through a sky full of stars",\n' + + * ' "algorithm": "DALL-E (stable diffusion)",\n' + + * ' "set": "1-of-2"\n' + + * '}' + * }, + * tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png', + * fullSizedUrl: '', + * optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm/whale-night-sky-01.png', + * optimizedFullSizedUrl: '', + * iconRepoCompatible: false, + * ps002Compatible: true + * } + * + */ + async getTokenData2 (tokenId) { + try { + const url = `${this.restURL}psf/slp/token/data2` + // console.log(`url: ${url}`) + + // Handle single address. + if (typeof tokenId === 'string') { + const response = await axios.post( + // 'https://bchn.fullstack.cash/v5/psf/slp/token/data/', + url, + { tokenId }, + this.axiosOptions + ) + return response.data + } + + throw new Error('Input tokenId must be a string.') + } catch (error) { + console.log('error: ', error) + if (error.response && error.response.data) throw error.response.data + else throw error + } + } } module.exports = PsfSlpIndexer diff --git a/test/integration/chains/bchn/psf-slp-indexer.integration.js b/test/integration/chains/bchn/psf-slp-indexer.integration.js index 11d0a38..d36ed37 100644 --- a/test/integration/chains/bchn/psf-slp-indexer.integration.js +++ b/test/integration/chains/bchn/psf-slp-indexer.integration.js @@ -155,6 +155,27 @@ describe('#psf-slp-indexer', () => { assert.isArray(result.genesisData.txs) }) }) + + describe('#getTokenData2', () => { + it('should get token data', async () => { + const tokenId = + 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b' + + // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/' + const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId) + console.log('result: ', result) + + assert.property(result, 'tokenStats') + assert.property(result, 'mutableData') + assert.property(result, 'immutableData') + assert.property(result, 'tokenIcon') + assert.property(result, 'fullSizedUrl') + assert.property(result, 'optimizedTokenIcon') + assert.property(result, 'optimizedFullSizedUrl') + assert.property(result, 'iconRepoCompatible') + assert.property(result, 'ps002Compatible') + }) + }) }) // Promise-based sleep function diff --git a/test/integration/price.js b/test/integration/price.js index 17b4e85..d535232 100644 --- a/test/integration/price.js +++ b/test/integration/price.js @@ -7,14 +7,14 @@ describe('#price', () => { if (process.env.IS_USING_FREE_TIER) await sleep(1500) }) - describe('#current', () => { - describe('#single currency', () => { - it('should get current price for single currency', async () => { - const result = await bchjs.Price.current('usd') - assert.notEqual(0, result) - }) - }) - }) + // describe('#current', () => { + // describe('#single currency', () => { + // it('should get current price for single currency', async () => { + // const result = await bchjs.Price.current('usd') + // assert.notEqual(0, result) + // }) + // }) + // }) describe('#getUsd', () => { it('should get the USD price of BCH', async () => { @@ -33,6 +33,7 @@ describe('#price', () => { assert.isNumber(result) }) }) + describe('#getBchUsd', () => { it('should get the USD price of BCH', async () => { const result = await bchjs.Price.getBchUsd() diff --git a/test/unit/fixtures/psf-slp-indexer-mock.js b/test/unit/fixtures/psf-slp-indexer-mock.js index cb41535..84b0920 100644 --- a/test/unit/fixtures/psf-slp-indexer-mock.js +++ b/test/unit/fixtures/psf-slp-indexer-mock.js @@ -150,11 +150,65 @@ const tokenData = { mutableData: 'ipfs://bafybeie6t5uyupddc7azms737xg4hxrj7i5t5ov3lb5g2qeehaujj6ak64' } +const tokenMedia01 = { + tokenStats: { + type: 65, + ticker: 'TEST02', + name: 'How to Send BCH and Tokens', + tokenId: 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b', + documentUri: 'ipfs://bafybeigjujbb55wqr5lns7z7vleg5cfp4yjwqp4swisxpgxl4xsp5tngai', + documentHash: '845f803d8dd3c2b6be94a6cf3a445b54c36f2e01bd5c9ab4c23f37dbd531489e', + decimals: 0, + mintBatonIsActive: false, + tokensInCirculationBN: '0', + tokensInCirculationStr: '0', + blockCreated: 740089, + totalBurned: '1', + totalMinted: '1', + parentGroupId: 'c9c425f2c6352697c6665a53e035cbad8a44c4b1e36491a1838dc4655479aa09' + }, + mutableData: { + updated: '2022-05-14T15:27:44.429Z', + tokenIcon: 'https://bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy.ipfs.dweb.link/send-bch-token-icon.png', + tokenInfo: 'https://token.fullstack.cash/?tokenid=d9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b', + description: 'This is an NFT representing a video. This is a test token.', + issuer: 'Chris Troutner', + forSale: false, + display: true, + currentOwner: { + bchAddr: 'bitcoincash:qqy7jcrm3vmtqs96r878hy2kx90mn84f25ujqw9z5h', + name: 'Chris Troutner', + contactEmail: 'chris.troutner@gmail.com' + }, + content: { + youtube: 'https://youtu.be/WZRwkLPtkaI', + rumble: 'https://rumble.com/v14n00h-how-to-send-bch-and-tokens.html', + odysee: 'https://odysee.com/@trout:5/how-to-send-bch-tokens:0', + lbry: 'lbry://@trout#5/how-to-send-bch-tokens#0', + ipfs: 'bafybeigf3ky5i6fyxwk5bjmtsr6urqmlx4zq2lqathgguytey67iinh4be', + filecoin: 'https://bafybeigf3ky5i6fyxwk5bjmtsr6urqmlx4zq2lqathgguytey67iinh4be.ipfs.dweb.link/send-bch-2022-02-20_08.22.45.mp4' + } + }, + immutableData: { + creationDate: '2022-05-13T21:32:11.619Z', + issuer: 'Chris Troutner', + license: 'https://bafybeidnkhjfsbihp4gquwqrs6y35jfpcriafymceszwvkundjkwk546pi.ipfs.dweb.link/copyright.txt', + name: 'How to Send BCH and Tokens' + }, + tokenIcon: 'https://bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy.ipfs.dweb.link/send-bch-token-icon.png', + fullSizedUrl: '', + optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy/send-bch-token-icon.png', + optimizedFullSizedUrl: '', + iconRepoCompatible: false, + ps002Compatible: true +} + module.exports = { tokenStats, txData, balance, status, tokenData01, - tokenData + tokenData, + tokenMedia01 } diff --git a/test/unit/price.js b/test/unit/price.js index ffef561..fc06b98 100644 --- a/test/unit/price.js +++ b/test/unit/price.js @@ -19,18 +19,18 @@ describe('#price', () => { afterEach(() => sandbox.restore()) - describe('#current', () => { - it('should get current price for single currency', async () => { - sandbox - .stub(bchjs.Price.axios, 'get') - .resolves({ data: { price: 24905 } }) - - const result = await bchjs.Price.current('usd') - // console.log(result) - - assert.isNumber(result) - }) - }) + // describe('#current', () => { + // it('should get current price for single currency', async () => { + // sandbox + // .stub(bchjs.Price.axios, 'get') + // .resolves({ data: { price: 24905 } }) + // + // const result = await bchjs.Price.current('usd') + // // console.log(result) + // + // assert.isNumber(result) + // }) + // }) describe('#getUsd', () => { it('should get the USD price of BCH', async () => { diff --git a/test/unit/psf-slp-indexer.js b/test/unit/psf-slp-indexer.js index b8744ef..161c669 100644 --- a/test/unit/psf-slp-indexer.js +++ b/test/unit/psf-slp-indexer.js @@ -411,4 +411,28 @@ describe('#PsfSlpIndexer', () => { } }) }) + + describe('#getTokenData2', () => { + it('should get token data', async () => { + // Stub the network call. + sandbox.stub(axios, 'post').resolves({ data: mockData.tokenMedia01 }) + + const tokenId = + 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b' + + // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/' + const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId) + // console.log('result: ', result) + + assert.property(result, 'tokenStats') + assert.property(result, 'mutableData') + assert.property(result, 'immutableData') + assert.property(result, 'tokenIcon') + assert.property(result, 'fullSizedUrl') + assert.property(result, 'optimizedTokenIcon') + assert.property(result, 'optimizedFullSizedUrl') + assert.property(result, 'iconRepoCompatible') + assert.property(result, 'ps002Compatible') + }) + }) })