@psf/bch-js 6.4.5 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psf/bch-js",
3
- "version": "6.4.5",
3
+ "version": "6.5.0",
4
4
  "description": "A JavaScript library for working with Bitcoin Cash, eCash, and SLP Tokens",
5
5
  "author": "Chris Troutner <chris.troutner@gmail.com>",
6
6
  "contributors": [
package/src/price.js CHANGED
@@ -30,19 +30,19 @@ class Price {
30
30
  }
31
31
 
32
32
  // This endpoint is deprecated. Documentation removed.
33
- async current (currency = 'usd') {
34
- try {
35
- const response = await this.axios.get(
36
- `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}`
37
- )
38
- // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
39
-
40
- return response.data.price
41
- } catch (err) {
42
- if (err.response && err.response.data) throw err.response.data
43
- else throw err
44
- }
45
- }
33
+ // async current (currency = 'usd') {
34
+ // try {
35
+ // const response = await this.axios.get(
36
+ // `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}`
37
+ // )
38
+ // // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
39
+ //
40
+ // return response.data.price
41
+ // } catch (err) {
42
+ // if (err.response && err.response.data) throw err.response.data
43
+ // else throw err
44
+ // }
45
+ // }
46
46
 
47
47
  /**
48
48
  * @api price.getUsd() getUsd()
@@ -442,6 +442,89 @@ class PsfSlpIndexer {
442
442
  else throw error
443
443
  }
444
444
  }
445
+
446
+ /**
447
+ * @api PsfSlpIndexer.getTokenData2() getTokenData2()
448
+ * @apiName Token Data
449
+ * @apiGroup PSF SLP
450
+ * @apiDescription Get token icon and other media associated with a token.
451
+ *
452
+ * @apiExample Example usage:
453
+ * (async () => {
454
+ * try {
455
+ * let tokenData = await bchjs.PsfSlpIndexer.getTokenData2('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2')
456
+ * console.log(tokenData)
457
+ * } catch(error) {
458
+ * console.error(error)
459
+ * }
460
+ * })()
461
+ *
462
+ * {
463
+ * tokenStats: {
464
+ * type: 1,
465
+ * ticker: 'CTAIA006',
466
+ * name: 'CTAIA006 - AI Art by Chris Troutner',
467
+ * tokenId: '0e4543f820699294ab57e02ee2b1815a8bbc7b17a4333e4a138034e4b2324a61',
468
+ * documentUri: 'ipfs://bafybeia5yuq7rg6jmwquako7t277cwrobcunz7cumqrv4wn6bgfvthemku',
469
+ * documentHash: '78a00e9db312b8fff4e5c37cf592be83e6bab7f3bd5a54c9545bad5d4f3ee0f5',
470
+ * decimals: 0,
471
+ * mintBatonIsActive: false,
472
+ * tokensInCirculationBN: '1',
473
+ * tokensInCirculationStr: '1',
474
+ * blockCreated: 757507,
475
+ * totalBurned: '0',
476
+ * totalMinted: '1'
477
+ * },
478
+ * mutableData: {
479
+ * tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png',
480
+ * fullSizedUrl: '',
481
+ * about: 'This NFT was created using the PSF Token Studio at https://nft-creator.fullstack.cash',
482
+ * userData: ''
483
+ * },
484
+ * immutableData: {
485
+ * issuer: 'http://psfoundation.cash',
486
+ * website: 'https://nft-creator.fullstack.cash',
487
+ * dateCreated: '9/12/2022, 5:17:38 PM',
488
+ * userData: '{\n' +
489
+ * ' "title": "CTAIA006 - AI Art by Chris Troutner",\n' +
490
+ * ' "about": "AI generated art. Generated from DALL-E at https://labs.openai.com",\n' +
491
+ * ' "prompt": "whale swimming through a sky full of stars",\n' +
492
+ * ' "algorithm": "DALL-E (stable diffusion)",\n' +
493
+ * ' "set": "1-of-2"\n' +
494
+ * '}'
495
+ * },
496
+ * tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png',
497
+ * fullSizedUrl: '',
498
+ * optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm/whale-night-sky-01.png',
499
+ * optimizedFullSizedUrl: '',
500
+ * iconRepoCompatible: false,
501
+ * ps002Compatible: true
502
+ * }
503
+ *
504
+ */
505
+ async getTokenData2 (tokenId) {
506
+ try {
507
+ const url = `${this.restURL}psf/slp/token/data2`
508
+ // console.log(`url: ${url}`)
509
+
510
+ // Handle single address.
511
+ if (typeof tokenId === 'string') {
512
+ const response = await axios.post(
513
+ // 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
514
+ url,
515
+ { tokenId },
516
+ this.axiosOptions
517
+ )
518
+ return response.data
519
+ }
520
+
521
+ throw new Error('Input tokenId must be a string.')
522
+ } catch (error) {
523
+ console.log('error: ', error)
524
+ if (error.response && error.response.data) throw error.response.data
525
+ else throw error
526
+ }
527
+ }
445
528
  }
