@psf/bch-js 6.7.3 → 6.8.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.7.3",
3
+ "version": "6.8.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
@@ -230,6 +230,42 @@ class Price {
230
230
  else throw err
231
231
  }
232
232
  }
233
+
234
+ /**
235
+ * @api price.getPsffppPrice() getPsffppPrice()
236
+ * @apiName Price getPsffppPrice()
237
+ * @apiGroup Price
238
+ * @apiDescription Return the cost in PSF tokens to write 1MB of data to the PSFFPP
239
+ * Find out more at PSFFPP.com. This is a IPFS pinning service that can pin
240
+ * up to 100MB per transaction into its network. The cost is denominated in
241
+ * PSF SLP tokens. The endpoint returns the cost to pin 1MB of data to the
242
+ * PSFFPP network.
243
+ *
244
+ * @apiExample Example usage:
245
+ *(async () => {
246
+ * try {
247
+ * let current = await bchjs.Price.getPsffppPrice();
248
+ * console.log(current);
249
+ * } catch(err) {
250
+ * console.error(err)
251
+ * }
252
+ *})()
253
+ *
254
+ * // 0.08335233
255
+ */
256
+ async getPsffppPrice () {
257
+ try {
258
+ const response = await this.axios.get(
259
+ `${this.restURL}price/psffpp`,
260
+ this.axiosOptions
261
+ )
262
+
263
+ return response.data.writePrice
264
+ } catch (err) {
265
+ if (err.response && err.response.data) throw err.response.data
266
+ else throw err
267
+ }
268
+ }
233
269
  }
234
270
 
235
271
  module.exports = Price
package/src/slp/nft1.js CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  // Public npm libraries
12
- const axios = require('axios')
12
+ // const axios = require('axios')
13
13
 
14
14
  // Local libraries.
15
15
  const Address = require('./address')
@@ -419,97 +419,6 @@ class Nft1 {
419
419
  throw err
420
420
  }
421
421
  }
422
-
423
- /**
424
- * @api SLP.NFT1.listNFTGroupChildren() listNFTGroupChildren()
425
- * @apiName listNFTGroupChildren
426
- * @apiGroup SLP NFT1
427
- * @apiDescription Return list of NFT children tokens in a NFT Group.
428
- * It's assumed provided groupId parameter is for an NFT Group token (type=129)
429
- *
430
- * Returns an Array with GENESIS transaction IDs of the children tokens.
431
- *
432
- * @apiExample Example usage:
433
- *
434
- * const groupId = '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
435
- * const children = await bchjs.SLP.Nft1.listNFTGroupChildren(groupId)
436
- *
437
- * children = {
438
- * "nftChildren": [
439
- * "45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9",
440
- * "928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55"
441
- * ]
442
- * }
443
- */
444
- async listNFTGroupChildren (groupId) {
445
- try {
446
- if (typeof groupId === 'string') {
447
- const response = await axios.get(
448
- `${this.restURL}slp/nftChildren/${groupId}`,
449
- this.axiosOptions
450
- )
451
- return response.data
452
- }
453
-
454
- throw new Error('groupId must be a string.')
455
- } catch (error) {
456
- // console.log('Error in listNFTGroupChildren()')
457
- if (error.response && error.response.data) throw error.response.data
458
- else throw error
459
- }
460
- }
461
-
462
- /**
463
- * @api SLP.NFT1.parentNFTGroup() parentNFTGroup()
464
- * @apiName parentNFTGroup
465
- * @apiGroup SLP NFT1
466
- * @apiDescription Return parent NFT Group information for a given NFT child token.
467
- * It's assumed provided groupId parameter is for an NFT Child token (type=65)
468
- *
469
- * Returns a JSON with NFT group information.
470
- *
471
- * @apiExample Example usage:
472
- *
473
- * const tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
474
- * const group = await bchjs.SLP.Nft1.parentNFTGroup(tokenId)
475
- *
476
- * group = {
477
- * "nftGroup": {
478
- * "decimals": 0,
479
- * "timestamp": "2021-05-03 10:36:01",
480
- * "timestamp_unix": 1620038161,
481
- * "versionType": 129,
482
- * "documentUri": "psfoundation.cash",
483
- * "symbol": "PSF.TEST.GROUP",
484
- * "name": "PSF Test NFT Group",
485
- * "containsBaton": true,
486
- * "id": "68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a",
487
- * "documentHash": null,
488
- * "initialTokenQty": 1000000,
489
- * "blockCreated": 686117,
490
- * "totalMinted": null,
491
- * "totalBurned": null,
492
- * "circulatingSupply": null
493
- * }
494
- * }
495
- */
496
- async parentNFTGroup (tokenId) {
497
- try {
498
- if (typeof tokenId === 'string') {
499
- const response = await axios.get(
500
- `${this.restURL}slp/nftGroup/${tokenId}`,
501
- this.axiosOptions
502
- )
503
- return response.data
504
- }
505
-
506
- throw new Error('tokenId must be a string.')
507
- } catch (error) {
508
- // console.log('Error in parentNFTGroup()')
509
- if (error.response && error.response.data) throw error.response.data
510
- else throw error
511
- }
512
- }
513
422
  }
