From 6ef5ac0f7c043fa389d5309dc5c9ee41a281c9a4 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 6 Oct 2022 17:57:11 -0700 Subject: [PATCH 1/4] feat(getTokenData2): Adding new endpoint for token icons and other media --- package-lock.json | 9 -- src/psf-slp-indexer.js | 82 +++++++++++++++++++ .../bchn/psf-slp-indexer.integration.js | 19 +++++ 3 files changed, 101 insertions(+), 9 deletions(-) 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/psf-slp-indexer.js b/src/psf-slp-indexer.js index 2e9f803..35691ea 100644 --- a/src/psf-slp-indexer.js +++ b/src/psf-slp-indexer.js @@ -442,6 +442,88 @@ 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) { + 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..cee2844 100644 --- a/test/integration/chains/bchn/psf-slp-indexer.integration.js +++ b/test/integration/chains/bchn/psf-slp-indexer.integration.js @@ -155,6 +155,25 @@ 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, 'genesisData') + // assert.property(result, 'immutableData') + // assert.property(result, 'mutableData') + // + // assert.isObject(result.genesisData) + // assert.isString(result.immutableData) + // assert.isString(result.mutableData) + }) + }) }) // Promise-based sleep function From 66253ed5a609881b0df25dfc20113411bbb52f7c Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 6 Oct 2022 17:58:00 -0700 Subject: [PATCH 2/4] feat(bchjs.Price.current): Removing dead endpoint --- src/price.js | 26 +++++++++++++------------- test/integration/price.js | 16 ++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) 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/test/integration/price.js b/test/integration/price.js index 17b4e85..3d0832a 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 () => { From 979fb481decd0606b7f42619a9b372b8028408ec Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 6 Oct 2022 18:30:39 -0700 Subject: [PATCH 3/4] feat(getTokenData2): Adding token media endpoint --- src/psf-slp-indexer.js | 1 + .../bchn/psf-slp-indexer.integration.js | 16 +++--- test/unit/fixtures/psf-slp-indexer-mock.js | 56 ++++++++++++++++++- test/unit/psf-slp-indexer.js | 24 ++++++++ 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/src/psf-slp-indexer.js b/src/psf-slp-indexer.js index 35691ea..0130a22 100644 --- a/src/psf-slp-indexer.js +++ b/src/psf-slp-indexer.js @@ -520,6 +520,7 @@ class PsfSlpIndexer { 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 } diff --git a/test/integration/chains/bchn/psf-slp-indexer.integration.js b/test/integration/chains/bchn/psf-slp-indexer.integration.js index cee2844..d36ed37 100644 --- a/test/integration/chains/bchn/psf-slp-indexer.integration.js +++ b/test/integration/chains/bchn/psf-slp-indexer.integration.js @@ -165,13 +165,15 @@ describe('#psf-slp-indexer', () => { const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId) console.log('result: ', result) - // assert.property(result, 'genesisData') - // assert.property(result, 'immutableData') - // assert.property(result, 'mutableData') - // - // assert.isObject(result.genesisData) - // assert.isString(result.immutableData) - // assert.isString(result.mutableData) + 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') }) }) }) 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/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') + }) + }) }) From 44e671dfbec4a4fe50cec6fa7fd2c4606c56dbe1 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 6 Oct 2022 20:24:17 -0700 Subject: [PATCH 4/4] fix(price): Removing dead price endpoint tests --- test/integration/price.js | 1 + test/unit/price.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/integration/price.js b/test/integration/price.js index 3d0832a..d535232 100644 --- a/test/integration/price.js +++ b/test/integration/price.js @@ -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/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 () => {