446
529
 
447
530
  module.exports = PsfSlpIndexer
@@ -155,6 +155,27 @@ describe('#psf-slp-indexer', () => {
155
155
  assert.isArray(result.genesisData.txs)
156
156
  })
157
157
  })
158
+
159
+ describe('#getTokenData2', () => {
160
+ it('should get token data', async () => {
161
+ const tokenId =
162
+ 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b'
163
+
164
+ // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/'
165
+ const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId)
166
+ console.log('result: ', result)
167
+
168
+ assert.property(result, 'tokenStats')
169
+ assert.property(result, 'mutableData')
170
+ assert.property(result, 'immutableData')
171
+ assert.property(result, 'tokenIcon')
172
+ assert.property(result, 'fullSizedUrl')
173
+ assert.property(result, 'optimizedTokenIcon')
174
+ assert.property(result, 'optimizedFullSizedUrl')
175
+ assert.property(result, 'iconRepoCompatible')
176
+ assert.property(result, 'ps002Compatible')
177
+ })
178
+ })
158
179
  })
159
180
 
160
181
  // Promise-based sleep function
@@ -7,14 +7,14 @@ describe('#price', () => {
7
7
  if (process.env.IS_USING_FREE_TIER) await sleep(1500)
8
8
  })
9
9
 
10
- describe('#current', () => {
11
- describe('#single currency', () => {
12
- it('should get current price for single currency', async () => {
13
- const result = await bchjs.Price.current('usd')
14
- assert.notEqual(0, result)
15
- })
16
- })
17
- })
10
+ // describe('#current', () => {
11
+ // describe('#single currency', () => {
12
+ // it('should get current price for single currency', async () => {
13
+ // const result = await bchjs.Price.current('usd')
14
+ // assert.notEqual(0, result)
15
+ // })
16
+ // })
17
+ // })
18
18
 
