@tchain/tcabci-read-js-client 2.1.0 → 2.1.2

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/client.js CHANGED
@@ -24,7 +24,7 @@ export default class TCAbciClient {
24
24
  subscribed = false
25
25
  subscribedAddresses = []
26
26
  connected = false
27
- version = 'v2.1.0'
27
+ version = 'v2.1.2'
28
28
  errorCb = null
29
29
  listenCb = null
30
30
  wsLibrary = null
@@ -66,7 +66,9 @@ export default class TCAbciClient {
66
66
 
67
67
  req.priority = 'high'
68
68
 
69
- return fetch(this.readNodeAddress + uri, req).then((response) => this.handleResponse(response))
69
+ return fetch(this.readNodeAddress + uri, req).then((response) =>
70
+ this.handleRestResponse(response),
71
+ )
70
72
  }
71
73
 
72
74
  Socket() {
@@ -200,6 +202,8 @@ export default class TCAbciClient {
200
202
  /**
201
203
  * @param {string} heightOperator
202
204
  * @param {number} height
205
+ * @param {?number} maxHeight
206
+ * @param {?number} lastOrder
203
207
  * @param {?Array<string>} recipientAddrs
204
208
  * @param {?Array<string>} senderAddrs
205
209
  * @param {?Array<string>} hashes
@@ -214,6 +218,8 @@ export default class TCAbciClient {
214
218
  TxSearch({
215
219
  heightOperator,
216
220
  height,
221
+ maxHeight,
222
+ lastOrder,
217
223
  recipientAddrs,
218
224
  senderAddrs,
219
225
  hashes,
@@ -228,14 +234,16 @@ export default class TCAbciClient {
228
234
  method: 'POST',
229
235
  body: JSON.stringify({
230
236
  height: `${heightOperator} ${height}`,
231
- recipient_addrs: recipientAddrs,
232
- sender_addrs: senderAddrs,
233
- hashes: hashes,
234
- limit,
235
- offset,
236
- order_field: orderField,
237
- order_by: orderBy,
238
- ...(types ? { types: types } : { typ: typ }),
237
+ ...(maxHeight ? { max_height: maxHeight } : {}),
238
+ ...(lastOrder ? { last_order: lastOrder } : {}),
239
+ ...(recipientAddrs ? { recipient_addrs: recipientAddrs } : {}),
240
+ ...(senderAddrs ? { sender_addrs: senderAddrs } : {}),
241
+ ...(hashes ? { hashes: hashes } : {}),
242
+ ...(limit ? { limit: limit } : {}),
243
+ ...(offset ? { offset: offset } : {}),
244
+ ...(orderField ? { order_field: orderField } : {}),
245
+ ...(orderBy ? { order_by: orderBy } : {}),
246
+ ...(types ? { types: types } : typ ? { typ: typ } : {}),
239
247
  }),
240
248
  })
241
249
  .then((res) => {
@@ -298,10 +306,19 @@ export default class TCAbciClient {
298
306
  .catch((e) => this.handleRestError(e, { 400: TRANSACTION_NOT_BROADCAST }))
299
307
  }
300
308
 
301
- Bulk(addresses = []) {
309
+ /**
310
+ * @param {Array<string>} addresses
311
+ * @param {?number} maxHeight
312
+ * @return {Promise<*>}
313
+ * @constructor
314
+ */
315
+ Bulk(addresses = [], maxHeight = null) {
302
316
  return this.httpClient('/v1/bulk_tx', {
303
317
  method: 'POST',
304
- body: JSON.stringify({ addresses: addresses }),
318
+ body: JSON.stringify({
319
+ addresses: addresses,
320
+ ...(maxHeight ? { max_height: maxHeight } : {}),
321
+ }),
305
322
  })
306
323
  }
307
324
 
@@ -392,7 +409,7 @@ export default class TCAbciClient {
392
409
  * @param {Response} response
393
410
  * @return {Promise<*>}
394
411
  */
395
- async handleResponse(response) {
412
+ async handleRestResponse(response) {
396
413
  if (response.status >= 200 && response.status < 400) {
397
414
  return response.json()
398
415
  }
@@ -403,12 +420,10 @@ export default class TCAbciClient {
403
420
  data = JSON.parse(data)
404
421
 
405
422
  return Promise.reject(
406
- new FetchError(data.message).setCode(response.status).setResponse(data)
423
+ new FetchError(data.message).setCode(response.status).setResponse(data),
407
424
  )
408
425
  } catch (e) {
409
- return Promise.reject(
410
- new FetchError(response.statusText)
411
- )
426
+ return Promise.reject(new FetchError(response.statusText))
412
427
  }
413
428
  }
414
429
 
package/client_test.js CHANGED
@@ -183,9 +183,10 @@ describe('TCAbciClient TESTS', () => {
183
183
  limit: 1,
184
184
  offset: 0,
185
185
  orderBy: 'ASC',
186
+ types: ['storage'],
186
187
  })
187
188
  .then((data) => {
188
- unitJS.value(data.txs).hasLength(1)
189
+ unitJS.value(data.txs.length).isGreaterThan(0)
189
190
  unitJS.value(data.total_count).isGreaterThan(0)
190
191
  done()
191
192
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tchain/tcabci-read-js-client",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "TransferChain Fastest Read Network WebSocket Client",
5
5
  "main": "client.js",
6
6
  "type": "module",