@tchain/tcabci-read-js-client 2.6.3 → 2.6.4
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/callback.d.ts +3 -1
- package/client.js +18 -9
- package/package.json +1 -1
- package/transaction.d.ts +6 -0
- package/transaction.js +105 -24
- package/websocketOptions.js +1 -1
package/callback.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Transaction } from './transaction'
|
|
2
|
+
|
|
1
3
|
export declare type SuccessCallback = (event: Event) => void
|
|
2
4
|
export declare type ErrorCallback = (event: Event) => void
|
|
3
5
|
export declare type CloseCallback = (event: Event) => void
|
|
4
|
-
export declare type ListenCallback = (
|
|
6
|
+
export declare type ListenCallback = (tx: Transaction) => void
|
package/client.js
CHANGED
|
@@ -47,7 +47,7 @@ export default class TCaBCIClient {
|
|
|
47
47
|
_connected = false
|
|
48
48
|
_chainName = 'transferchain'
|
|
49
49
|
_chainVersion = 'v1'
|
|
50
|
-
_version = `v2.6.
|
|
50
|
+
_version = `v2.6.4`
|
|
51
51
|
/**
|
|
52
52
|
* @type {?SuccessCallback}
|
|
53
53
|
*/
|
|
@@ -383,20 +383,29 @@ export default class TCaBCIClient {
|
|
|
383
383
|
}),
|
|
384
384
|
})
|
|
385
385
|
.then((res) => {
|
|
386
|
-
|
|
387
|
-
res.data.first_transaction,
|
|
388
|
-
)
|
|
389
|
-
if (error) return Promise.reject(error)
|
|
386
|
+
let firstTransaction, lastTransaction
|
|
390
387
|
|
|
391
|
-
|
|
392
|
-
Transaction.FromObject(
|
|
393
|
-
|
|
388
|
+
if (res.data.first_transaction) {
|
|
389
|
+
const { transaction, error } = Transaction.FromObject(
|
|
390
|
+
res.data.first_transaction,
|
|
391
|
+
)
|
|
392
|
+
if (error) return Promise.reject(error)
|
|
393
|
+
firstTransaction = transaction
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (res.data.last_transaction) {
|
|
397
|
+
const { transaction, error: errorTwo } = Transaction.FromObject(
|
|
398
|
+
res.data.last_transaction,
|
|
399
|
+
)
|
|
400
|
+
if (errorTwo) return Promise.reject(errorTwo)
|
|
401
|
+
lastTransaction = transaction
|
|
402
|
+
}
|
|
394
403
|
|
|
395
404
|
return {
|
|
396
405
|
chain_name: res.data.chain_name,
|
|
397
406
|
chain_version: res.data.chain_version,
|
|
398
407
|
first_block_height: res.data.first_block_height,
|
|
399
|
-
first_transaction:
|
|
408
|
+
first_transaction: firstTransaction,
|
|
400
409
|
last_block_height: res.data.last_block_height,
|
|
401
410
|
last_transaction: lastTransaction,
|
|
402
411
|
total_count: res.total_count,
|
package/package.json
CHANGED
package/transaction.d.ts
CHANGED
|
@@ -69,7 +69,10 @@ export declare class Transaction {
|
|
|
69
69
|
inserted_at,
|
|
70
70
|
additionalData,
|
|
71
71
|
cipherData,
|
|
72
|
+
chainName,
|
|
73
|
+
chainVersion,
|
|
72
74
|
}?: Record<string, any>)
|
|
75
|
+
get Order(): number
|
|
73
76
|
get ID(): string
|
|
74
77
|
get Height(): number
|
|
75
78
|
get Version(): number
|
|
@@ -83,10 +86,13 @@ export declare class Transaction {
|
|
|
83
86
|
get Fee(): number
|
|
84
87
|
get Hash(): string
|
|
85
88
|
get InsertedAt(): Date
|
|
89
|
+
get ChainName(): string
|
|
90
|
+
get ChainVersion(): string
|
|
86
91
|
static FromJSON(value: string): { transaction?: Transaction; error?: Error }
|
|
87
92
|
static FromObject(obj: Record<string, any>): {
|
|
88
93
|
transaction?: Transaction
|
|
89
94
|
error?: Error
|
|
90
95
|
}
|
|
91
96
|
ToJSON(): string
|
|
97
|
+
ToObject(): Record<string, any>
|
|
92
98
|
}
|
package/transaction.js
CHANGED
|
@@ -121,6 +121,8 @@ export class Transaction {
|
|
|
121
121
|
_fee
|
|
122
122
|
_hash
|
|
123
123
|
_inserted_at
|
|
124
|
+
_chainName
|
|
125
|
+
_chainVersion
|
|
124
126
|
|
|
125
127
|
/**
|
|
126
128
|
* @param {string} id
|
|
@@ -136,6 +138,8 @@ export class Transaction {
|
|
|
136
138
|
* @param {Date} inserted_at
|
|
137
139
|
* @param {?string} additionalData
|
|
138
140
|
* @param {?string} cipherData
|
|
141
|
+
* @param {?string} chainName
|
|
142
|
+
* @param {?string} chainVersion
|
|
139
143
|
* @throws Error
|
|
140
144
|
*/
|
|
141
145
|
constructor({
|
|
@@ -152,6 +156,8 @@ export class Transaction {
|
|
|
152
156
|
inserted_at,
|
|
153
157
|
additionalData = null,
|
|
154
158
|
cipherData = null,
|
|
159
|
+
chainName = null,
|
|
160
|
+
chainVersion = null,
|
|
155
161
|
} = {}) {
|
|
156
162
|
this._id = id
|
|
157
163
|
this._height = height
|
|
@@ -166,6 +172,12 @@ export class Transaction {
|
|
|
166
172
|
this._inserted_at = inserted_at
|
|
167
173
|
if (additionalData) this._additionalData = additionalData
|
|
168
174
|
if (cipherData) this._cipherData = cipherData
|
|
175
|
+
if (chainName) this._chainName = chainName
|
|
176
|
+
if (chainVersion) this._chainVersion = chainVersion
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get Order() {
|
|
180
|
+
return this._order
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
get ID() {
|
|
@@ -220,26 +232,48 @@ export class Transaction {
|
|
|
220
232
|
return this._inserted_at
|
|
221
233
|
}
|
|
222
234
|
|
|
235
|
+
get ChainName() {
|
|
236
|
+
return this._chainName
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
get ChainVersion() {
|
|
240
|
+
return this._chainVersion
|
|
241
|
+
}
|
|
242
|
+
|
|
223
243
|
static FromJSON(value) {
|
|
244
|
+
if (typeof value !== 'string')
|
|
245
|
+
return {
|
|
246
|
+
transaction: null,
|
|
247
|
+
error: new Error('invalid json payload'),
|
|
248
|
+
}
|
|
249
|
+
|
|
224
250
|
try {
|
|
225
251
|
const parsed = JSON.parse(value),
|
|
226
252
|
tx = new Transaction()
|
|
227
253
|
|
|
228
|
-
if (parsed.order) tx._order = parsed.order
|
|
254
|
+
if (typeof parsed.order !== 'undefined') tx._order = parsed.order
|
|
229
255
|
tx._id = parsed.id
|
|
230
256
|
tx._typ = parsed.typ
|
|
231
|
-
if (parsed.identifier
|
|
257
|
+
if (typeof parsed.identifier !== 'undefined')
|
|
258
|
+
tx._identifier = parsed.identifier
|
|
232
259
|
tx._height = parsed.height
|
|
233
260
|
tx._version = parsed.version
|
|
234
261
|
tx._sender_addr = parsed.sender_addr
|
|
235
262
|
tx._recipient_addr = parsed.recipient_addr
|
|
236
263
|
tx._data = parsed.data
|
|
237
|
-
if (parsed.additional_data
|
|
238
|
-
|
|
264
|
+
if (typeof parsed.additional_data !== 'undefined')
|
|
265
|
+
tx._additionalData = parsed.additional_data
|
|
266
|
+
if (typeof parsed.cipher_data !== 'undefined')
|
|
267
|
+
tx._cipherData = parsed.cipher_data
|
|
239
268
|
tx._sign = parsed.sign
|
|
240
269
|
tx._fee = parsed.fee
|
|
241
270
|
tx._hash = parsed.hash
|
|
242
|
-
|
|
271
|
+
if (typeof parsed.inserted_at !== 'undefined')
|
|
272
|
+
tx._inserted_at = new Date(parsed.inserted_at)
|
|
273
|
+
if (typeof parsed.chain_name !== 'undefined')
|
|
274
|
+
this._chainName = parsed.chain_name
|
|
275
|
+
if (typeof parsed.chain_version !== 'undefined')
|
|
276
|
+
this._chainVersion = parsed.chain_version
|
|
243
277
|
|
|
244
278
|
return { transaction: tx, error: null }
|
|
245
279
|
} catch (e) {
|
|
@@ -248,24 +282,37 @@ export class Transaction {
|
|
|
248
282
|
}
|
|
249
283
|
|
|
250
284
|
static FromObject(obj) {
|
|
285
|
+
if (!obj)
|
|
286
|
+
return {
|
|
287
|
+
transaction: null,
|
|
288
|
+
error: new Error('invalid obj payload'),
|
|
289
|
+
}
|
|
290
|
+
|
|
251
291
|
try {
|
|
252
292
|
const tx = new Transaction()
|
|
253
293
|
|
|
254
|
-
if (obj.order) tx._order = obj.order
|
|
294
|
+
if (typeof obj.order !== 'undefined') tx._order = obj.order
|
|
255
295
|
tx._id = obj.id
|
|
256
296
|
tx._typ = obj.typ
|
|
257
|
-
if (obj.identifier) tx._identifier = obj.identifier
|
|
297
|
+
if (typeof obj.identifier !== 'undefined') tx._identifier = obj.identifier
|
|
258
298
|
tx._height = obj.height
|
|
259
299
|
tx._version = obj.version
|
|
260
300
|
tx._sender_addr = obj.sender_addr
|
|
261
301
|
tx._recipient_addr = obj.recipient_addr
|
|
262
302
|
tx._data = obj.data
|
|
263
|
-
if (obj.additional_data
|
|
264
|
-
|
|
303
|
+
if (typeof obj.additional_data !== 'undefined')
|
|
304
|
+
tx._additionalData = obj.additional_data
|
|
305
|
+
if (typeof obj.cipher_data !== 'undefined')
|
|
306
|
+
tx._cipherData = obj.cipher_data
|
|
265
307
|
tx._sign = obj.sign
|
|
266
308
|
tx._fee = obj.fee
|
|
267
309
|
tx._hash = obj.hash
|
|
268
|
-
|
|
310
|
+
if (typeof obj.inserted_at !== 'undefined')
|
|
311
|
+
tx._inserted_at = new Date(obj.inserted_at)
|
|
312
|
+
if (typeof obj.chain_name !== 'undefined')
|
|
313
|
+
this._chainName = obj.chain_name
|
|
314
|
+
if (typeof obj.chain_version !== 'undefined')
|
|
315
|
+
this._chainVersion = obj.chain_version
|
|
269
316
|
|
|
270
317
|
return { transaction: tx, error: null }
|
|
271
318
|
} catch (e) {
|
|
@@ -291,14 +338,48 @@ export class Transaction {
|
|
|
291
338
|
sign: this._sign,
|
|
292
339
|
fee: this._fee,
|
|
293
340
|
hash: this._hash,
|
|
294
|
-
|
|
341
|
+
...(this._inserted_at
|
|
342
|
+
? { inserted_at: this._inserted_at.toISOString() }
|
|
343
|
+
: {}),
|
|
295
344
|
...(this._additionalData
|
|
296
345
|
? { additional_data: this._additionalData }
|
|
297
346
|
: {}),
|
|
298
347
|
...(this._cipherData ? { cipher_data: this._cipherData } : {}),
|
|
348
|
+
...(this._chainName ? { chain_name: this._chainName } : {}),
|
|
349
|
+
...(this._chainVersion ? { chain_version: this._chainVersion } : {}),
|
|
299
350
|
})
|
|
300
351
|
}
|
|
301
352
|
|
|
353
|
+
/**
|
|
354
|
+
* @return {Object<string, *>}
|
|
355
|
+
* @throws Error
|
|
356
|
+
*/
|
|
357
|
+
ToObject() {
|
|
358
|
+
this.Validate()
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
id: this._id,
|
|
362
|
+
height: this._height,
|
|
363
|
+
version: this._version,
|
|
364
|
+
typ: this._typ,
|
|
365
|
+
sender_addr: this._sender_addr,
|
|
366
|
+
recipient_addr: this._recipient_addr,
|
|
367
|
+
data: this._data,
|
|
368
|
+
sign: this._sign,
|
|
369
|
+
fee: this._fee,
|
|
370
|
+
hash: this._hash,
|
|
371
|
+
...(this._inserted_at
|
|
372
|
+
? { inserted_at: this._inserted_at.toISOString() }
|
|
373
|
+
: {}),
|
|
374
|
+
...(this._additionalData
|
|
375
|
+
? { additional_data: this._additionalData }
|
|
376
|
+
: {}),
|
|
377
|
+
...(this._cipherData ? { cipher_data: this._cipherData } : {}),
|
|
378
|
+
...(this._chainName ? { chain_name: this._chainName } : {}),
|
|
379
|
+
...(this._chainVersion ? { chain_version: this._chainVersion } : {}),
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
302
383
|
Validate() {
|
|
303
384
|
if (typeof this._id === 'undefined')
|
|
304
385
|
throw new Error(INVALID_ARGUMENT_WITH_CS('id'))
|
|
@@ -314,23 +395,23 @@ export class Transaction {
|
|
|
314
395
|
throw new Error(INVALID_ARGUMENT_WITH_CS('senderAddr'))
|
|
315
396
|
if (typeof this._recipient_addr !== 'string')
|
|
316
397
|
throw new Error(INVALID_ARGUMENT_WITH_CS('recipientAddr'))
|
|
317
|
-
if (typeof this._data
|
|
398
|
+
if (typeof this._data === 'undefined')
|
|
318
399
|
throw new Error(INVALID_ARGUMENT_WITH_CS('data'))
|
|
319
|
-
if (
|
|
320
|
-
typeof this._additionalData !== 'undefined' &&
|
|
321
|
-
typeof this._additionalData !== 'string'
|
|
322
|
-
)
|
|
323
|
-
throw new Error(INVALID_ARGUMENT_WITH_CS('additionalData'))
|
|
324
|
-
if (
|
|
325
|
-
typeof this._cipherData !== 'undefined' &&
|
|
326
|
-
typeof this._cipherData !== 'string'
|
|
327
|
-
)
|
|
328
|
-
throw new Error(INVALID_ARGUMENT_WITH_CS('cipherData'))
|
|
329
|
-
if (typeof this._sign !== 'object')
|
|
400
|
+
if (typeof this._sign === 'undefined')
|
|
330
401
|
throw new Error(INVALID_ARGUMENT_WITH_CS('sign'))
|
|
331
402
|
if (typeof this._fee !== 'number')
|
|
332
403
|
throw new Error(INVALID_ARGUMENT_WITH_CS('fee'))
|
|
333
|
-
if (!(this._inserted_at instanceof Date))
|
|
404
|
+
if (this._inserted_at && !(this._inserted_at instanceof Date))
|
|
334
405
|
throw new Error(INVALID_ARGUMENT_WITH_CS('insertedAt'))
|
|
406
|
+
if (
|
|
407
|
+
typeof this._chainName !== 'undefined' &&
|
|
408
|
+
typeof this._chainName !== 'string'
|
|
409
|
+
)
|
|
410
|
+
throw new Error(INVALID_ARGUMENT_WITH_CS('chainName'))
|
|
411
|
+
if (
|
|
412
|
+
typeof this._chainVersion !== 'undefined' &&
|
|
413
|
+
typeof this._chainVersion !== 'string'
|
|
414
|
+
)
|
|
415
|
+
throw new Error(INVALID_ARGUMENT_WITH_CS('chainVersion'))
|
|
335
416
|
}
|
|
336
417
|
}
|
package/websocketOptions.js
CHANGED