514
423
 
515
424
  module.exports = Nft1
@@ -52,6 +52,15 @@ describe('#price', () => {
52
52
  assert.property(result, 'CAD')
53
53
  })
54
54
  })
55
+
56
+ describe('#getPsffppPrice', () => {
57
+ it('should get the price of BCH in several currencies', async () => {
58
+ const result = await bchjs.Price.getPsffppPrice()
59
+ // console.log(result)
60
+
61
+ assert.isNumber(result)
62
+ })
63
+ })
55
64
  })
56
65
 
57
66
  function sleep (ms) {
@@ -4,7 +4,7 @@
4
4
 
5
5
  const assert = require('chai').assert
6
6
  const sinon = require('sinon')
7
- const axios = require('axios')
7
+ // const axios = require('axios')
8
8
 
9
9
  // Default to unit tests unless some other value for TEST is passed.
10
10
  if (!process.env.TEST) process.env.TEST = 'unit'
@@ -14,7 +14,7 @@ const BCHJS = require('../../src/bch-js')
14
14
  const bchjs = new BCHJS()
15
15
 
16
16
  // Mock data used for unit tests
17
- const mockData = require('./fixtures/slp/mock-utils')
17
+ // const mockData = require('./fixtures/slp/mock-utils')
18
18
 
19
19
  // Default to unit tests unless some other value for TEST is passed.
20
20
  if (!process.env.TEST) process.env.TEST = 'unit'
@@ -253,95 +253,4 @@ describe('#SLP NFT1', () => {
253
253
  assert.isNumber(result.outputs)
254
254
  })
255
255
  })
256
- describe('#listNFTGroupChildren', () => {
257
- it('should throw an error for improper input', async () => {
258
- try {
259
- const groupId = 12345
260
-
261
- await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
262
- assert.equal(true, false, 'Unexpected result!')
263
- } catch (err) {
264
- // console.log(`err: `, err)
265
- assert.include(
266
- err.message,
267
- 'groupId must be a string'
268
- )
269
- }
270
- })
271
- it('should handle API response error', async () => {
272
- try {
273
- const error = new Error()
274
- error.response = {
275
- error: 'NFT group does not exists'
276
- }
277
- sandbox.stub(axios, 'get').throws(error)
278
-
279
- const groupId = 'non-exists'
280
- await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
281
- } catch (err) {
282
- assert.include(
283
- err.response,
284
- { error: 'NFT group does not exists' }
285
- )
286
- }
287
- })
288
- it('should return array of children GENESIS transactions IDs', async () => {
289
- sandbox.stub(axios, 'get').resolves({ data: mockData.mockNftChildrenList })
290
-
291
- const groupId = '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
292
- const result = await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
293
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
294
-
295
- assert.property(result, 'nftChildren')
296
- assert.isArray(result.nftChildren)
297
- })
298
- })
299
- describe('#parentNFTGroup', () => {
300
- it('should throw an error for improper input', async () => {
301
- try {
302
- const tokenId = 12345
303
-
304
- await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
305
- assert.equal(true, false, 'Unexpected result!')
306
- } catch (err) {
307
- // console.log(`err: `, err)
308
- assert.include(
309
- err.message,
310
- 'tokenId must be a string'
311
- )
312
- }
313
- })
314
- it('should handle API response error', async () => {
315
- try {
316
- const error = new Error()
317
- error.response = {
318
- error: 'NFT child does not exists'
319
- }
320
- sandbox.stub(axios, 'get').throws(error)
321
-
322
- const tokenId = 'non-exists'
323
- await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
324
- } catch (err) {
325
- assert.include(
326
- err.response,
327
- { error: 'NFT child does not exists' }
328
- )
329
- }
330
- })
331
- it('should return parent NFT group information', async () => {
332
- sandbox.stub(axios, 'get').resolves({ data: mockData.mockNftGroup })
333
-
334
- const tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
335
- const result = await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
336
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
337
-
338
- assert.property(result, 'nftGroup')
339
- assert.property(result.nftGroup, 'id')
340
- assert.property(result.nftGroup, 'name')
341
- assert.property(result.nftGroup, 'symbol')
342
- assert.property(result.nftGroup, 'documentUri')
343
- assert.property(result.nftGroup, 'versionType')
344
- assert.property(result.nftGroup, 'initialTokenQty')
345
- })
346
- })
347
256
  })