quantum-coin-js-sdk 1.0.13 → 1.0.14
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/README.md +48 -3
- package/example/example.js +3 -2
- package/index.js +233 -172
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Quantum Coin JS SDK provides functionality to interact with the Quantum Coin Blo
|
|
|
5
5
|
|
|
6
6
|
**Example**
|
|
7
7
|
```js
|
|
8
|
-
Installation:
|
|
9
8
|
|
|
10
9
|
|
|
10
|
+
Requires Node.js version v20.18.1 or higher
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
* [quantum-coin-js-sdk](#module_quantum-coin-js-sdk)
|
|
@@ -28,6 +28,7 @@ Installation:
|
|
|
28
28
|
* [.blockDetails](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+blockDetails) : <code>BlockDetails</code>
|
|
29
29
|
* [.response](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+response) : <code>Object</code>
|
|
30
30
|
* [.requestId](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+requestId) : <code>string</code>
|
|
31
|
+
* [.err](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+err) : <code>error</code>
|
|
31
32
|
* [~AccountDetails](#module_quantum-coin-js-sdk..AccountDetails)
|
|
32
33
|
* [.address](#module_quantum-coin-js-sdk..AccountDetails+address) : <code>string</code>
|
|
33
34
|
* [.balance](#module_quantum-coin-js-sdk..AccountDetails+balance) : <code>string</code>
|
|
@@ -38,6 +39,7 @@ Installation:
|
|
|
38
39
|
* [.accountDetails](#module_quantum-coin-js-sdk..AccountDetailsResult+accountDetails) : <code>AccountDetails</code>
|
|
39
40
|
* [.response](#module_quantum-coin-js-sdk..AccountDetailsResult+response) : <code>Object</code>
|
|
40
41
|
* [.requestId](#module_quantum-coin-js-sdk..AccountDetailsResult+requestId) : <code>string</code>
|
|
42
|
+
* [.err](#module_quantum-coin-js-sdk..AccountDetailsResult+err) : <code>error</code>
|
|
41
43
|
* [~SignResult](#module_quantum-coin-js-sdk..SignResult)
|
|
42
44
|
* [.resultCode](#module_quantum-coin-js-sdk..SignResult+resultCode) : <code>number</code>
|
|
43
45
|
* [.txnHash](#module_quantum-coin-js-sdk..SignResult+txnHash) : <code>string</code>
|
|
@@ -47,6 +49,7 @@ Installation:
|
|
|
47
49
|
* [.txnHash](#module_quantum-coin-js-sdk..SendResult+txnHash) : <code>string</code>
|
|
48
50
|
* [.response](#module_quantum-coin-js-sdk..SendResult+response) : <code>Object</code>
|
|
49
51
|
* [.requestId](#module_quantum-coin-js-sdk..SendResult+requestId) : <code>string</code>
|
|
52
|
+
* [.err](#module_quantum-coin-js-sdk..SendResult+err) : <code>error</code>
|
|
50
53
|
* [~TransactionReceipt](#module_quantum-coin-js-sdk..TransactionReceipt)
|
|
51
54
|
* [.cumulativeGasUsed](#module_quantum-coin-js-sdk..TransactionReceipt+cumulativeGasUsed) : <code>string</code>
|
|
52
55
|
* [.effectiveGasPrice](#module_quantum-coin-js-sdk..TransactionReceipt+effectiveGasPrice) : <code>string</code>
|
|
@@ -71,6 +74,7 @@ Installation:
|
|
|
71
74
|
* [.transactionDetails](#module_quantum-coin-js-sdk..TransactionDetailsResult+transactionDetails) : <code>TransactionDetails</code>
|
|
72
75
|
* [.response](#module_quantum-coin-js-sdk..TransactionDetailsResult+response) : <code>Object</code>
|
|
73
76
|
* [.requestId](#module_quantum-coin-js-sdk..TransactionDetailsResult+requestId) : <code>string</code>
|
|
77
|
+
* [.err](#module_quantum-coin-js-sdk..TransactionDetailsResult+err) : <code>error</code>
|
|
74
78
|
* [~AccountTransactionCompact](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
75
79
|
* [.blockNumber](#module_quantum-coin-js-sdk..AccountTransactionCompact+blockNumber) : <code>number</code>
|
|
76
80
|
* [.from](#module_quantum-coin-js-sdk..AccountTransactionCompact+from) : <code>string</code>
|
|
@@ -86,6 +90,7 @@ Installation:
|
|
|
86
90
|
* [.listAccountTransactionsResponse](#module_quantum-coin-js-sdk..AccountTransactionsResult+listAccountTransactionsResponse) : <code>ListAccountTransactionsResponse</code>
|
|
87
91
|
* [.response](#module_quantum-coin-js-sdk..AccountTransactionsResult+response) : <code>Object</code>
|
|
88
92
|
* [.requestId](#module_quantum-coin-js-sdk..AccountTransactionsResult+requestId) : <code>string</code>
|
|
93
|
+
* [.err](#module_quantum-coin-js-sdk..AccountTransactionsResult+err) : <code>error</code>
|
|
89
94
|
* [~initialize(clientConfig)](#module_quantum-coin-js-sdk..initialize) ⇒ <code>Promise.<boolean></code>
|
|
90
95
|
* [~isAddressValid(address)](#module_quantum-coin-js-sdk..isAddressValid) ⇒ <code>boolean</code>
|
|
91
96
|
* [~newWallet()](#module_quantum-coin-js-sdk..newWallet) ⇒ <code>Wallet</code>
|
|
@@ -239,6 +244,7 @@ This class represents a result from invoking the getLatestBlock function.
|
|
|
239
244
|
* [.blockDetails](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+blockDetails) : <code>BlockDetails</code>
|
|
240
245
|
* [.response](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+response) : <code>Object</code>
|
|
241
246
|
* [.requestId](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+requestId) : <code>string</code>
|
|
247
|
+
* [.err](#module_quantum-coin-js-sdk..LatestBlockDetailsResult+err) : <code>error</code>
|
|
242
248
|
|
|
243
249
|
<a name="module_quantum-coin-js-sdk..LatestBlockDetailsResult+resultCode"></a>
|
|
244
250
|
|
|
@@ -266,6 +272,13 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
266
272
|
#### latestBlockDetailsResult.requestId : <code>string</code>
|
|
267
273
|
An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
268
274
|
|
|
275
|
+
**Kind**: instance property of [<code>LatestBlockDetailsResult</code>](#module_quantum-coin-js-sdk..LatestBlockDetailsResult)
|
|
276
|
+
**Access**: public
|
|
277
|
+
<a name="module_quantum-coin-js-sdk..LatestBlockDetailsResult+err"></a>
|
|
278
|
+
|
|
279
|
+
#### latestBlockDetailsResult.err : <code>error</code>
|
|
280
|
+
An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
281
|
+
|
|
269
282
|
**Kind**: instance property of [<code>LatestBlockDetailsResult</code>](#module_quantum-coin-js-sdk..LatestBlockDetailsResult)
|
|
270
283
|
**Access**: public
|
|
271
284
|
<a name="module_quantum-coin-js-sdk..AccountDetails"></a>
|
|
@@ -323,6 +336,7 @@ This class represents a result from invoking the getAccountDetails function.
|
|
|
323
336
|
* [.accountDetails](#module_quantum-coin-js-sdk..AccountDetailsResult+accountDetails) : <code>AccountDetails</code>
|
|
324
337
|
* [.response](#module_quantum-coin-js-sdk..AccountDetailsResult+response) : <code>Object</code>
|
|
325
338
|
* [.requestId](#module_quantum-coin-js-sdk..AccountDetailsResult+requestId) : <code>string</code>
|
|
339
|
+
* [.err](#module_quantum-coin-js-sdk..AccountDetailsResult+err) : <code>error</code>
|
|
326
340
|
|
|
327
341
|
<a name="module_quantum-coin-js-sdk..AccountDetailsResult+resultCode"></a>
|
|
328
342
|
|
|
@@ -350,6 +364,13 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
350
364
|
#### accountDetailsResult.requestId : <code>string</code>
|
|
351
365
|
An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
352
366
|
|
|
367
|
+
**Kind**: instance property of [<code>AccountDetailsResult</code>](#module_quantum-coin-js-sdk..AccountDetailsResult)
|
|
368
|
+
**Access**: public
|
|
369
|
+
<a name="module_quantum-coin-js-sdk..AccountDetailsResult+err"></a>
|
|
370
|
+
|
|
371
|
+
#### accountDetailsResult.err : <code>error</code>
|
|
372
|
+
An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
373
|
+
|
|
353
374
|
**Kind**: instance property of [<code>AccountDetailsResult</code>](#module_quantum-coin-js-sdk..AccountDetailsResult)
|
|
354
375
|
**Access**: public
|
|
355
376
|
<a name="module_quantum-coin-js-sdk..SignResult"></a>
|
|
@@ -399,6 +420,7 @@ This class represents a result from invoking the sendCoins function.
|
|
|
399
420
|
* [.txnHash](#module_quantum-coin-js-sdk..SendResult+txnHash) : <code>string</code>
|
|
400
421
|
* [.response](#module_quantum-coin-js-sdk..SendResult+response) : <code>Object</code>
|
|
401
422
|
* [.requestId](#module_quantum-coin-js-sdk..SendResult+requestId) : <code>string</code>
|
|
423
|
+
* [.err](#module_quantum-coin-js-sdk..SendResult+err) : <code>error</code>
|
|
402
424
|
|
|
403
425
|
<a name="module_quantum-coin-js-sdk..SendResult+resultCode"></a>
|
|
404
426
|
|
|
@@ -426,6 +448,13 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
426
448
|
#### sendResult.requestId : <code>string</code>
|
|
427
449
|
An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
428
450
|
|
|
451
|
+
**Kind**: instance property of [<code>SendResult</code>](#module_quantum-coin-js-sdk..SendResult)
|
|
452
|
+
**Access**: public
|
|
453
|
+
<a name="module_quantum-coin-js-sdk..SendResult+err"></a>
|
|
454
|
+
|
|
455
|
+
#### sendResult.err : <code>error</code>
|
|
456
|
+
An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
457
|
+
|
|
429
458
|
**Kind**: instance property of [<code>SendResult</code>](#module_quantum-coin-js-sdk..SendResult)
|
|
430
459
|
**Access**: public
|
|
431
460
|
<a name="module_quantum-coin-js-sdk..TransactionReceipt"></a>
|
|
@@ -597,6 +626,7 @@ This class represents a result from invoking the getTransactionDetails function.
|
|
|
597
626
|
* [.transactionDetails](#module_quantum-coin-js-sdk..TransactionDetailsResult+transactionDetails) : <code>TransactionDetails</code>
|
|
598
627
|
* [.response](#module_quantum-coin-js-sdk..TransactionDetailsResult+response) : <code>Object</code>
|
|
599
628
|
* [.requestId](#module_quantum-coin-js-sdk..TransactionDetailsResult+requestId) : <code>string</code>
|
|
629
|
+
* [.err](#module_quantum-coin-js-sdk..TransactionDetailsResult+err) : <code>error</code>
|
|
600
630
|
|
|
601
631
|
<a name="module_quantum-coin-js-sdk..TransactionDetailsResult+resultCode"></a>
|
|
602
632
|
|
|
@@ -624,6 +654,13 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
624
654
|
#### transactionDetailsResult.requestId : <code>string</code>
|
|
625
655
|
An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
626
656
|
|
|
657
|
+
**Kind**: instance property of [<code>TransactionDetailsResult</code>](#module_quantum-coin-js-sdk..TransactionDetailsResult)
|
|
658
|
+
**Access**: public
|
|
659
|
+
<a name="module_quantum-coin-js-sdk..TransactionDetailsResult+err"></a>
|
|
660
|
+
|
|
661
|
+
#### transactionDetailsResult.err : <code>error</code>
|
|
662
|
+
An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
663
|
+
|
|
627
664
|
**Kind**: instance property of [<code>TransactionDetailsResult</code>](#module_quantum-coin-js-sdk..TransactionDetailsResult)
|
|
628
665
|
**Access**: public
|
|
629
666
|
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact"></a>
|
|
@@ -723,6 +760,7 @@ This class represents a result from invoking the listAccountTransactionDetails f
|
|
|
723
760
|
* [.listAccountTransactionsResponse](#module_quantum-coin-js-sdk..AccountTransactionsResult+listAccountTransactionsResponse) : <code>ListAccountTransactionsResponse</code>
|
|
724
761
|
* [.response](#module_quantum-coin-js-sdk..AccountTransactionsResult+response) : <code>Object</code>
|
|
725
762
|
* [.requestId](#module_quantum-coin-js-sdk..AccountTransactionsResult+requestId) : <code>string</code>
|
|
763
|
+
* [.err](#module_quantum-coin-js-sdk..AccountTransactionsResult+err) : <code>error</code>
|
|
726
764
|
|
|
727
765
|
<a name="module_quantum-coin-js-sdk..AccountTransactionsResult+resultCode"></a>
|
|
728
766
|
|
|
@@ -750,6 +788,13 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
750
788
|
#### accountTransactionsResult.requestId : <code>string</code>
|
|
751
789
|
An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
752
790
|
|
|
791
|
+
**Kind**: instance property of [<code>AccountTransactionsResult</code>](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
792
|
+
**Access**: public
|
|
793
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionsResult+err"></a>
|
|
794
|
+
|
|
795
|
+
#### accountTransactionsResult.err : <code>error</code>
|
|
796
|
+
An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
797
|
+
|
|
753
798
|
**Kind**: instance property of [<code>AccountTransactionsResult</code>](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
754
799
|
**Access**: public
|
|
755
800
|
<a name="module_quantum-coin-js-sdk..initialize"></a>
|
|
@@ -878,7 +923,7 @@ The listAccountTransactions function returns a list of transactions for a specif
|
|
|
878
923
|
<a name="module_quantum-coin-js-sdk..signSendCoinTransaction"></a>
|
|
879
924
|
|
|
880
925
|
### quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress, coins, nonce) ⇒ <code>SignResult</code>
|
|
881
|
-
The signSendCoinTransaction function returns a signed transaction.
|
|
926
|
+
The signSendCoinTransaction function returns a signed transaction.
|
|
882
927
|
|
|
883
928
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
884
929
|
**Returns**: <code>SignResult</code> - Returns a promise of type SignResult.
|
|
@@ -893,7 +938,7 @@ The signSendCoinTransaction function returns a signed transaction.
|
|
|
893
938
|
<a name="module_quantum-coin-js-sdk..sendCoins"></a>
|
|
894
939
|
|
|
895
940
|
### quantum-coin-js-sdk~sendCoins(wallet, toAddress, coins, nonce) ⇒ <code>Promise.<SendResult></code>
|
|
896
|
-
The sendCoins function posts a send-coin transaction to the blockchain.
|
|
941
|
+
The sendCoins function posts a send-coin transaction to the blockchain.
|
|
897
942
|
|
|
898
943
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
899
944
|
**Returns**: <code>Promise.<SendResult></code> - Returns a promise of type SendResult.
|
package/example/example.js
CHANGED
|
@@ -117,7 +117,7 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
117
117
|
|
|
118
118
|
//Get the latest block details
|
|
119
119
|
console.log("getLatestBlockDetails");
|
|
120
|
-
qcsdk.getLatestBlockDetails(
|
|
120
|
+
qcsdk.getLatestBlockDetails().then((latestBlockDetailsResult) => {
|
|
121
121
|
if (latestBlockDetailsResult === null) {
|
|
122
122
|
console.error(" getLatestBlockDetails failed : latestBlockDetailsResult is null");
|
|
123
123
|
return;
|
|
@@ -253,7 +253,8 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
253
253
|
}
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
-
//Offline sign a transaction from existing wallet. This is typically called from an offline device hosting a cold storage wallet
|
|
256
|
+
//Offline sign a transaction from existing wallet. This is typically called from an offline device hosting a cold storage wallet.
|
|
257
|
+
//Another usecase is to first store the signed transaction in a database and then later submit it using the postTransaction function.
|
|
257
258
|
let walletJsonExample = '{"address":"0xAB035828c5A9d240bB97c6136E4299150829c8dEa12908E85351e9dF6C379BB7","privateKey":"M4a/VQGhosseluM6qQv1QSbWS2GIKRiZS8up1pX5z5EkRlRxoGt6SRoUkjBfUfr8ro35Y2Pcs7HxNWnmVbCCZvipadwa+YZHvraA1kWOn/G5MOOULp2tziYbj6ZpSiqf6agTq7IDE+gn2Cgc4x3PxgM2vHXMffpSAYC0aK3ix2ZIXlsqignmdtfbL8erR9NLTqBE+mjRLxriimnb+2z3Z503ycwWEKexRcK9pGNmovgRLlMf5DoD9viNDe/2fXkw3DhoIBQIxJggoBAsCjcyxLhwIylxoiBpRKRFCYKNHCGR0yKFyjKJJIGFAbQkgwYqASAqhBIJApkMwCIIgsAMgCICQxIpIgMuYyQlA4mBjAQQCwYkICUCEThwGAMKEyhm4LiJIbUBmiZAYzKES0ZgHINAmqYMEAgwYxaJwr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XgvTFigQD5tE+AFg9GNIkfnrZfq8G29OWKvbOlqNmogKOHQSHpcUODPiv/DwpbA9O04hCHoCIINZ0b8PxZNXaC/6+e2B6AkBMCnl9TZic4bNo+vs63ydTiuvJMSpWkbt2lnrJ7iKpiSAJ17ZBsXyZQCZ1+Zwe+HEBrA0hW02xVqy+dm3D0d1fnF5D+LdaUrH6UgaUy1bYI4KVq+LTOk2dC4nKkhVlYdG2JLtu16Olq/mpbLY/WeS3svKchXo69oq4lTogVxmc5DCl2gMHqVdK+v/4A7ObhCMftGKSD9BxXurBIhP5CQlYsEVO1tOagm0p7DcAI1O5QeKOCXgL1IrwNuW5gkuRM1MUyvKwnIl8FDBOVvzZRKfBSwAum4CEn6T+ja064ldZDigVACIWl9P9m9zmLXblWcZCi9e8ym+dg=="}';
|
|
258
259
|
let walletExample = qcsdk.deserializeWallet(walletJsonExample);
|
|
259
260
|
|
package/index.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* @description Quantum Coin JS SDK provides functionality to interact with the Quantum Coin Blockchain using the Relay APIs.
|
|
7
7
|
* {@link https://github.com/quantumcoinproject/quantum-coin-js-sdk/tree/main/example|Example Project}
|
|
8
8
|
* @example
|
|
9
|
+
*
|
|
10
|
+
* Requires Node.js version v20.18.1 or higher
|
|
11
|
+
*
|
|
9
12
|
* Installation:
|
|
10
13
|
* npm install quantum-coin-js-sdk --save
|
|
11
14
|
*
|
|
@@ -152,7 +155,7 @@ class BlockDetails {
|
|
|
152
155
|
* @classdesc This class represents a result from invoking the getLatestBlock function.
|
|
153
156
|
*/
|
|
154
157
|
class LatestBlockDetailsResult {
|
|
155
|
-
constructor(resultCode, blockDetails, response, requestId) {
|
|
158
|
+
constructor(resultCode, blockDetails, response, requestId, err) {
|
|
156
159
|
/**
|
|
157
160
|
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
158
161
|
* @type {number}
|
|
@@ -180,6 +183,13 @@ class LatestBlockDetailsResult {
|
|
|
180
183
|
* @public
|
|
181
184
|
*/
|
|
182
185
|
this.requestId = requestId;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
189
|
+
* @type {error}
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
this.err = err;
|
|
183
193
|
}
|
|
184
194
|
}
|
|
185
195
|
|
|
@@ -228,7 +238,7 @@ class AccountDetails {
|
|
|
228
238
|
* @classdesc This class represents a result from invoking the getAccountDetails function.
|
|
229
239
|
*/
|
|
230
240
|
class AccountDetailsResult {
|
|
231
|
-
constructor(resultCode, accountDetails, response, requestId) {
|
|
241
|
+
constructor(resultCode, accountDetails, response, requestId, err) {
|
|
232
242
|
/**
|
|
233
243
|
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
234
244
|
* @type {number}
|
|
@@ -256,6 +266,13 @@ class AccountDetailsResult {
|
|
|
256
266
|
* @public
|
|
257
267
|
*/
|
|
258
268
|
this.requestId = requestId;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
272
|
+
* @type {error}
|
|
273
|
+
* @public
|
|
274
|
+
*/
|
|
275
|
+
this.err = err;
|
|
259
276
|
}
|
|
260
277
|
}
|
|
261
278
|
|
|
@@ -299,7 +316,7 @@ class SignResult {
|
|
|
299
316
|
* @classdesc This class represents a result from invoking the sendCoins function.
|
|
300
317
|
*/
|
|
301
318
|
class SendResult {
|
|
302
|
-
constructor(resultCode, txnHash, response, requestId) {
|
|
319
|
+
constructor(resultCode, txnHash, response, requestId, err) {
|
|
303
320
|
/**
|
|
304
321
|
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
305
322
|
* @type {number}
|
|
@@ -327,6 +344,13 @@ class SendResult {
|
|
|
327
344
|
* @public
|
|
328
345
|
*/
|
|
329
346
|
this.requestId = requestId;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
350
|
+
* @type {error}
|
|
351
|
+
* @public
|
|
352
|
+
*/
|
|
353
|
+
this.err = err;
|
|
330
354
|
}
|
|
331
355
|
}
|
|
332
356
|
|
|
@@ -478,7 +502,7 @@ class TransactionDetails {
|
|
|
478
502
|
* @classdesc This class represents a result from invoking the getTransactionDetails function. If transactions get discarded by the blockchain, for reasons such as due to lower than minimum gas fees or invalid nonce, the resultCode will always contain a non-zero value (failure).
|
|
479
503
|
*/
|
|
480
504
|
class TransactionDetailsResult {
|
|
481
|
-
constructor(resultCode, transactionDetails, response, requestId) {
|
|
505
|
+
constructor(resultCode, transactionDetails, response, requestId, err) {
|
|
482
506
|
/**
|
|
483
507
|
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
484
508
|
* @type {number}
|
|
@@ -507,6 +531,13 @@ class TransactionDetailsResult {
|
|
|
507
531
|
* @public
|
|
508
532
|
*/
|
|
509
533
|
this.requestId = requestId;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
537
|
+
* @type {error}
|
|
538
|
+
* @public
|
|
539
|
+
*/
|
|
540
|
+
this.err = err;
|
|
510
541
|
}
|
|
511
542
|
}
|
|
512
543
|
|
|
@@ -595,7 +626,7 @@ class ListAccountTransactionsResponse {
|
|
|
595
626
|
* @classdesc This class represents a result from invoking the listAccountTransactionDetails function.
|
|
596
627
|
*/
|
|
597
628
|
class AccountTransactionsResult {
|
|
598
|
-
constructor(resultCode, listAccountTransactionsResponse, response, requestId) {
|
|
629
|
+
constructor(resultCode, listAccountTransactionsResponse, response, requestId, err) {
|
|
599
630
|
/**
|
|
600
631
|
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
601
632
|
* @type {number}
|
|
@@ -623,6 +654,13 @@ class AccountTransactionsResult {
|
|
|
623
654
|
* @public
|
|
624
655
|
*/
|
|
625
656
|
this.requestId = requestId;
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
660
|
+
* @type {error}
|
|
661
|
+
* @public
|
|
662
|
+
*/
|
|
663
|
+
this.err = err;
|
|
626
664
|
}
|
|
627
665
|
}
|
|
628
666
|
|
|
@@ -902,21 +940,25 @@ async function postTransaction(txnData) {
|
|
|
902
940
|
|
|
903
941
|
let txnDataJson = JSON.stringify({ txnData: txnData });
|
|
904
942
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
943
|
+
try {
|
|
944
|
+
const response = await fetch(url, {
|
|
945
|
+
method: 'POST',
|
|
946
|
+
headers: reqHeaders,
|
|
947
|
+
body: txnDataJson
|
|
948
|
+
});
|
|
910
949
|
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
950
|
+
if (response == null) {
|
|
951
|
+
return new SendResult(-601, null, null, requestId);
|
|
952
|
+
}
|
|
914
953
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
954
|
+
if (response.status == 200 || response.status == 204) {
|
|
955
|
+
return new SendResult(0, null, response, requestId);
|
|
956
|
+
}
|
|
918
957
|
|
|
919
|
-
|
|
958
|
+
return new SendResult(-602, null, response, requestId);
|
|
959
|
+
} catch(error) {
|
|
960
|
+
return new SendResult(-10000, null, null, requestId, error);
|
|
961
|
+
}
|
|
920
962
|
}
|
|
921
963
|
|
|
922
964
|
/**
|
|
@@ -943,38 +985,42 @@ async function getLatestBlockDetails() {
|
|
|
943
985
|
|
|
944
986
|
var url = config.readUrl + "/latestblock";
|
|
945
987
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
988
|
+
try {
|
|
989
|
+
const response = await fetch(url, {
|
|
990
|
+
headers: reqHeaders,
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
if (response == null) {
|
|
994
|
+
return new LatestBlockDetailsResult(-100, null, response, requestId);
|
|
995
|
+
}
|
|
996
|
+
if (response.status !== 200) {
|
|
997
|
+
return new LatestBlockDetailsResult(-101, null, response, requestId);
|
|
998
|
+
}
|
|
949
999
|
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
}
|
|
1000
|
+
const jsonObj = await response.json();
|
|
1001
|
+
if (jsonObj == null) {
|
|
1002
|
+
return new LatestBlockDetailsResult(-102, null, response, requestId);
|
|
1003
|
+
}
|
|
1004
|
+
const result = jsonObj.result;
|
|
956
1005
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
const result = jsonObj.result;
|
|
1006
|
+
if (result == null) {
|
|
1007
|
+
return new LatestBlockDetailsResult(-103, null, response, requestId);
|
|
1008
|
+
}
|
|
962
1009
|
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1010
|
+
if (result.blockNumber == null) {
|
|
1011
|
+
return new LatestBlockDetailsResult(-104, null, response, requestId);
|
|
1012
|
+
}
|
|
966
1013
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1014
|
+
let blockNumber = parseInt(result.blockNumber);
|
|
1015
|
+
if (Number.isInteger(blockNumber) == false) {
|
|
1016
|
+
return new LatestBlockDetailsResult(-105, null, response, requestId);
|
|
1017
|
+
}
|
|
970
1018
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1019
|
+
var blockDetails = new BlockDetails(blockNumber);
|
|
1020
|
+
return new LatestBlockDetailsResult(0, blockDetails, response, requestId);
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
return new LatestBlockDetailsResult(-10000, null, null, requestId, error);
|
|
974
1023
|
}
|
|
975
|
-
|
|
976
|
-
var blockDetails = new BlockDetails(blockNumber);
|
|
977
|
-
return new LatestBlockDetailsResult(0, blockDetails, response, requestId);
|
|
978
1024
|
}
|
|
979
1025
|
|
|
980
1026
|
/**
|
|
@@ -1009,63 +1055,67 @@ async function getAccountDetails(address) {
|
|
|
1009
1055
|
reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
|
|
1010
1056
|
}
|
|
1011
1057
|
|
|
1012
|
-
|
|
1013
1058
|
var url = config.readUrl + "/account/" + address;
|
|
1014
1059
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1060
|
+
try {
|
|
1061
|
+
const response = await fetch(url, {
|
|
1062
|
+
headers: reqHeaders,
|
|
1063
|
+
});
|
|
1018
1064
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1065
|
+
if(response == null) {
|
|
1066
|
+
return new AccountDetailsResult(-202, null, response, requestId);
|
|
1067
|
+
}
|
|
1068
|
+
if (response.status !== 200) {
|
|
1069
|
+
return new AccountDetailsResult(-203, null, response, requestId);
|
|
1070
|
+
}
|
|
1025
1071
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1072
|
+
const jsonObj = await response.json();
|
|
1073
|
+
if (jsonObj == null) {
|
|
1074
|
+
return new AccountDetailsResult(-204, null, response, requestId);
|
|
1075
|
+
}
|
|
1076
|
+
const result = jsonObj.result;
|
|
1031
1077
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1078
|
+
if (result == null) {
|
|
1079
|
+
return new AccountDetailsResult(-205, null, response, requestId);
|
|
1080
|
+
}
|
|
1035
1081
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1082
|
+
if(result.blockNumber == null) {
|
|
1083
|
+
return new AccountDetailsResult(-206, null, response, requestId);
|
|
1084
|
+
}
|
|
1039
1085
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1086
|
+
let blockNumber = parseInt(result.blockNumber);
|
|
1087
|
+
if (Number.isInteger(blockNumber) == false) {
|
|
1088
|
+
return new AccountDetailsResult(-207, null, response, requestId);
|
|
1089
|
+
}
|
|
1044
1090
|
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
} else {
|
|
1048
|
-
let tempNonce = parseInt(result.nonce);
|
|
1049
|
-
if (Number.isInteger(tempNonce) == true) {
|
|
1050
|
-
nonce = tempNonce;
|
|
1051
|
-
if (nonce < 0) {
|
|
1052
|
-
return new AccountDetailsResult(-208, null, response, requestId);
|
|
1053
|
-
}
|
|
1091
|
+
if (result.nonce === null) {
|
|
1092
|
+
nonce = 0;
|
|
1054
1093
|
} else {
|
|
1055
|
-
|
|
1094
|
+
let tempNonce = parseInt(result.nonce);
|
|
1095
|
+
if (Number.isInteger(tempNonce) == true) {
|
|
1096
|
+
nonce = tempNonce;
|
|
1097
|
+
if (nonce < 0) {
|
|
1098
|
+
return new AccountDetailsResult(-208, null, response, requestId);
|
|
1099
|
+
}
|
|
1100
|
+
} else {
|
|
1101
|
+
return new AccountDetailsResult(-209, null, response, requestId);
|
|
1102
|
+
}
|
|
1056
1103
|
}
|
|
1057
|
-
}
|
|
1058
1104
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1105
|
+
if (result.balance != null) {
|
|
1106
|
+
if (isLargeNumber(result.balance) == false) {
|
|
1107
|
+
return new AccountDetailsResult(-210, null, response, requestId);
|
|
1108
|
+
} else {
|
|
1109
|
+
balance = result.balance;
|
|
1110
|
+
}
|
|
1064
1111
|
}
|
|
1065
|
-
}
|
|
1066
1112
|
|
|
1067
|
-
|
|
1068
|
-
|
|
1113
|
+
var accountDetails = new AccountDetails(address, balance, nonce, blockNumber);
|
|
1114
|
+
return new AccountDetailsResult(0, accountDetails, response, requestId);
|
|
1115
|
+
|
|
1116
|
+
} catch (error) {
|
|
1117
|
+
return new AccountDetailsResult(0, null, null, requestId, error);
|
|
1118
|
+
}
|
|
1069
1119
|
}
|
|
1070
1120
|
|
|
1071
1121
|
/**
|
|
@@ -1104,60 +1154,64 @@ async function getTransactionDetails(txnHash) {
|
|
|
1104
1154
|
|
|
1105
1155
|
var url = config.readUrl + "/transaction/" + txnHash;
|
|
1106
1156
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1157
|
+
try {
|
|
1158
|
+
const response = await fetch(url, {
|
|
1159
|
+
headers: reqHeaders,
|
|
1160
|
+
});
|
|
1110
1161
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1162
|
+
if (response == null) {
|
|
1163
|
+
return new TransactionDetailsResult(-302, null, response, requestId);
|
|
1164
|
+
}
|
|
1165
|
+
if (response.status !== 200) {
|
|
1166
|
+
return new TransactionDetailsResult(-303, null, response, requestId);
|
|
1167
|
+
}
|
|
1117
1168
|
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1169
|
+
const jsonObj = await response.json();
|
|
1170
|
+
if (jsonObj == null) {
|
|
1171
|
+
return new TransactionDetailsResult(-304, null, response, requestId);
|
|
1172
|
+
}
|
|
1173
|
+
const result = jsonObj.result;
|
|
1123
1174
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1175
|
+
if (result == null) {
|
|
1176
|
+
return new TransactionDetailsResult(-305, null, response, requestId);
|
|
1177
|
+
}
|
|
1127
1178
|
|
|
1128
|
-
|
|
1179
|
+
var transactionDetails = new TransactionDetails();
|
|
1129
1180
|
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1181
|
+
if (result.blockNumber !== null) {
|
|
1182
|
+
let tempBlockNumber = parseInt(result.blockNumber);
|
|
1183
|
+
if (Number.isInteger(tempBlockNumber) == true) {
|
|
1184
|
+
transactionDetails.blockNumber = tempBlockNumber;
|
|
1185
|
+
}
|
|
1186
|
+
if (tempBlockNumber < 0) {
|
|
1187
|
+
return new TransactionDetailsResult(-306, null, response, requestId);
|
|
1188
|
+
}
|
|
1137
1189
|
}
|
|
1138
|
-
}
|
|
1139
1190
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1191
|
+
transactionDetails.blockHash = result.blockHash;
|
|
1192
|
+
transactionDetails.from = result.from;
|
|
1193
|
+
transactionDetails.gas = result.gas;
|
|
1194
|
+
transactionDetails.gasPrice = result.gasPrice;
|
|
1195
|
+
transactionDetails.hash = result.hash;
|
|
1196
|
+
transactionDetails.input = result.input;
|
|
1197
|
+
transactionDetails.nonce = result.nonce;
|
|
1198
|
+
transactionDetails.to = result.to;
|
|
1199
|
+
transactionDetails.value = result.value;
|
|
1200
|
+
|
|
1201
|
+
if(result.receipt !== null) {
|
|
1202
|
+
transactionDetails.receipt = new TransactionReceipt();
|
|
1203
|
+
transactionDetails.receipt.cumulativeGasUsed = result.receipt.cumulativeGasUsed;
|
|
1204
|
+
transactionDetails.receipt.effectiveGasPrice = result.receipt.effectiveGasPrice;
|
|
1205
|
+
transactionDetails.receipt.gasUsed = result.receipt.gasUsed;
|
|
1206
|
+
transactionDetails.receipt.status = result.receipt.status;
|
|
1207
|
+
transactionDetails.receipt.hash = result.receipt.hash;
|
|
1208
|
+
transactionDetails.receipt.type = result.receipt.type;
|
|
1209
|
+
}
|
|
1159
1210
|
|
|
1160
|
-
|
|
1211
|
+
return new TransactionDetailsResult(0, transactionDetails, response, requestId);
|
|
1212
|
+
} catch (error) {
|
|
1213
|
+
return new TransactionDetailsResult(0, null, null, requestId, error);
|
|
1214
|
+
}
|
|
1161
1215
|
}
|
|
1162
1216
|
|
|
1163
1217
|
/**
|
|
@@ -1205,58 +1259,64 @@ async function listAccountTransactions(address, pageNumber) {
|
|
|
1205
1259
|
var url = config.readUrl + "/account/" + address + "/transactions/" + pageNumber;
|
|
1206
1260
|
console.log(url);
|
|
1207
1261
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1262
|
+
try {
|
|
1263
|
+
const response = await fetch(url, {
|
|
1264
|
+
headers: reqHeaders,
|
|
1265
|
+
});
|
|
1211
1266
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1267
|
+
if (response === null) {
|
|
1268
|
+
return new AccountTransactionsResult(-703, null, response, requestId);
|
|
1269
|
+
}
|
|
1270
|
+
if (response.status !== 200) {
|
|
1271
|
+
return new AccountTransactionsResult(-704, null, response, requestId);
|
|
1272
|
+
}
|
|
1218
1273
|
|
|
1219
|
-
|
|
1274
|
+
const jsonObj = await response.json();
|
|
1220
1275
|
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1276
|
+
if (jsonObj === null) {
|
|
1277
|
+
return new AccountTransactionsResult(-705, null, response, requestId);
|
|
1278
|
+
}
|
|
1279
|
+
const result = jsonObj;
|
|
1225
1280
|
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1281
|
+
if (result.pageCount === null) {
|
|
1282
|
+
return new AccountTransactionsResult(-706, null, response, requestId);
|
|
1283
|
+
}
|
|
1229
1284
|
|
|
1230
|
-
|
|
1285
|
+
var listAccountDetailsResponse = new ListAccountTransactionsResponse();
|
|
1231
1286
|
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1287
|
+
let tempPageCount = parseInt(result.pageCount);
|
|
1288
|
+
if (Number.isInteger(tempPageCount) === true) {
|
|
1289
|
+
listAccountDetailsResponse.pageCount = tempPageCount;
|
|
1290
|
+
}
|
|
1236
1291
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1292
|
+
if (result.items !== null) {
|
|
1293
|
+
if (Array.isArray(result.items) === false) {
|
|
1294
|
+
return new AccountTransactionsResult(-707, null, response, requestId);
|
|
1295
|
+
}
|
|
1296
|
+
listAccountDetailsResponse.items = new Array();
|
|
1297
|
+
for (const item of result.items) {
|
|
1298
|
+
let txn = new AccountTransactionCompact();
|
|
1299
|
+
txn.blockNumber = item.blockNumber;
|
|
1300
|
+
txn.from = item.from;
|
|
1301
|
+
txn.hash = item.hash;
|
|
1302
|
+
txn.to = item.to;
|
|
1303
|
+
txn.value = item.value;
|
|
1304
|
+
txn.status = item.status;
|
|
1305
|
+
listAccountDetailsResponse.items.push(txn);
|
|
1306
|
+
}
|
|
1240
1307
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
txn.hash = item.hash;
|
|
1247
|
-
txn.to = item.to;
|
|
1248
|
-
txn.value = item.value;
|
|
1249
|
-
txn.status = item.status;
|
|
1250
|
-
listAccountDetailsResponse.items.push(txn);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
return new AccountTransactionsResult(0, listAccountDetailsResponse, response, requestId);
|
|
1308
|
+
|
|
1309
|
+
return new AccountTransactionsResult(0, listAccountDetailsResponse, response, requestId);
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
return new AccountTransactionsResult(0, null, null, requestId, error);
|
|
1312
|
+
}
|
|
1255
1313
|
}
|
|
1256
1314
|
|
|
1257
1315
|
/**
|
|
1258
1316
|
* The signSendCoinTransaction function returns a signed transaction.
|
|
1317
|
+
* Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
|
|
1259
1318
|
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then use the postTransaction function to post it on a connected device.
|
|
1319
|
+
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally submit the transaction by calling the postTransaction function.
|
|
1260
1320
|
*
|
|
1261
1321
|
* @function signSendCoinTransaction
|
|
1262
1322
|
* @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
|
|
@@ -1324,6 +1384,7 @@ async function signSendCoinTransaction(wallet, toAddress, coins, nonce) {
|
|
|
1324
1384
|
|
|
1325
1385
|
/**
|
|
1326
1386
|
* The sendCoins function posts a send-coin transaction to the blockchain.
|
|
1387
|
+
* Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
|
|
1327
1388
|
* It may take many seconds after submitting a transaction before the transaction is returned by the getTransactionDetails function.
|
|
1328
1389
|
* Transactions are usually committed in less than 30 seconds.
|
|
1329
1390
|
*
|