@psf/bch-js 6.4.5 → 6.5.1
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 +1 -1
- package/src/price.js +13 -13
- package/src/psf-slp-indexer.js +95 -0
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +21 -0
- package/test/integration/price.js +9 -8
- package/test/unit/fixtures/psf-slp-indexer-mock.js +55 -1
- package/test/unit/price.js +12 -12
- package/test/unit/psf-slp-indexer.js +24 -0
package/package.json
CHANGED
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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()
|
package/src/psf-slp-indexer.js
CHANGED
|
@@ -442,6 +442,101 @@ 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
|
+
* Get the icon for a token, given it's token ID.
|
|
453
|
+
* This function expects a string input of a token ID property.
|
|
454
|
+
* This function returns an object with a tokenIcon property that contains
|
|
455
|
+
* the URL to the icon.
|
|
456
|
+
*
|
|
457
|
+
* The output object always have these properties:
|
|
458
|
+
* - tokenIcon: A url to the token icon, if it exists.
|
|
459
|
+
* - tokenStats: Data about the token from psf-slp-indexer.
|
|
460
|
+
* - optimizedTokenIcon: An alternative, potentially more optimal, url to the token icon, if it exists.
|
|
461
|
+
* - iconRepoCompatible: true if the token icon is available via token.bch.sx
|
|
462
|
+
* - ps002Compatible: true if the token icon is compatible with PS007 specification.
|
|
463
|
+
*
|
|
464
|
+
* @apiExample Example usage:
|
|
465
|
+
* (async () => {
|
|
466
|
+
* try {
|
|
467
|
+
* let tokenData = await bchjs.PsfSlpIndexer.getTokenData2('a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2')
|
|
468
|
+
* console.log(tokenData)
|
|
469
|
+
* } catch(error) {
|
|
470
|
+
* console.error(error)
|
|
471
|
+
* }
|
|
472
|
+
* })()
|
|
473
|
+
*
|
|
474
|
+
* {
|
|
475
|
+
* tokenStats: {
|
|
476
|
+
* type: 1,
|
|
477
|
+
* ticker: 'CTAIA006',
|
|
478
|
+
* name: 'CTAIA006 - AI Art by Chris Troutner',
|
|
479
|
+
* tokenId: '0e4543f820699294ab57e02ee2b1815a8bbc7b17a4333e4a138034e4b2324a61',
|
|
480
|
+
* documentUri: 'ipfs://bafybeia5yuq7rg6jmwquako7t277cwrobcunz7cumqrv4wn6bgfvthemku',
|
|
481
|
+
* documentHash: '78a00e9db312b8fff4e5c37cf592be83e6bab7f3bd5a54c9545bad5d4f3ee0f5',
|
|
482
|
+
* decimals: 0,
|
|
483
|
+
* mintBatonIsActive: false,
|
|
484
|
+
* tokensInCirculationBN: '1',
|
|
485
|
+
* tokensInCirculationStr: '1',
|
|
486
|
+
* blockCreated: 757507,
|
|
487
|
+
* totalBurned: '0',
|
|
488
|
+
* totalMinted: '1'
|
|
489
|
+
* },
|
|
490
|
+
* mutableData: {
|
|
491
|
+
* tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png',
|
|
492
|
+
* fullSizedUrl: '',
|
|
493
|
+
* about: 'This NFT was created using the PSF Token Studio at https://nft-creator.fullstack.cash',
|
|
494
|
+
* userData: ''
|
|
495
|
+
* },
|
|
496
|
+
* immutableData: {
|
|
497
|
+
* issuer: 'http://psfoundation.cash',
|
|
498
|
+
* website: 'https://nft-creator.fullstack.cash',
|
|
499
|
+
* dateCreated: '9/12/2022, 5:17:38 PM',
|
|
500
|
+
* userData: '{\n' +
|
|
501
|
+
* ' "title": "CTAIA006 - AI Art by Chris Troutner",\n' +
|
|
502
|
+
* ' "about": "AI generated art. Generated from DALL-E at https://labs.openai.com",\n' +
|
|
503
|
+
* ' "prompt": "whale swimming through a sky full of stars",\n' +
|
|
504
|
+
* ' "algorithm": "DALL-E (stable diffusion)",\n' +
|
|
505
|
+
* ' "set": "1-of-2"\n' +
|
|
506
|
+
* '}'
|
|
507
|
+
* },
|
|
508
|
+
* tokenIcon: 'https://bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm.ipfs.w3s.link/whale-night-sky-01.png',
|
|
509
|
+
* fullSizedUrl: '',
|
|
510
|
+
* optimizedTokenIcon: 'https://p2wdb-gateway-678.fullstack.cash/ipfs/bafybeihiv5jvlhoymmbous3h2akotogj6b7hruhjcj3zq7dsfteimuuttm/whale-night-sky-01.png',
|
|
511
|
+
* optimizedFullSizedUrl: '',
|
|
512
|
+
* iconRepoCompatible: false,
|
|
513
|
+
* ps002Compatible: true
|
|
514
|
+
* }
|
|
515
|
+
*
|
|
516
|
+
*/
|
|
517
|
+
async getTokenData2 (tokenId) {
|
|
518
|
+
try {
|
|
519
|
+
const url = `${this.restURL}psf/slp/token/data2`
|
|
520
|
+
// console.log(`url: ${url}`)
|
|
521
|
+
|
|
522
|
+
// Handle single address.
|
|
523
|
+
if (typeof tokenId === 'string') {
|
|
524
|
+
const response = await axios.post(
|
|
525
|
+
// 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
|
|
526
|
+
url,
|
|
527
|
+
{ tokenId },
|
|
528
|
+
this.axiosOptions
|
|
529
|
+
)
|
|
530
|
+
return response.data
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
throw new Error('Input tokenId must be a string.')
|
|
534
|
+
} catch (error) {
|
|
535
|
+
// console.log('error: ', error)
|
|
536
|
+
if (error.response && error.response.data) throw error.response.data
|
|
537
|
+
else throw error
|
|
538
|
+
}
|
|
539
|
+
}
|
|
445
540
|
}
|
|
446
541
|
|
|
447
542
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
}
|
package/test/unit/price.js
CHANGED
|
@@ -19,18 +19,18 @@ describe('#price', () => {
|
|
|
19
19
|
|
|
20
20
|
afterEach(() => sandbox.restore())
|
|
21
21
|
|
|
22
|
-
describe('#current', () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
})
|