@psf/bch-js 4.21.0 → 5.2.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/src/ninsight.js DELETED
@@ -1,319 +0,0 @@
1
- /*
2
- This library interacts with the ninsight REST API endpoints operated by
3
- Bitcoin.com
4
- */
5
-
6
- const axios = require('axios')
7
-
8
- // let _this
9
-
10
- class Ninsight {
11
- constructor (config) {
12
- // this.restURL = config.restURL
13
- // this.apiToken = config.apiToken
14
-
15
- // this.ninsightURL = `https://bch-explorer.api.bitcoin.com/v1/`
16
- if (config) {
17
- this.ninsightURL = config.ninsightURL
18
- ? config.ninsightURL
19
- : 'https://rest.bitcoin.com/v2'
20
- }
21
-
22
- // Add JWT token to the authorization header.
23
- this.axiosOptions = {
24
- headers: {
25
- authorization: `Token ${this.apiToken}`,
26
- timeout: 15000
27
- }
28
- }
29
-
30
- // _this = this
31
- }
32
-
33
- /**
34
- * @api Ninsight.utxo() utxo()
35
- * @apiName Ninsight Utxo
36
- * @apiGroup Ninsight
37
- * @apiDescription Return list of uxto for address.
38
- *
39
- * @apiExample Example usage:
40
- * (async () => {
41
- * try {
42
- * let utxo = await bchjs.Ninsight.utxo('bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c');
43
- * console.log(utxo);
44
- * } catch(error) {
45
- * console.error(error)
46
- * }
47
- * })()
48
- *
49
- * // [
50
- * // {
51
- * // "txid": "d31dc2cf66fe4d3d3ae18e1065def58a64920746b1702b52f060e5edeea9883b",
52
- * // "vout": 1,
53
- * // "amount": 0.03608203,
54
- * // "satoshis": 3608203,
55
- * // "height": 585570,
56
- * // "confirmations": 10392
57
- * // },
58
- * // {
59
- * // "txid": "41e9a118765ecf7a1ba4487c0863e23dba343cc5880381a72f0365ac2546c5fa",
60
- * // "vout": 0,
61
- * // "amount": 0.03608203,
62
- * // "satoshis": 3608203,
63
- * // "height": 577125,
64
- * // "confirmations": 18837
65
- * // }
66
- * // ]
67
- *
68
- */
69
- async utxo (address) {
70
- try {
71
- // Handle single address.
72
- if (typeof address === 'string') {
73
- const response = await axios.post(
74
- `${this.ninsightURL}/address/utxo`,
75
- {
76
- addresses: [address]
77
- },
78
- this.axiosOptions
79
- )
80
- return response.data
81
-
82
- // Handle array of addresses.
83
- } else if (Array.isArray(address)) {
84
- const response = await axios.post(
85
- `${this.ninsightURL}/address/utxo`,
86
- {
87
- addresses: address
88
- },
89
- this.axiosOptions
90
- )
91
-
92
- return response.data
93
- }
94
-
95
- throw new Error('Input address must be a string or array of strings.')
96
- } catch (error) {
97
- if (error.response && error.response.data) throw error.response.data
98
- else throw error
99
- }
100
- }
101
-
102
- /**
103
- * @api Ninsight.unconfirmed() unconfirmed()
104
- * @apiName Ninsight Unconfirmed Utxo
105
- * @apiGroup Ninsight
106
- * @apiDescription Returns a list of unconfirmed UTXOs for an address.
107
- *
108
- * @apiExample Example usage:
109
- * (async () => {
110
- * try {
111
- * let utxo = await bchjs.Ninsight.unconfirmed('bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c');
112
- * console.log(utxo);
113
- * } catch(error) {
114
- * console.error(error)
115
- * }
116
- * })()
117
- *
118
- * // [
119
- * // {
120
- * // "txid": "d31dc2cf66fe4d3d3ae18e1065def58a64920746b1702b52f060e5edeea9883b",
121
- * // "vout": 1,
122
- * // "amount": 0.03608203,
123
- * // "satoshis": 3608203,
124
- * // "confirmations": 0
125
- * // "ts": 1559670801
126
- * // },
127
- * // {
128
- * // "txid": "41e9a118765ecf7a1ba4487c0863e23dba343cc5880381a72f0365ac2546c5fa",
129
- * // "vout": 0,
130
- * // "amount": 0.03608203,
131
- * // "satoshis": 3608203,
132
- * // "confirmations": 0
133
- * // "ts": 1559670902
134
- * // }
135
- * // ]
136
- *
137
- */
138
- async unconfirmed (address) {
139
- try {
140
- if (typeof address === 'string') {
141
- const response = await axios.post(
142
- `${this.ninsightURL}/address/unconfirmed`,
143
- {
144
- addresses: [address]
145
- },
146
- this.axiosOptions
147
- )
148
-
149
- return response.data
150
- } else if (Array.isArray(address)) {
151
- const response = await axios.post(
152
- `${this.ninsightURL}/address/unconfirmed`,
153
- {
154
- addresses: address
155
- },
156
- this.axiosOptions
157
- )
158
-
159
- return response.data
160
- }
161
-
162
- throw new Error('Input address must be a string or array of strings.')
163
- } catch (error) {
164
- if (error.response && error.response.data) throw error.response.data
165
- else throw error
166
- }
167
- }
168
-
169
- /**
170
- * @api Ninsight.transactions() transactions()
171
- * @apiName Ninsight TX History
172
- * @apiGroup Ninsight
173
- * @apiDescription Return transactions history for address.
174
- *
175
- * @apiExample Example usage:
176
- * (async () => {
177
- * try {
178
- * let txs = await bchjs.Ninsight.transactions('bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c');
179
- * console.log(txs);
180
- * } catch(error) {
181
- * console.error(error)
182
- * }
183
- * })()
184
- *
185
- * // [
186
- * // {
187
- * // "pagesTotal": 1,
188
- * // "txs": [
189
- * // {
190
- * // "txid": "ec7bc8349386e3e1939bbdc4f8092fdbdd6a380734e68486b558cd594c451d5b",
191
- * // "version": 2,
192
- * // "locktime": 0,
193
- * // "vin": [
194
- * // {
195
- * // "txid": "4f1fc57c33659628938db740449bf92fb75799e1d5750a4aeef80eb52d6df1e0",
196
- * // "vout": 0,
197
- * // "sequence": 4294967295,
198
- * // "n": 0,
199
- * // ...
200
- * // }
201
- * // ...
202
- * // ]
203
- * // ...
204
- * // }
205
- * // ],
206
- * // "legacyAddress": "1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP",
207
- * // "cashAddress": "bitcoincash:qrvk436u4r0ew2wj0rd9pnxhx4w90p2yfc29ta0d2n",
208
- * // "currentPage": 0
209
- * // }
210
- * // ]
211
- * //
212
- *
213
- */
214
- async transactions (address) {
215
- try {
216
- if (typeof address === 'string') {
217
- const response = await axios.post(
218
- `${this.ninsightURL}/address/transactions`,
219
- {
220
- addresses: [address]
221
- },
222
- this.axiosOptions
223
- )
224
-
225
- return response.data
226
- } else if (Array.isArray(address)) {
227
- const response = await axios.post(
228
- `${this.ninsightURL}/address/transactions`,
229
- {
230
- addresses: address
231
- },
232
- this.axiosOptions
233
- )
234
-
235
- return response.data
236
- }
237
-
238
- throw new Error('Input address must be a string or array of strings.')
239
- } catch (error) {
240
- if (error.response && error.response.data) throw error.response.data
241
- else throw error
242
- }
243
- }
244
-
245
- /**
246
- * @api Ninsight.txDetails() txDetails()
247
- * @apiName Ninsight TX Details
248
- * @apiGroup Ninsight
249
- * @apiDescription Return transactions details for address(es).
250
- *
251
- * @apiExample Example usage:
252
- * (async () => {
253
- * try {
254
- * let result = await bchjs.Ninsight.txDetails('fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33');
255
- * console.log(result);
256
- * } catch(error) {
257
- * console.error(error)
258
- * }
259
- * })()
260
- *
261
- * // [
262
- * // {
263
- * // "txid": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
264
- * // "version": 1,
265
- * // "locktime": 0,
266
- * // "vin": [
267
- * // {
268
- * // "sequence": 4294967295,
269
- * // "n": 0
270
- * // }
271
- * // ],
272
- * // "vout": [
273
- * // ...
274
- * // ],
275
- * // "blockhash": "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09",
276
- * // "blockheight": 1000,
277
- * // "confirmations": 659909,
278
- * // "time": 1232346882,
279
- * // "blocktime": 1232346882,
280
- * // "firstSeenTime": null,
281
- * // "valueOut": 50,
282
- * // "size": 135
283
- * // }
284
- * // ]
285
- *
286
- */
287
- async txDetails (txid) {
288
- try {
289
- if (typeof txid === 'string') {
290
- const response = await axios.post(
291
- `${this.ninsightURL}/transaction/details`,
292
- {
293
- txids: [txid]
294
- },
295
- this.axiosOptions
296
- )
297
-
298
- return response.data
299
- } else if (Array.isArray(txid)) {
300
- const response = await axios.post(
301
- `${this.ninsightURL}/transaction/details`,
302
- {
303
- txids: txid
304
- },
305
- this.axiosOptions
306
- )
307
-
308
- return response.data
309
- }
310
-
311
- throw new Error('Transaction ID must be a string or array of strings.')
312
- } catch (error) {
313
- if (error.response && error.response.data) throw error.response.data
314
- else throw error
315
- }
316
- }
317
- }
318
-
319
- module.exports = Ninsight
@@ -1,170 +0,0 @@
1
- /*
2
- Mocking data for unit tests for the Ninsight library.
3
- */
4
-
5
- const utxo = {
6
- utxos: [
7
- {
8
- txid: '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7',
9
- vout: 0,
10
- amount: 0.00001,
11
- satoshis: 1000,
12
- height: 602405,
13
- confirmations: 36459
14
- }
15
- ],
16
- legacyAddress: '15NCRBJsHaJy8As5bX1oh2YauRejnZ1MKF',
17
- cashAddress: 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9',
18
- slpAddress: 'simpleledger:qqh793x9au6ehvh7r2zflzguanlme760wuwzunhjfm',
19
- scriptPubKey: '76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac',
20
- asm:
21
- 'OP_DUP OP_HASH160 2fe2c4c5ef359bb2fe1a849f891cecffbcfb4f77 OP_EQUALVERIFY OP_CHECKSIG'
22
- }
23
-
24
- const unconfirmed = {
25
- utxos: [
26
- {
27
- txid: '3904ffe6f8fba4ceda5e887130f60fcb18bdc7dcee10392a57f89475c5c108f1',
28
- vout: 0,
29
- amount: 0.03608203,
30
- satoshis: 3608203,
31
- confirmations: 0,
32
- ts: 1559670801
33
- }
34
- ],
35
- legacyAddress: '1AyWs8U4HUnTLmxxFiGoJbsXauRsvBrcKW',
36
- cashAddress: 'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5',
37
- slpAddress: 'simpleledger:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rkuk8mdxlf2',
38
- scriptPubKey: '76a9146d695af951760b837c8e58b045b098f9c17e23b788ac'
39
- }
40
-
41
- const utxoPost = [utxo, utxo]
42
- const unconfirmedPost = [unconfirmed, unconfirmed]
43
-
44
- const transactions = {
45
- pagesTotal: 1,
46
- txs: [
47
- {
48
- txid: 'ec7bc8349386e3e1939bbdc4f8092fdbdd6a380734e68486b558cd594c451d5b',
49
- version: 2,
50
- locktime: 0,
51
- vin: [
52
- {
53
- txid:
54
- '4f1fc57c33659628938db740449bf92fb75799e1d5750a4aeef80eb52d6df1e0',
55
- vout: 0,
56
- sequence: 4294967295,
57
- n: 0,
58
- scriptSig: {
59
- hex:
60
- '483045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f',
61
- asm:
62
- '3045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f'
63
- },
64
- addr: '17HPz8RQ4XM6mjre6aspvqyj1j648CZidM',
65
- valueSat: 1111,
66
- value: 0.00001111,
67
- doubleSpentTxID: null
68
- },
69
- {
70
- txid:
71
- '126d62c299e7e14c66fe0b485d13082c23641f003690462046bc24ad2d1180c1',
72
- vout: 0,
73
- sequence: 4294967295,
74
- n: 1,
75
- scriptSig: {
76
- hex:
77
- '47304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f',
78
- asm:
79
- '304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f'
80
- },
81
- addr: '17HPz8RQ4XM6mjre6aspvqyj1j648CZidM',
82
- valueSat: 1000,
83
- value: 0.00001,
84
- doubleSpentTxID: null
85
- }
86
- ],
87
- vout: [
88
- {
89
- value: '0.00001736',
90
- n: 0,
91
- scriptPubKey: {
92
- hex: '76a914d96ac75ca8df9729d278da50ccd7355c5785444e88ac',
93
- asm:
94
- 'OP_DUP OP_HASH160 d96ac75ca8df9729d278da50ccd7355c5785444e OP_EQUALVERIFY OP_CHECKSIG',
95
- addresses: ['1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP'],
96
- type: 'pubkeyhash'
97
- },
98
- spentTxId: null,
99
- spentIndex: null,
100
- spentHeight: null
101
- }
102
- ],
103
- blockheight: -1,
104
- confirmations: 0,
105
- time: 1559673337,
106
- valueOut: 0.00001736,
107
- size: 339,
108
- valueIn: 0.00002111,
109
- fees: 0.00000375
110
- }
111
- ],
112
- legacyAddress: '1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP',
113
- cashAddress: 'bitcoincash:qrvk436u4r0ew2wj0rd9pnxhx4w90p2yfc29ta0d2n',
114
- currentPage: 0
115
- }
116
-
117
- const transactionsPost = [transactions, transactions]
118
-
119
- const details = {
120
- txid: 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33',
121
- version: 1,
122
- locktime: 0,
123
- vin: [
124
- {
125
- coinbase: '04ffff001d02fd04',
126
- sequence: 4294967295,
127
- n: 0
128
- }
129
- ],
130
- vout: [
131
- {
132
- value: '50.00000000',
133
- n: 0,
134
- scriptPubKey: {
135
- hex:
136
- '4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac',
137
- asm:
138
- '04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG',
139
- addresses: ['1BW18n7MfpU35q4MTBSk8pse3XzQF8XvzT'],
140
- type: 'pubkeyhash',
141
- cashAddrs: ['bitcoincash:qpej6mkrwca4tvy2snq4crhrf88v4ljspysx0ueetk']
142
- },
143
- spentTxId: null,
144
- spentIndex: null,
145
- spentHeight: null
146
- }
147
- ],
148
- blockhash:
149
- '00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09',
150
- blockheight: 1000,
151
- confirmations: 585610,
152
- time: 1232346882,
153
- blocktime: 1232346882,
154
- isCoinBase: true,
155
- valueOut: 50,
156
- size: 135
157
- }
158
-
159
- const detailsPost = [details, details]
160
-
161
- module.exports = {
162
- utxo,
163
- utxoPost,
164
- unconfirmed,
165
- unconfirmedPost,
166
- transactions,
167
- transactionsPost,
168
- details,
169
- detailsPost
170
- }