quantum-coin-js-sdk 1.0.7 → 1.0.9
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 +152 -6
- package/example/example.js +45 -1
- package/example/package-lock.json +3 -3
- package/index.js +215 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,20 @@ Installation:
|
|
|
67
67
|
* [.resultCode](#module_quantum-coin-js-sdk..TransactionDetailsResult+resultCode) : <code>number</code>
|
|
68
68
|
* [.transactionDetails](#module_quantum-coin-js-sdk..TransactionDetailsResult+transactionDetails) : <code>TransactionDetails</code>
|
|
69
69
|
* [.response](#module_quantum-coin-js-sdk..TransactionDetailsResult+response) : <code>Object</code>
|
|
70
|
+
* [~AccountTransactionCompact](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
71
|
+
* [.blockNumber](#module_quantum-coin-js-sdk..AccountTransactionCompact+blockNumber) : <code>number</code>
|
|
72
|
+
* [.from](#module_quantum-coin-js-sdk..AccountTransactionCompact+from) : <code>string</code>
|
|
73
|
+
* [.hash](#module_quantum-coin-js-sdk..AccountTransactionCompact+hash) : <code>string</code>
|
|
74
|
+
* [.to](#module_quantum-coin-js-sdk..AccountTransactionCompact+to) : <code>string</code>
|
|
75
|
+
* [.value](#module_quantum-coin-js-sdk..AccountTransactionCompact+value) : <code>string</code>
|
|
76
|
+
* [.status](#module_quantum-coin-js-sdk..AccountTransactionCompact+status) : <code>string</code>
|
|
77
|
+
* [~ListAccountTransactionsResponse](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse)
|
|
78
|
+
* [.pageCount](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse+pageCount) : <code>number</code>
|
|
79
|
+
* [.items](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse+items) : <code>AccountTransactionCompact</code> \| <code>Array</code>
|
|
80
|
+
* [~AccountTransactionsResult](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
81
|
+
* [.resultCode](#module_quantum-coin-js-sdk..AccountTransactionsResult+resultCode) : <code>number</code>
|
|
82
|
+
* [.listAccountTransactionsResponse](#module_quantum-coin-js-sdk..AccountTransactionsResult+listAccountTransactionsResponse) : <code>ListAccountTransactionsResponse</code>
|
|
83
|
+
* [.response](#module_quantum-coin-js-sdk..AccountTransactionsResult+response) : <code>Object</code>
|
|
70
84
|
* [~initialize(clientConfig)](#module_quantum-coin-js-sdk..initialize) ⇒ <code>Promise.<boolean></code>
|
|
71
85
|
* [~isAddressValid(address)](#module_quantum-coin-js-sdk..isAddressValid) ⇒ <code>boolean</code>
|
|
72
86
|
* [~newWallet()](#module_quantum-coin-js-sdk..newWallet) ⇒ <code>Wallet</code>
|
|
@@ -77,6 +91,7 @@ Installation:
|
|
|
77
91
|
* [~getLatestBlockDetails()](#module_quantum-coin-js-sdk..getLatestBlockDetails) ⇒ <code>Promise.<BlockDetailsResult></code>
|
|
78
92
|
* [~getAccountDetails(address)](#module_quantum-coin-js-sdk..getAccountDetails) ⇒ <code>Promise.<AccountDetailsResult></code>
|
|
79
93
|
* [~getTransactionDetails(txnHash)](#module_quantum-coin-js-sdk..getTransactionDetails) ⇒ <code>Promise.<TransactionDetailsResult></code>
|
|
94
|
+
* [~listAccountTransactions(address, pageNumber)](#module_quantum-coin-js-sdk..listAccountTransactions) ⇒ <code>Promise.<ListAccountTransactionsResponse></code>
|
|
80
95
|
* [~signSendCoinTransaction(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..signSendCoinTransaction) ⇒ <code>SignResult</code>
|
|
81
96
|
* [~sendCoins(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..sendCoins) ⇒ <code>Promise.<SendResult></code>
|
|
82
97
|
|
|
@@ -387,7 +402,7 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
387
402
|
<a name="module_quantum-coin-js-sdk..TransactionReceipt"></a>
|
|
388
403
|
|
|
389
404
|
### quantum-coin-js-sdk~TransactionReceipt
|
|
390
|
-
This class represents a Receipt of a transaction that
|
|
405
|
+
This class represents a Receipt of a transaction that is registered in the blockchain. The transactionReceipt field can be null unless the transaction is registered with the blockchain.
|
|
391
406
|
|
|
392
407
|
**Kind**: inner class of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
393
408
|
**Access**: public
|
|
@@ -445,7 +460,7 @@ A hexadecimal string representing the transaction type. 0x0 is DefaultFeeTxType.
|
|
|
445
460
|
<a name="module_quantum-coin-js-sdk..TransactionDetails"></a>
|
|
446
461
|
|
|
447
462
|
### quantum-coin-js-sdk~TransactionDetails
|
|
448
|
-
This class represents
|
|
463
|
+
This class represents details of a transaction. You should consider the transaction as succeeded only if the status field of the receipt object is 0x1 (success).
|
|
449
464
|
|
|
450
465
|
**Kind**: inner class of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
451
466
|
**Access**: public
|
|
@@ -501,7 +516,7 @@ A hexadecimal string representing the gasPrice used for each paid gas, in Wei.
|
|
|
501
516
|
<a name="module_quantum-coin-js-sdk..TransactionDetails+hash"></a>
|
|
502
517
|
|
|
503
518
|
#### transactionDetails.hash : <code>string</code>
|
|
504
|
-
A hexadecimal string representing the hash of the transaction.
|
|
519
|
+
A 66 character hexadecimal string representing the hash of the transaction.
|
|
505
520
|
|
|
506
521
|
**Kind**: instance property of [<code>TransactionDetails</code>](#module_quantum-coin-js-sdk..TransactionDetails)
|
|
507
522
|
**Access**: public
|
|
@@ -563,7 +578,7 @@ Represents the result of the operation. A value of 0 represents that the operati
|
|
|
563
578
|
<a name="module_quantum-coin-js-sdk..TransactionDetailsResult+transactionDetails"></a>
|
|
564
579
|
|
|
565
580
|
#### transactionDetailsResult.transactionDetails : <code>TransactionDetails</code>
|
|
566
|
-
An object of type TransactionDetails representing the
|
|
581
|
+
An object of type TransactionDetails representing the transaction. This value is null if the value of resultCode is not 0.
|
|
567
582
|
|
|
568
583
|
**Kind**: instance property of [<code>TransactionDetailsResult</code>](#module_quantum-coin-js-sdk..TransactionDetailsResult)
|
|
569
584
|
**Access**: public
|
|
@@ -574,6 +589,124 @@ An object of representing the raw Response returned by the service. For details,
|
|
|
574
589
|
|
|
575
590
|
**Kind**: instance property of [<code>TransactionDetailsResult</code>](#module_quantum-coin-js-sdk..TransactionDetailsResult)
|
|
576
591
|
**Access**: public
|
|
592
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact"></a>
|
|
593
|
+
|
|
594
|
+
### quantum-coin-js-sdk~AccountTransactionCompact
|
|
595
|
+
This class represents a transaction of an account. You should consider the transaction as succeeded only if the status field is 0x1 (success).
|
|
596
|
+
|
|
597
|
+
**Kind**: inner class of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
598
|
+
**Access**: public
|
|
599
|
+
|
|
600
|
+
* [~AccountTransactionCompact](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
601
|
+
* [.blockNumber](#module_quantum-coin-js-sdk..AccountTransactionCompact+blockNumber) : <code>number</code>
|
|
602
|
+
* [.from](#module_quantum-coin-js-sdk..AccountTransactionCompact+from) : <code>string</code>
|
|
603
|
+
* [.hash](#module_quantum-coin-js-sdk..AccountTransactionCompact+hash) : <code>string</code>
|
|
604
|
+
* [.to](#module_quantum-coin-js-sdk..AccountTransactionCompact+to) : <code>string</code>
|
|
605
|
+
* [.value](#module_quantum-coin-js-sdk..AccountTransactionCompact+value) : <code>string</code>
|
|
606
|
+
* [.status](#module_quantum-coin-js-sdk..AccountTransactionCompact+status) : <code>string</code>
|
|
607
|
+
|
|
608
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact+blockNumber"></a>
|
|
609
|
+
|
|
610
|
+
#### accountTransactionCompact.blockNumber : <code>number</code>
|
|
611
|
+
The number of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
|
|
612
|
+
|
|
613
|
+
**Kind**: instance property of [<code>AccountTransactionCompact</code>](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
614
|
+
**Access**: public
|
|
615
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact+from"></a>
|
|
616
|
+
|
|
617
|
+
#### accountTransactionCompact.from : <code>string</code>
|
|
618
|
+
A 66 character hexadecimal string representing the address the transaction is sent from.
|
|
619
|
+
|
|
620
|
+
**Kind**: instance property of [<code>AccountTransactionCompact</code>](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
621
|
+
**Access**: public
|
|
622
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact+hash"></a>
|
|
623
|
+
|
|
624
|
+
#### accountTransactionCompact.hash : <code>string</code>
|
|
625
|
+
A 66 character hexadecimal string representing the hash of the transaction.
|
|
626
|
+
|
|
627
|
+
**Kind**: instance property of [<code>AccountTransactionCompact</code>](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
628
|
+
**Access**: public
|
|
629
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact+to"></a>
|
|
630
|
+
|
|
631
|
+
#### accountTransactionCompact.to : <code>string</code>
|
|
632
|
+
A 66 character hexadecimal string representing address the transaction is directed to.
|
|
633
|
+
|
|
634
|
+
**Kind**: instance property of [<code>AccountTransactionCompact</code>](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
635
|
+
**Access**: public
|
|
636
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact+value"></a>
|
|
637
|
+
|
|
638
|
+
#### accountTransactionCompact.value : <code>string</code>
|
|
639
|
+
A hexadecimal string representing the value sent with this transaction. The value can be 0 for smart contract transactions, since it only represents the number of coins sent.
|
|
640
|
+
|
|
641
|
+
**Kind**: instance property of [<code>AccountTransactionCompact</code>](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
642
|
+
**Access**: public
|
|
643
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionCompact+status"></a>
|
|
644
|
+
|
|
645
|
+
#### accountTransactionCompact.status : <code>string</code>
|
|
646
|
+
A hexadecimal string representing either 0x1 (success) or 0x0 (failure). Failed transactions can also incur gas fee. You should consider the transaction as succeeded only if the status value is 0x1 (success).
|
|
647
|
+
|
|
648
|
+
**Kind**: instance property of [<code>AccountTransactionCompact</code>](#module_quantum-coin-js-sdk..AccountTransactionCompact)
|
|
649
|
+
**Access**: public
|
|
650
|
+
<a name="module_quantum-coin-js-sdk..ListAccountTransactionsResponse"></a>
|
|
651
|
+
|
|
652
|
+
### quantum-coin-js-sdk~ListAccountTransactionsResponse
|
|
653
|
+
This class represents a list of account transactions returned by the listAccountTransactionDetails function.
|
|
654
|
+
|
|
655
|
+
**Kind**: inner class of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
656
|
+
**Access**: public
|
|
657
|
+
|
|
658
|
+
* [~ListAccountTransactionsResponse](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse)
|
|
659
|
+
* [.pageCount](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse+pageCount) : <code>number</code>
|
|
660
|
+
* [.items](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse+items) : <code>AccountTransactionCompact</code> \| <code>Array</code>
|
|
661
|
+
|
|
662
|
+
<a name="module_quantum-coin-js-sdk..ListAccountTransactionsResponse+pageCount"></a>
|
|
663
|
+
|
|
664
|
+
#### listAccountTransactionsResponse.pageCount : <code>number</code>
|
|
665
|
+
The number of pages available for listing.
|
|
666
|
+
|
|
667
|
+
**Kind**: instance property of [<code>ListAccountTransactionsResponse</code>](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse)
|
|
668
|
+
**Access**: public
|
|
669
|
+
<a name="module_quantum-coin-js-sdk..ListAccountTransactionsResponse+items"></a>
|
|
670
|
+
|
|
671
|
+
#### listAccountTransactionsResponse.items : <code>AccountTransactionCompact</code> \| <code>Array</code>
|
|
672
|
+
An array of type AccountTransactionCompact, containing the list of transactions. Can be null if no items are available.
|
|
673
|
+
|
|
674
|
+
**Kind**: instance property of [<code>ListAccountTransactionsResponse</code>](#module_quantum-coin-js-sdk..ListAccountTransactionsResponse)
|
|
675
|
+
**Access**: public
|
|
676
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionsResult"></a>
|
|
677
|
+
|
|
678
|
+
### quantum-coin-js-sdk~AccountTransactionsResult
|
|
679
|
+
This class represents a result from invoking the listAccountTransactionDetails function.
|
|
680
|
+
|
|
681
|
+
**Kind**: inner class of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
682
|
+
**Access**: public
|
|
683
|
+
|
|
684
|
+
* [~AccountTransactionsResult](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
685
|
+
* [.resultCode](#module_quantum-coin-js-sdk..AccountTransactionsResult+resultCode) : <code>number</code>
|
|
686
|
+
* [.listAccountTransactionsResponse](#module_quantum-coin-js-sdk..AccountTransactionsResult+listAccountTransactionsResponse) : <code>ListAccountTransactionsResponse</code>
|
|
687
|
+
* [.response](#module_quantum-coin-js-sdk..AccountTransactionsResult+response) : <code>Object</code>
|
|
688
|
+
|
|
689
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionsResult+resultCode"></a>
|
|
690
|
+
|
|
691
|
+
#### accountTransactionsResult.resultCode : <code>number</code>
|
|
692
|
+
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.
|
|
693
|
+
|
|
694
|
+
**Kind**: instance property of [<code>AccountTransactionsResult</code>](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
695
|
+
**Access**: public
|
|
696
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionsResult+listAccountTransactionsResponse"></a>
|
|
697
|
+
|
|
698
|
+
#### accountTransactionsResult.listAccountTransactionsResponse : <code>ListAccountTransactionsResponse</code>
|
|
699
|
+
An object of type ListAccountTransactionsResponse representing the list of transactions along with metadata. This value is null if the value of resultCode is not 0.
|
|
700
|
+
|
|
701
|
+
**Kind**: instance property of [<code>AccountTransactionsResult</code>](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
702
|
+
**Access**: public
|
|
703
|
+
<a name="module_quantum-coin-js-sdk..AccountTransactionsResult+response"></a>
|
|
704
|
+
|
|
705
|
+
#### accountTransactionsResult.response : <code>Object</code>
|
|
706
|
+
An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
707
|
+
|
|
708
|
+
**Kind**: instance property of [<code>AccountTransactionsResult</code>](#module_quantum-coin-js-sdk..AccountTransactionsResult)
|
|
709
|
+
**Access**: public
|
|
577
710
|
<a name="module_quantum-coin-js-sdk..initialize"></a>
|
|
578
711
|
|
|
579
712
|
### quantum-coin-js-sdk~initialize(clientConfig) ⇒ <code>Promise.<boolean></code>
|
|
@@ -647,7 +780,7 @@ The deserializeWallet function creates a Wallet object from a JSON string.
|
|
|
647
780
|
The postTransaction function posts a signed transaction to the blockchain.
|
|
648
781
|
|
|
649
782
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
650
|
-
**Returns**: <code>Promise.<SendResult></code> - Returns a promise of type SendResult.
|
|
783
|
+
**Returns**: <code>Promise.<SendResult></code> - Returns a promise of type SendResult. txnHash will be null in SendResult.
|
|
651
784
|
|
|
652
785
|
| Param | Type | Description |
|
|
653
786
|
| --- | --- | --- |
|
|
@@ -675,7 +808,7 @@ The getAccountDetails function returns details of an account corresponding to th
|
|
|
675
808
|
<a name="module_quantum-coin-js-sdk..getTransactionDetails"></a>
|
|
676
809
|
|
|
677
810
|
### quantum-coin-js-sdk~getTransactionDetails(txnHash) ⇒ <code>Promise.<TransactionDetailsResult></code>
|
|
678
|
-
The getTransactionDetails function returns details of a transaction posted to the blockchain.
|
|
811
|
+
The getTransactionDetails function returns details of a transaction posted to the blockchain.
|
|
679
812
|
|
|
680
813
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
681
814
|
**Returns**: <code>Promise.<TransactionDetailsResult></code> - Returns a promise of type type TransactionDetailsResult.
|
|
@@ -684,6 +817,19 @@ The getTransactionDetails function returns details of a transaction posted to th
|
|
|
684
817
|
| --- | --- | --- |
|
|
685
818
|
| txnHash | <code>string</code> | The hash of the transaction to retrieve. |
|
|
686
819
|
|
|
820
|
+
<a name="module_quantum-coin-js-sdk..listAccountTransactions"></a>
|
|
821
|
+
|
|
822
|
+
### quantum-coin-js-sdk~listAccountTransactions(address, pageNumber) ⇒ <code>Promise.<ListAccountTransactionsResponse></code>
|
|
823
|
+
The listAccountTransactions function returns a list of transactions for a specific account.
|
|
824
|
+
|
|
825
|
+
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
826
|
+
**Returns**: <code>Promise.<ListAccountTransactionsResponse></code> - Returns a promise of type type ListAccountTransactionsResponse.
|
|
827
|
+
|
|
828
|
+
| Param | Type | Description |
|
|
829
|
+
| --- | --- | --- |
|
|
830
|
+
| address | <code>string</code> | The address for which the transactions have to be listed. |
|
|
831
|
+
| pageNumber | <code>number</code> | The page number for which the transactions has to be listed for the account. Pass 0 to list the latest page. |
|
|
832
|
+
|
|
687
833
|
<a name="module_quantum-coin-js-sdk..signSendCoinTransaction"></a>
|
|
688
834
|
|
|
689
835
|
### quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress, coins, nonce) ⇒ <code>SignResult</code>
|
package/example/example.js
CHANGED
|
@@ -17,7 +17,6 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
17
17
|
}
|
|
18
18
|
console.log("Initialize succeeded");
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
//Get the account details
|
|
22
21
|
let address = "0x0000000000000000000000000000000000000000000000000000000000001000"; //Just an example address https://t4.scan.quantumcoin.org/account/0x0000000000000000000000000000000000000000000000000000000000001000
|
|
23
22
|
|
|
@@ -192,5 +191,50 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
192
191
|
console.log(" sendCoin succeeded. This does not necessarily mean that the transaction has succeded. txnHash " + sendResult.txnHash);
|
|
193
192
|
});
|
|
194
193
|
});
|
|
194
|
+
|
|
195
|
+
//List transactions of an account
|
|
196
|
+
let address = "0x0000000000000000000000000000000000000000000000000000000000002000";
|
|
197
|
+
let pageNumber = 0; //zero is default for latest page
|
|
198
|
+
qcsdk.listAccountTransactions(address, pageNumber).then((accountTransactionsResult) => {
|
|
199
|
+
if (accountTransactionsResult === null) {
|
|
200
|
+
console.error(" listAccountTransactions failed : accountTransactionsResult is null");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (accountTransactionsResult.resultCode !== 0) {
|
|
205
|
+
console.log(" listAccountTransactions failed. resultCode is " + accountTransactionsResult.resultCode);
|
|
206
|
+
console.log(accountTransactionsResult.response.status);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (accountTransactionsResult.listAccountTransactionsResponse === null) {
|
|
211
|
+
console.error(" listAccountTransactions failed : listAccountTransactionsResponse is null");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (accountTransactionsResult.listAccountTransactionsResponse.pageCount === null) {
|
|
216
|
+
console.error(" listAccountTransactions failed : pageCount is null");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (accountTransactionsResult.listAccountTransactionsResponse.items === null) {
|
|
221
|
+
console.error(" listAccountTransactions : items is null, no items to list");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let txnList = accountTransactionsResult.listAccountTransactionsResponse.items;
|
|
226
|
+
|
|
227
|
+
console.log(" Account address: " + address);
|
|
228
|
+
console.log(" Page Count: " + accountTransactionsResult.listAccountTransactionsResponse.pageCount);
|
|
229
|
+
console.log(" Number of transactions returned: " + txnList.length);
|
|
230
|
+
for (const txn of txnList) {
|
|
231
|
+
console.log(" Transaction Hash: " + txn.hash);
|
|
232
|
+
console.log(" From Address: " + txn.from);
|
|
233
|
+
console.log(" To Address: " + txn.to);
|
|
234
|
+
console.log(" Value: " + txn.value);
|
|
235
|
+
console.log(" Status: " + txn.status);
|
|
236
|
+
console.log(" Block Number: " + txn.blockNumber);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
195
239
|
});
|
|
196
240
|
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"integrity": "sha512-7Q5YlFvaXoP+MK+yn4KH4MYvJDkyGoGUU/zKYsRxR1mVqddqGUsGvz2JTsfH5B/Gkk97gMMh3PQ7MmkM8iJA5Q=="
|
|
87
87
|
},
|
|
88
88
|
"node_modules/quantum-coin-js-sdk": {
|
|
89
|
-
"version": "1.0.
|
|
90
|
-
"resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.
|
|
91
|
-
"integrity": "sha512-
|
|
89
|
+
"version": "1.0.8",
|
|
90
|
+
"resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.8.tgz",
|
|
91
|
+
"integrity": "sha512-7DYUWqxoB6fUO4nv07ZlgxF4tepyvqL3G2pbINQvVaDSjxDcfu2zr/gD5/rZ4zqPBW3hY9jrD7lJdZifmKrlDQ==",
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"pqc-js-sdk": "^1.0.0"
|
|
94
94
|
}
|
package/index.js
CHANGED
|
@@ -313,7 +313,7 @@ class SendResult {
|
|
|
313
313
|
* @class
|
|
314
314
|
* @constructor
|
|
315
315
|
* @public
|
|
316
|
-
* @classdesc This class represents a Receipt of a transaction that
|
|
316
|
+
* @classdesc This class represents a Receipt of a transaction that is registered in the blockchain. The transactionReceipt field can be null unless the transaction is registered with the blockchain.
|
|
317
317
|
* While the transaction is pending, this field will be null. You should consider the transaction as succeeded only if the status field's value is 0x1 (success).
|
|
318
318
|
*/
|
|
319
319
|
class TransactionReceipt {
|
|
@@ -366,7 +366,7 @@ class TransactionReceipt {
|
|
|
366
366
|
* @class
|
|
367
367
|
* @constructor
|
|
368
368
|
* @public
|
|
369
|
-
* @classdesc This class represents
|
|
369
|
+
* @classdesc This class represents details of a transaction. You should consider the transaction as succeeded only if the status field of the receipt object is 0x1 (success).
|
|
370
370
|
*/
|
|
371
371
|
class TransactionDetails {
|
|
372
372
|
constructor() {
|
|
@@ -406,7 +406,7 @@ class TransactionDetails {
|
|
|
406
406
|
this.gasPrice = null;
|
|
407
407
|
|
|
408
408
|
/**
|
|
409
|
-
* A hexadecimal string representing the hash of the transaction.
|
|
409
|
+
* A 66 character hexadecimal string representing the hash of the transaction.
|
|
410
410
|
* @type {string}
|
|
411
411
|
* @public
|
|
412
412
|
*/
|
|
@@ -468,7 +468,7 @@ class TransactionDetailsResult {
|
|
|
468
468
|
this.resultCode = resultCode;
|
|
469
469
|
|
|
470
470
|
/**
|
|
471
|
-
* An object of type TransactionDetails representing the
|
|
471
|
+
* An object of type TransactionDetails representing the transaction. This value is null if the value of resultCode is not 0.
|
|
472
472
|
* @type {TransactionDetails}
|
|
473
473
|
* @public
|
|
474
474
|
*/
|
|
@@ -483,6 +483,115 @@ class TransactionDetailsResult {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
+
/**
|
|
487
|
+
* @class
|
|
488
|
+
* @constructor
|
|
489
|
+
* @public
|
|
490
|
+
* @classdesc This class represents a transaction of an account. You should consider the transaction as succeeded only if the status field is 0x1 (success).
|
|
491
|
+
*/
|
|
492
|
+
class AccountTransactionCompact {
|
|
493
|
+
constructor() {
|
|
494
|
+
/**
|
|
495
|
+
* The number of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
|
|
496
|
+
* @type {number}
|
|
497
|
+
* @public
|
|
498
|
+
*/
|
|
499
|
+
this.blockNumber = null;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* A 66 character hexadecimal string representing the address the transaction is sent from.
|
|
503
|
+
* @type {string}
|
|
504
|
+
* @public
|
|
505
|
+
*/
|
|
506
|
+
this.from = null;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* A 66 character hexadecimal string representing the hash of the transaction.
|
|
510
|
+
* @type {string}
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
this.hash = null;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* A 66 character hexadecimal string representing address the transaction is directed to.
|
|
517
|
+
* @type {string}
|
|
518
|
+
* @public
|
|
519
|
+
*/
|
|
520
|
+
this.to = null;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* A hexadecimal string representing the value sent with this transaction. The value can be 0 for smart contract transactions, since it only represents the number of coins sent.
|
|
524
|
+
* @type {string}
|
|
525
|
+
* @public
|
|
526
|
+
*/
|
|
527
|
+
this.value = null;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* A hexadecimal string representing either 0x1 (success) or 0x0 (failure). Failed transactions can also incur gas fee. You should consider the transaction as succeeded only if the status value is 0x1 (success).
|
|
531
|
+
* @type {string}
|
|
532
|
+
* @public
|
|
533
|
+
*/
|
|
534
|
+
this.status = null;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* @class
|
|
541
|
+
* @constructor
|
|
542
|
+
* @public
|
|
543
|
+
* @classdesc This class represents a list of account transactions returned by the listAccountTransactionDetails function.
|
|
544
|
+
*/
|
|
545
|
+
class ListAccountTransactionsResponse {
|
|
546
|
+
constructor() {
|
|
547
|
+
/**
|
|
548
|
+
* The number of pages available for listing.
|
|
549
|
+
* @type {number}
|
|
550
|
+
* @public
|
|
551
|
+
*/
|
|
552
|
+
this.pageCount = null;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* An array of type AccountTransactionCompact, containing the list of transactions. Can be null if no items are available.
|
|
556
|
+
* @type {(AccountTransactionCompact|Array)}
|
|
557
|
+
* @public
|
|
558
|
+
*/
|
|
559
|
+
this.items = null;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* @class
|
|
566
|
+
* @constructor
|
|
567
|
+
* @public
|
|
568
|
+
* @classdesc This class represents a result from invoking the listAccountTransactionDetails function.
|
|
569
|
+
*/
|
|
570
|
+
class AccountTransactionsResult {
|
|
571
|
+
constructor(resultCode, listAccountTransactionsResponse, response) {
|
|
572
|
+
/**
|
|
573
|
+
* 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.
|
|
574
|
+
* @type {number}
|
|
575
|
+
* @public
|
|
576
|
+
*/
|
|
577
|
+
this.resultCode = resultCode;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* An object of type ListAccountTransactionsResponse representing the list of transactions along with metadata. This value is null if the value of resultCode is not 0.
|
|
581
|
+
* @type {ListAccountTransactionsResponse}
|
|
582
|
+
* @public
|
|
583
|
+
*/
|
|
584
|
+
this.listAccountTransactionsResponse = listAccountTransactionsResponse;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
588
|
+
* @type {Object}
|
|
589
|
+
* @public
|
|
590
|
+
*/
|
|
591
|
+
this.response = response;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
486
595
|
function isLargeNumber(val) {
|
|
487
596
|
if (val === null) {
|
|
488
597
|
return false;
|
|
@@ -735,7 +844,7 @@ function transactionGetData(fromaddress, nonce, toaddress, amount, gas, chainid,
|
|
|
735
844
|
* @async
|
|
736
845
|
* @function postTransaction
|
|
737
846
|
* @param {string} txnData - A signed transaction string returned by the signSendCoinTransaction function.
|
|
738
|
-
* @return {Promise<SendResult>} Returns a promise of type SendResult.
|
|
847
|
+
* @return {Promise<SendResult>} Returns a promise of type SendResult. txnHash will be null in SendResult.
|
|
739
848
|
*/
|
|
740
849
|
async function postTransaction(txnData) {
|
|
741
850
|
if (isInitialized === false) {
|
|
@@ -926,7 +1035,9 @@ async function getAccountDetails(address) {
|
|
|
926
1035
|
}
|
|
927
1036
|
|
|
928
1037
|
/**
|
|
929
|
-
* The getTransactionDetails function returns details of a transaction posted to the blockchain.
|
|
1038
|
+
* The getTransactionDetails function returns details of a transaction posted to the blockchain.
|
|
1039
|
+
* Transactions may take a while to get registered in the blockchain. After a transaction is submitted, it may take a while before it is available for reading.
|
|
1040
|
+
* Some transactions that have lower balance than the minimum required for gas fees may be discarded.
|
|
930
1041
|
* In these cases, the transactions may not be returned when invoking the getTransactionDetails function.
|
|
931
1042
|
* You should consider the transaction as succeeded only if the status field of the transactionReceipt object is 0x1 (success).
|
|
932
1043
|
* The transactionReceipt field can be null unless the transaction is registered with the blockchain.
|
|
@@ -967,7 +1078,6 @@ async function getTransactionDetails(txnHash) {
|
|
|
967
1078
|
return new TransactionDetailsResult(-302, null, response);
|
|
968
1079
|
}
|
|
969
1080
|
if (response.status !== 200) {
|
|
970
|
-
console.log("response statuys " + response.status);
|
|
971
1081
|
return new TransactionDetailsResult(-303, null, response);
|
|
972
1082
|
}
|
|
973
1083
|
|
|
@@ -1016,6 +1126,100 @@ async function getTransactionDetails(txnHash) {
|
|
|
1016
1126
|
return new TransactionDetailsResult(0, transactionDetails, response);
|
|
1017
1127
|
}
|
|
1018
1128
|
|
|
1129
|
+
/**
|
|
1130
|
+
* The listAccountTransactions function returns a list of transactions for a specific account.
|
|
1131
|
+
* Transactions may take a while to get registered in the blockchain. After a transaction is submitted, it may take a while before it is available for listing.
|
|
1132
|
+
* Some transactions that have lower balance than the minimum required for gas fees may be discarded.
|
|
1133
|
+
* In these cases, the transactions may not be returned when invoking the listAccountTransactions function.
|
|
1134
|
+
* You should consider the transaction as succeeded only if the status field AccountDetailsCompact object is 0x1 (success).
|
|
1135
|
+
* Both transactions from and transactions to the address will be returned in the list.
|
|
1136
|
+
* Use the getTransactionDetails function, passing the hash of the transaction to get detailed information about the transaction.
|
|
1137
|
+
* @async
|
|
1138
|
+
* @function listAccountTransactions
|
|
1139
|
+
* @param {string} address - The address for which the transactions have to be listed.
|
|
1140
|
+
* @param {number} pageNumber - The page number for which the transactions has to be listed for the account. Pass 0 to list the latest page.
|
|
1141
|
+
* @return {Promise<ListAccountTransactionsResponse>} Returns a promise of type type ListAccountTransactionsResponse.
|
|
1142
|
+
*/
|
|
1143
|
+
async function listAccountTransactions(address, pageNumber) {
|
|
1144
|
+
if (isInitialized === false) {
|
|
1145
|
+
return -1000;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
if (address === null) {
|
|
1149
|
+
return new AccountTransactionsResult(-700, null, null);
|
|
1150
|
+
}
|
|
1151
|
+
if (isAddressValid(address) === false) {
|
|
1152
|
+
return new AccountTransactionsResult(-701, null, null);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
if (pageNumber === null) {
|
|
1156
|
+
pageNumber = 0;
|
|
1157
|
+
} else if (Number.isInteger(pageNumber) === false) {
|
|
1158
|
+
return new AccountTransactionsResult(-702, null, null);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
let requestId = getRandomRequestId();
|
|
1162
|
+
|
|
1163
|
+
let reqHeaders = new Headers({
|
|
1164
|
+
"Content-Type": "application/json"
|
|
1165
|
+
});
|
|
1166
|
+
reqHeaders.append(REQUEST_ID_HEADER_NAME, requestId);
|
|
1167
|
+
if (config.readApiKey !== null) {
|
|
1168
|
+
reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
var url = config.readUrl + "/account/" + address + "/transactions/" + pageNumber;
|
|
1172
|
+
console.log(url);
|
|
1173
|
+
|
|
1174
|
+
const response = await fetch(url, {
|
|
1175
|
+
headers: reqHeaders,
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
if (response === null) {
|
|
1179
|
+
return new AccountTransactionsResult(-703, null, response);
|
|
1180
|
+
}
|
|
1181
|
+
if (response.status !== 200) {
|
|
1182
|
+
return new AccountTransactionsResult(-704, null, response);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
const jsonObj = await response.json();
|
|
1186
|
+
|
|
1187
|
+
if (jsonObj === null) {
|
|
1188
|
+
return new AccountTransactionsResult(-705, null, response);
|
|
1189
|
+
}
|
|
1190
|
+
const result = jsonObj;
|
|
1191
|
+
|
|
1192
|
+
if (result.pageCount === null) {
|
|
1193
|
+
return new AccountTransactionsResult(-706, null, response);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
var listAccountDetailsResponse = new ListAccountTransactionsResponse();
|
|
1197
|
+
|
|
1198
|
+
let tempPageCount = parseInt(result.pageCount);
|
|
1199
|
+
if (Number.isInteger(tempPageCount) === true) {
|
|
1200
|
+
listAccountDetailsResponse.pageCount = tempPageCount;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
if (result.items !== null) {
|
|
1204
|
+
if (Array.isArray(result.items) === false) {
|
|
1205
|
+
return new AccountTransactionsResult(-707, null, response);
|
|
1206
|
+
}
|
|
1207
|
+
listAccountDetailsResponse.items = new Array();
|
|
1208
|
+
for (const item of result.items) {
|
|
1209
|
+
let txn = new AccountTransactionCompact();
|
|
1210
|
+
txn.blockNumber = item.blockNumber;
|
|
1211
|
+
txn.from = item.from;
|
|
1212
|
+
txn.hash = item.hash;
|
|
1213
|
+
txn.to = item.to;
|
|
1214
|
+
txn.value = item.value;
|
|
1215
|
+
txn.status = item.status;
|
|
1216
|
+
listAccountDetailsResponse.items.push(txn);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
return new AccountTransactionsResult(0, listAccountDetailsResponse, response);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1019
1223
|
/**
|
|
1020
1224
|
* The signSendCoinTransaction function returns a signed transaction.
|
|
1021
1225
|
* 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.
|
|
@@ -1027,7 +1231,7 @@ async function getTransactionDetails(txnHash) {
|
|
|
1027
1231
|
* @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
|
|
1028
1232
|
* @return {SignResult} Returns a promise of type SignResult.
|
|
1029
1233
|
*/
|
|
1030
|
-
async function signSendCoinTransaction(wallet, toAddress, coins) {
|
|
1234
|
+
async function signSendCoinTransaction(wallet, toAddress, coins, nonce) {
|
|
1031
1235
|
if (isInitialized === false) {
|
|
1032
1236
|
return -1000;
|
|
1033
1237
|
}
|
|
@@ -1073,15 +1277,15 @@ async function signSendCoinTransaction(wallet, toAddress, coins) {
|
|
|
1073
1277
|
|
|
1074
1278
|
var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
1075
1279
|
if (txHashHex == null) {
|
|
1076
|
-
return new
|
|
1280
|
+
return new SignResult(-508, null, null);
|
|
1077
1281
|
}
|
|
1078
1282
|
|
|
1079
1283
|
var txnData = transactionGetData(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
1080
1284
|
if (txnData == null) {
|
|
1081
|
-
return new
|
|
1285
|
+
return new SignResult(-509, null, null);
|
|
1082
1286
|
}
|
|
1083
1287
|
|
|
1084
|
-
return new
|
|
1288
|
+
return new SignResult(0, txHashHex, txnData);
|
|
1085
1289
|
}
|
|
1086
1290
|
|
|
1087
1291
|
/**
|