19
19
  describe('#getUsd', () => {
20
20
  it('should get the USD price of BCH', async () => {
@@ -33,6 +33,7 @@ describe('#price', () => {
33
33
  assert.isNumber(result)
34
34
  })
35
35
  })
36
+
36
37
  describe('#getBchUsd', () => {
37
38
  it('should get the USD price of BCH', async () => {
38
39
  const result = await bchjs.Price.getBchUsd()
@@ -150,11 +150,65 @@ const tokenData = {
150
150
  mutableData: 'ipfs://bafybeie6t5uyupddc7azms737xg4hxrj7i5t5ov3lb5g2qeehaujj6ak64'
151
151
  }
152
152
 
153
+ const tokenMedia01 = {
154
+ tokenStats: {
155
+ type: 65,
156
+ ticker: 'TEST02',
157
+ name: 'How to Send BCH and Tokens',
158
+ tokenId: 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b',
159
+ documentUri: 'ipfs://bafybeigjujbb55wqr5lns7z7vleg5cfp4yjwqp4swisxpgxl4xsp5tngai',
160
+ documentHash: '845f803d8dd3c2b6be94a6cf3a445b54c36f2e01bd5c9ab4c23f37dbd531489e',
161
+ decimals: 0,
162
+ mintBatonIsActive: false,
163
+ tokensInCirculationBN: '0',
164
+ tokensInCirculationStr: '0',
165
+ blockCreated: 740089,
166
+ totalBurned: '1',
167
+ totalMinted: '1',
168
+ parentGroupId: 'c9c425f2c6352697c6665a53e035cbad8a44c4b1e36491a1838dc4655479aa09'
169
+ },
170
+ mutableData: {
171
+ updated: '2022-05-14T15:27:44.429Z',
172
+ tokenIcon: 'https://bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy.ipfs.dweb.link/send-bch-token-icon.png',
173
+ tokenInfo: 'https://token.fullstack.cash/?tokenid=d9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b',
174
+ description: 'This is an NFT representing a video. This is a test token.',
175
+ issuer: 'Chris Troutner',
176
+ forSale: false,
177
+ display: true,
178
+ currentOwner: {
179
+ bchAddr: 'bitcoincash:qqy7jcrm3vmtqs96r878hy2kx90mn84f25ujqw9z5h',
180
+ name: 'Chris Troutner',
181
+ contactEmail: 'chris.troutner@gmail.com'
182
+ },
183
+ content: {
184
+ youtube: 'https://youtu.be/WZRwkLPtkaI',
185
+ rumble: 'https://rumble.com/v14n00h-how-to-send-bch-and-tokens.html',
186
+ odysee: 'https://odysee.com/@trout:5/how-to-send-bch-tokens:0',
187
+ lbry: 'lbry://@trout#5/how-to-send-bch-tokens#0',
188
+ ipfs: 'bafybeigf3ky5i6fyxwk5bjmtsr6urqmlx4zq2lqathgguytey67iinh4be',
189
+ filecoin: 'https://bafybeigf3ky5i6fyxwk5bjmtsr6urqmlx4zq2lqathgguytey67iinh4be.ipfs.dweb.link/send-bch-2022-02-20_08.22.45.mp4'
190
+ }
191
+ },
192
+ immutableData: {
193
+ creationDate: '2022-05-13T21:32:11.619Z',
194
+ issuer: 'Chris Troutner',
195
+ license: 'https://bafybeidnkhjfsbihp4gquwqrs6y35jfpcriafymceszwvkundjkwk546pi.ipfs.dweb.link/copyright.txt',
196
+ name: 'How to Send BCH and Tokens'
197
+ },
198
+ tokenIcon: 'https://bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy.ipfs.dweb.link/send-bch-token-icon.png',
199
+ fullSizedUrl: '',
200
+ optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeiefg3nd5iognbqztkpi5hj34dmwkqfe7v7xeayn2nhhatinmjmzcy/send-bch-token-icon.png',
201
+ optimizedFullSizedUrl: '',
202
+ iconRepoCompatible: false,
203
+ ps002Compatible: true
204
+ }
205
+
153
206
  module.exports = {
154
207
  tokenStats,
155
208
  txData,
156
209
  balance,
157
210
  status,
158
211
  tokenData01,
159
- tokenData
212
+ tokenData,
213
+ tokenMedia01
160
214
  }
@@ -19,18 +19,18 @@ describe('#price', () => {
19
19
 
20
20
  afterEach(() => sandbox.restore())
21
21
 
22
- describe('#current', () => {
23
- it('should get current price for single currency', async () => {
24
- sandbox
25
- .stub(bchjs.Price.axios, 'get')
26
- .resolves({ data: { price: 24905 } })
27
-
28
- const result = await bchjs.Price.current('usd')
29
- // console.log(result)
30
-
31
- assert.isNumber(result)
32
- })
33
- })
22
+ // describe('#current', () => {
23
+ // it('should get current price for single currency', async () => {
24
+ // sandbox
25
+ // .stub(bchjs.Price.axios, 'get')
26
+ // .resolves({ data: { price: 24905 } })
27
+ //
28
+ // const result = await bchjs.Price.current('usd')
29
+ // // console.log(result)
30
+ //
31
+ // assert.isNumber(result)
32
+ // })
33
+ // })
34
34
 
35
35
  describe('#getUsd', () => {
36
36
  it('should get the USD price of BCH', async () => {
@@ -411,4 +411,28 @@ describe('#PsfSlpIndexer', () => {
411
411
  }
412
412
  })
413
413
  })
414
+
415
+ describe('#getTokenData2', () => {
416
+ it('should get token data', async () => {
417
+ // Stub the network call.
418
+ sandbox.stub(axios, 'post').resolves({ data: mockData.tokenMedia01 })
419
+
420
+ const tokenId =
421
+ 'd9aafa7acb514c597caf440ae268b5e4e955f2687e05f044cdf8fd9550d9a27b'
422
+
423
+ // bchjs.PsfSlpIndexer.restURL = 'http://localhost:3000/v5/'
424
+ const result = await bchjs.PsfSlpIndexer.getTokenData2(tokenId)
425
+ // console.log('result: ', result)
426
+
427
+ assert.property(result, 'tokenStats')
428
+ assert.property(result, 'mutableData')
429
+ assert.property(result, 'immutableData')
430
+ assert.property(result, 'tokenIcon')
431
+ assert.property(result, 'fullSizedUrl')
432
+ assert.property(result, 'optimizedTokenIcon')
433
+ assert.property(result, 'optimizedFullSizedUrl')
434
+ assert.property(result, 'iconRepoCompatible')
435
+ assert.property(result, 'ps002Compatible')
436
+ })
437
+ })
414
438
  })