@xelis/sdk 0.6.0 → 0.7.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/README.md CHANGED
@@ -15,8 +15,12 @@ Import library and start working :).
15
15
  Use Daemon HTTP RPC connection.
16
16
 
17
17
  ```js
18
+ // ESM
18
19
  import { TESTNET_NODE_RPC } from '@xelis/sdk/config'
19
20
  import DaemonRPC from '@xelis/sdk/daemon/rpc'
21
+ // CommonJS
22
+ // const { TESTNET_NODE_RPC } = require('@xelis/sdk/config')
23
+ // const { RPC: DaemonRPC } = require('@xelis/sdk/daemon/rpc')
20
24
 
21
25
  const main = async () => {
22
26
  const daemon = new DaemonRPC(TESTNET_NODE_RPC)
@@ -30,8 +34,12 @@ main()
30
34
  Use Daemon WebSocket RPC connection.
31
35
 
32
36
  ```js
37
+ // ESM
33
38
  import { TESTNET_NODE_WS } from '@xelis/sdk/config'
34
39
  import DaemonWS from '@xelis/sdk/daemon/websocket'
40
+ // CommonJS
41
+ // const { TESTNET_NODE_RPC } = require('@xelis/sdk/config')
42
+ // const { WS: DaemonWS } = require('@xelis/sdk/daemon/websocket')
35
43
 
36
44
  const main = async () => {
37
45
  const daemon = new DaemonWS()
@@ -46,8 +54,12 @@ main()
46
54
  Use Wallet WebSocket RPC connection.
47
55
 
48
56
  ```js
57
+ // ESM
49
58
  import { LOCAL_WALLET_WS } from '@xelis/sdk/config'
50
59
  import DaemonWS from '@xelis/sdk/wallet/websocket'
60
+ // CommonJS
61
+ // const { LOCAL_WALLET_WS } = require('@xelis/sdk/config')
62
+ // const { WS: WalletWS } = require('@xelis/sdk/wallet/websocket')
51
63
 
52
64
  const main = async () => {
53
65
  const wallet = new WalletWS(`test`, `test`) // username, password
@@ -62,8 +74,12 @@ main()
62
74
  Use XSWD protocol.
63
75
 
64
76
  ```js
77
+ // ESM
65
78
  import { LOCAL_XSWD_WS } from '@xelis/sdk/config'
66
79
  import XSWD from '@xelis/sdk/xswd/websocket'
80
+ // CommonJS
81
+ // const { LOCAL_XSWD_WS } = require('@xelis/sdk/config')
82
+ // const { WS: XSWD } = require('@xelis/sdk/xswd/websocket')
67
83
 
68
84
  const main = async () => {
69
85
  const xswd = new XSWD()
package/daemon/rpc.d.ts CHANGED
@@ -1,41 +1,43 @@
1
- import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetBalanceResult, P2PStatusResult, Transaction, GetBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams, GetAccountHistoryParams, AccounHistory, Peer, DevFee, DiskSize, HasBalanceParams, HasBalanceResult, AssetData, IsTxExecutedInBlockParams, GetAssetParams } from './types';
1
+ import { Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetBalanceResult, P2PStatusResult, GetBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams, GetAccountHistoryParams, AccounHistory, DevFee, DiskSize, HasBalanceParams, HasBalanceResult, AssetData, IsTxExecutedInBlockParams, GetAssetParams, GetPeersResult, GetBlockTemplateResult, VersionedBalance, VersionedNonce, GetNonceAtTopoheightParams, HasNonceParams, HasNonceResult, TransactionResponse } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
- declare class RPC extends BaseRPC {
3
+ export declare class RPC extends BaseRPC {
4
4
  getVersion(): Promise<import("../lib/types").RPCResponse<string>>;
5
- getInfo(): Promise<import("../lib/types").RPCResponse<GetInfoResult>>;
6
5
  getHeight(): Promise<import("../lib/types").RPCResponse<number>>;
7
6
  getTopoHeight(): Promise<import("../lib/types").RPCResponse<number>>;
8
7
  getStableHeight(): Promise<import("../lib/types").RPCResponse<number>>;
9
- getBlockTemplate(address: string): Promise<import("../lib/types").RPCResponse<string>>;
8
+ getBlockTemplate(address: string): Promise<import("../lib/types").RPCResponse<GetBlockTemplateResult>>;
10
9
  getBlockAtTopoHeight(params: GetBlockAtTopoHeightParams): Promise<import("../lib/types").RPCResponse<Block>>;
11
10
  getBlocksAtHeight(params: GetBlocksAtHeightParams): Promise<import("../lib/types").RPCResponse<Block[]>>;
12
11
  getBlockByHash(params: GetBlockByHashParams): Promise<import("../lib/types").RPCResponse<Block>>;
13
12
  getTopBlock(params: GetTopBlockParams): Promise<import("../lib/types").RPCResponse<Block>>;
14
- getNonce(params: GetNonceParams): Promise<import("../lib/types").RPCResponse<GetNonceResult>>;
13
+ submitBlock(blockTemplate: string): Promise<import("../lib/types").RPCResponse<boolean>>;
15
14
  getBalance(params: GetBalanceParams): Promise<import("../lib/types").RPCResponse<GetBalanceResult>>;
16
15
  hasBalance(params: HasBalanceParams): Promise<import("../lib/types").RPCResponse<HasBalanceResult>>;
17
- getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<import("../lib/types").RPCResponse<Balance>>;
16
+ getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<import("../lib/types").RPCResponse<VersionedBalance>>;
17
+ getInfo(): Promise<import("../lib/types").RPCResponse<GetInfoResult>>;
18
+ getNonce(params: GetNonceParams): Promise<import("../lib/types").RPCResponse<GetNonceResult>>;
19
+ hasNonce(params: HasNonceParams): Promise<import("../lib/types").RPCResponse<HasNonceResult>>;
20
+ getNonceAtTopoheight(params: GetNonceAtTopoheightParams): Promise<import("../lib/types").RPCResponse<VersionedNonce>>;
18
21
  getAsset(params: GetAssetParams): Promise<import("../lib/types").RPCResponse<AssetData>>;
19
22
  getAssets(): Promise<import("../lib/types").RPCResponse<string[]>>;
20
- countTransactions(): Promise<import("../lib/types").RPCResponse<number>>;
21
23
  countAssets(): Promise<import("../lib/types").RPCResponse<number>>;
22
24
  countAccounts(): Promise<import("../lib/types").RPCResponse<number>>;
23
- getTips(): Promise<import("../lib/types").RPCResponse<string[]>>;
25
+ countTransactions(): Promise<import("../lib/types").RPCResponse<number>>;
26
+ submitTransaction(hexData: string): Promise<import("../lib/types").RPCResponse<boolean>>;
27
+ getTransaction(hash: string): Promise<import("../lib/types").RPCResponse<TransactionResponse>>;
24
28
  p2pStatus(): Promise<import("../lib/types").RPCResponse<P2PStatusResult>>;
29
+ getPeers(): Promise<import("../lib/types").RPCResponse<GetPeersResult>>;
30
+ getMemPool(): Promise<import("../lib/types").RPCResponse<TransactionResponse[]>>;
31
+ getTips(): Promise<import("../lib/types").RPCResponse<string[]>>;
25
32
  getDAGOrder(params: TopoHeightRangeParams): Promise<import("../lib/types").RPCResponse<string[]>>;
26
- getMemPool(): Promise<import("../lib/types").RPCResponse<Transaction[]>>;
27
- getTransaction(hash: string): Promise<import("../lib/types").RPCResponse<Transaction>>;
28
- getTransactions(txHashes: string[]): Promise<import("../lib/types").RPCResponse<Transaction[]>>;
29
33
  getBlocksRangeByTopoheight(params: TopoHeightRangeParams): Promise<import("../lib/types").RPCResponse<Block[]>>;
30
34
  getBlocksRangeByHeight(params: HeightRangeParams): Promise<import("../lib/types").RPCResponse<Block[]>>;
31
- getAccounts(params: GetAccountsParams): Promise<import("../lib/types").RPCResponse<string[]>>;
32
- submitBlock(blockTemplate: string): Promise<import("../lib/types").RPCResponse<boolean>>;
33
- submitTransaction(hexData: string): Promise<import("../lib/types").RPCResponse<boolean>>;
35
+ getTransactions(txHashes: string[]): Promise<import("../lib/types").RPCResponse<TransactionResponse[]>>;
34
36
  getAccountHistory(params: GetAccountHistoryParams): Promise<import("../lib/types").RPCResponse<AccounHistory[]>>;
35
37
  getAccountAssets(address: string): Promise<import("../lib/types").RPCResponse<string[]>>;
36
- getPeers(): Promise<import("../lib/types").RPCResponse<Peer[]>>;
38
+ getAccounts(params: GetAccountsParams): Promise<import("../lib/types").RPCResponse<string[]>>;
39
+ isTxExecutedInBlock(params: IsTxExecutedInBlockParams): Promise<import("../lib/types").RPCResponse<boolean>>;
37
40
  getDevFeeThresholds(): Promise<import("../lib/types").RPCResponse<DevFee[]>>;
38
41
  getSizeOnDisk(): Promise<import("../lib/types").RPCResponse<DiskSize>>;
39
- isTxExecutedInBlock(params: IsTxExecutedInBlockParams): Promise<import("../lib/types").RPCResponse<boolean>>;
40
42
  }
41
43
  export default RPC;
package/daemon/rpc.js CHANGED
@@ -1,12 +1,9 @@
1
1
  import { RPCMethod } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
- class RPC extends BaseRPC {
3
+ export class RPC extends BaseRPC {
4
4
  getVersion() {
5
5
  return this.post(RPCMethod.GetVersion);
6
6
  }
7
- getInfo() {
8
- return this.post(RPCMethod.GetInfo);
9
- }
10
7
  getHeight() {
11
8
  return this.post(RPCMethod.GetHeight);
12
9
  }
@@ -31,8 +28,8 @@ class RPC extends BaseRPC {
31
28
  getTopBlock(params) {
32
29
  return this.post(RPCMethod.GetTopBlock, params);
33
30
  }
34
- getNonce(params) {
35
- return this.post(RPCMethod.GetNonce, params);
31
+ submitBlock(blockTemplate) {
32
+ return this.post(RPCMethod.SubmitBlock, { block_template: blockTemplate });
36
33
  }
37
34
  getBalance(params) {
38
35
  return this.post(RPCMethod.GetBalance, params);
@@ -43,38 +40,53 @@ class RPC extends BaseRPC {
43
40
  getBalanceAtTopoHeight(params) {
44
41
  return this.post(RPCMethod.GetBalanceAtTopoHeight, params);
45
42
  }
43
+ getInfo() {
44
+ return this.post(RPCMethod.GetInfo);
45
+ }
46
+ getNonce(params) {
47
+ return this.post(RPCMethod.GetNonce, params);
48
+ }
49
+ hasNonce(params) {
50
+ return this.post(RPCMethod.HasNonce, params);
51
+ }
52
+ getNonceAtTopoheight(params) {
53
+ return this.post(RPCMethod.GetNonceAtTopoheight, params);
54
+ }
46
55
  getAsset(params) {
47
56
  return this.post(RPCMethod.GetAsset, params);
48
57
  }
49
58
  getAssets() {
50
59
  return this.post(RPCMethod.GetAssets);
51
60
  }
52
- countTransactions() {
53
- return this.post(RPCMethod.CountTransactions);
54
- }
55
61
  countAssets() {
56
62
  return this.post(RPCMethod.CountAssets);
57
63
  }
58
64
  countAccounts() {
59
65
  return this.post(RPCMethod.CountAccounts);
60
66
  }
61
- getTips() {
62
- return this.post(RPCMethod.GetTips);
67
+ countTransactions() {
68
+ return this.post(RPCMethod.CountTransactions);
69
+ }
70
+ submitTransaction(hexData) {
71
+ return this.post(RPCMethod.SubmitTransaction, { data: hexData });
72
+ }
73
+ getTransaction(hash) {
74
+ return this.post(RPCMethod.GetTransaction, { hash });
63
75
  }
64
76
  p2pStatus() {
65
77
  return this.post(RPCMethod.P2PStatus);
66
78
  }
67
- getDAGOrder(params) {
68
- return this.post(RPCMethod.GetDAGOrder, params);
79
+ getPeers() {
80
+ return this.post(RPCMethod.GetPeers);
69
81
  }
70
82
  getMemPool() {
71
83
  return this.post(RPCMethod.GetMempool);
72
84
  }
73
- getTransaction(hash) {
74
- return this.post(RPCMethod.GetTransaction, { hash });
85
+ getTips() {
86
+ return this.post(RPCMethod.GetTips);
75
87
  }
76
- getTransactions(txHashes) {
77
- return this.post(RPCMethod.GetTransactions, { tx_hashes: txHashes });
88
+ getDAGOrder(params) {
89
+ return this.post(RPCMethod.GetDAGOrder, params);
78
90
  }
79
91
  getBlocksRangeByTopoheight(params) {
80
92
  return this.post(RPCMethod.GetBlocksRangeByTopoheight, params);
@@ -82,14 +94,8 @@ class RPC extends BaseRPC {
82
94
  getBlocksRangeByHeight(params) {
83
95
  return this.post(RPCMethod.GetBlocksRangeByHeight, params);
84
96
  }
85
- getAccounts(params) {
86
- return this.post(RPCMethod.GetAccounts, params);
87
- }
88
- submitBlock(blockTemplate) {
89
- return this.post(RPCMethod.SubmitBlock, { block_template: blockTemplate });
90
- }
91
- submitTransaction(hexData) {
92
- return this.post(RPCMethod.SubmitTransaction, { data: hexData });
97
+ getTransactions(txHashes) {
98
+ return this.post(RPCMethod.GetTransactions, { tx_hashes: txHashes });
93
99
  }
94
100
  getAccountHistory(params) {
95
101
  return this.post(RPCMethod.GetAccountHistory, params);
@@ -97,8 +103,11 @@ class RPC extends BaseRPC {
97
103
  getAccountAssets(address) {
98
104
  return this.post(RPCMethod.GetAccountAssets, { address });
99
105
  }
100
- getPeers() {
101
- return this.post(RPCMethod.GetPeers);
106
+ getAccounts(params) {
107
+ return this.post(RPCMethod.GetAccounts, params);
108
+ }
109
+ isTxExecutedInBlock(params) {
110
+ return this.post(RPCMethod.IsTxExecutedInBlock, params);
102
111
  }
103
112
  getDevFeeThresholds() {
104
113
  return this.post(RPCMethod.GetDevFeeThresholds);
@@ -106,8 +115,5 @@ class RPC extends BaseRPC {
106
115
  getSizeOnDisk() {
107
116
  return this.post(RPCMethod.GetSizeOnDisk);
108
117
  }
109
- isTxExecutedInBlock(params) {
110
- return this.post(RPCMethod.IsTxExecutedInBlock, params);
111
- }
112
118
  }
113
119
  export default RPC;
package/daemon/types.d.ts CHANGED
@@ -1,34 +1,38 @@
1
1
  export interface GetInfoResult {
2
+ average_block_time: number;
3
+ block_reward: number;
2
4
  block_time_target: number;
3
- difficulty: number;
4
- height: number;
5
- mempool_size: number;
6
5
  circulating_supply: number;
6
+ difficulty: string;
7
+ height: number;
7
8
  maximum_supply: number;
9
+ mempool_size: number;
10
+ network: string;
11
+ pruned_topoheight?: number;
8
12
  stableheight: number;
9
13
  top_block_hash: string;
10
- version: string;
11
- network: string;
12
14
  topoheight: number;
15
+ version: string;
13
16
  }
14
17
  export interface Block {
15
- block_type: string;
16
- cumulative_difficulty: number;
17
- supply: number;
18
- difficulty: number;
19
- reward: number;
20
- extra_nonce: string;
21
18
  hash: string;
19
+ topoheight?: number;
20
+ block_type: BlockType;
21
+ difficulty: string;
22
+ supply?: number;
23
+ reward?: number;
24
+ cumulative_difficulty: string;
25
+ total_fees?: number;
26
+ total_size_in_bytes: number;
27
+ version: number;
28
+ tips: string[];
29
+ timestamp: number;
22
30
  height: number;
23
- miner: string;
24
31
  nonce: number;
25
- tips: string[];
26
- topoheight: number;
27
- total_fees: number;
28
- total_size_in_bytes: number;
29
- transactions?: Transaction[];
32
+ extra_nonce: string;
33
+ miner: string;
30
34
  txs_hashes: string[];
31
- version: number;
35
+ transactions?: Transaction[];
32
36
  }
33
37
  export interface GetBalanceParams {
34
38
  address: string;
@@ -43,17 +47,35 @@ export interface GetNonceParams {
43
47
  address: string;
44
48
  topoheight: number;
45
49
  }
46
- export interface GetNonceResult {
50
+ export interface VersionedNonce {
47
51
  nonce: number;
48
- previous_topoheight: number;
52
+ previous_topoheight?: number;
53
+ }
54
+ export interface GetNonceResult {
55
+ version: VersionedNonce;
56
+ topoheight: number;
57
+ }
58
+ export interface GetNonceAtTopoheightParams {
59
+ address: string;
49
60
  topoheight: number;
50
61
  }
51
- export interface Balance {
52
- balance: number;
53
- previous_topoheight: number;
62
+ export interface EncryptedBalance {
63
+ commitment: number[];
64
+ handle: number[];
65
+ }
66
+ export declare enum BalanceType {
67
+ Input = "input",
68
+ Output = "output",
69
+ Both = "both"
70
+ }
71
+ export interface VersionedBalance {
72
+ balance_type: BalanceType;
73
+ final_balance: EncryptedBalance;
74
+ output_balance?: EncryptedBalance;
75
+ previous_topoheight?: number;
54
76
  }
55
77
  export interface GetBalanceResult {
56
- version: Balance;
78
+ version: VersionedBalance;
57
79
  topoheight: number;
58
80
  }
59
81
  export interface P2PStatusResult {
@@ -76,20 +98,22 @@ export interface RPCEventResult {
76
98
  event: string;
77
99
  }
78
100
  export type PeerPeers = {
79
- [ip: string]: `In` | `Out` | `Both`;
101
+ [addr: string]: `In` | `Out` | `Both`;
80
102
  };
81
103
  export interface Peer {
82
104
  id: number;
83
105
  addr: string;
84
- tag: string;
106
+ local_port: number;
107
+ tag?: string;
85
108
  version: string;
86
109
  top_block_hash: string;
87
110
  topoheight: number;
88
111
  height: number;
89
112
  last_ping: number;
90
- pruned_topoheight: number;
113
+ pruned_topoheight?: number;
91
114
  peers: PeerPeers;
92
- cumulative_difficulty: number;
115
+ cumulative_difficulty: string;
116
+ connected_on: number;
93
117
  }
94
118
  export interface BlockOrdered {
95
119
  topoheight: number;
@@ -100,31 +124,66 @@ export interface BlockOrphaned {
100
124
  block_hash: string;
101
125
  old_topoheight: number;
102
126
  }
127
+ export interface StableHeightChanged {
128
+ previous_stable_height: number;
129
+ new_stable_height: number;
130
+ }
131
+ export interface Proof {
132
+ Y_0: number[];
133
+ Y_1: number[];
134
+ z_r: number[];
135
+ z_x: number[];
136
+ }
137
+ export interface EqProof {
138
+ Y_0: number[];
139
+ Y_1: number[];
140
+ Y_2: number[];
141
+ z_r: number[];
142
+ z_s: number[];
143
+ z_x: number[];
144
+ }
103
145
  export interface Transfer {
104
- amount: number;
105
146
  asset: string;
147
+ destination: string;
106
148
  extra_data?: any;
107
- to: string;
149
+ commitment: number[];
150
+ sender_handle: number[];
151
+ receiver_handle: number[];
152
+ ct_validity_proof: Proof;
153
+ }
154
+ export interface Burn {
155
+ asset: string;
156
+ amount: number;
108
157
  }
109
158
  export interface TransactionData {
110
159
  transfers: Transfer[];
111
- burn: {
112
- asset: string;
113
- amount: number;
114
- };
115
- call_contract: {
116
- contract: string;
117
- };
118
- deploy_contract: string;
160
+ burn: Burn;
161
+ }
162
+ export interface SourceCommitment {
163
+ commitment: number[];
164
+ proof: EqProof;
165
+ asset: string;
166
+ }
167
+ export interface Reference {
168
+ hash: string;
169
+ topoheight: number;
119
170
  }
120
171
  export interface Transaction {
121
172
  hash: string;
122
- blocks: string[];
173
+ version: number;
174
+ source: string;
123
175
  data: TransactionData;
124
176
  fee: number;
125
177
  nonce: number;
126
- owner: string;
178
+ source_commitments: SourceCommitment[];
179
+ range_proof: number[];
127
180
  signature: string;
181
+ reference: Reference;
182
+ }
183
+ export interface TransactionResponse extends Transaction {
184
+ blocks: string[];
185
+ executed_in_block: string;
186
+ in_mempool: boolean;
128
187
  first_seen?: number;
129
188
  }
130
189
  export interface GetAccountsParams {
@@ -156,7 +215,6 @@ export interface GetAccountHistoryParams {
156
215
  }
157
216
  export interface AccounHistory {
158
217
  topoheight: number;
159
- block_timestamp: number;
160
218
  hash: string;
161
219
  mining?: {
162
220
  reward: number;
@@ -165,11 +223,12 @@ export interface AccounHistory {
165
223
  amount: number;
166
224
  };
167
225
  outgoing?: {
168
- amount: number;
226
+ to: string;
169
227
  };
170
228
  incoming?: {
171
- amount: number;
229
+ from: string;
172
230
  };
231
+ block_timestamp: number;
173
232
  }
174
233
  export interface PeerPeerListUpdated {
175
234
  peer_id: number;
@@ -203,6 +262,9 @@ export interface HasBalanceParams {
203
262
  export interface HasBalanceResult {
204
263
  exists: boolean;
205
264
  }
265
+ export interface HasNonceResult {
266
+ exists: boolean;
267
+ }
206
268
  export interface IsTxExecutedInBlockParams {
207
269
  tx_hash: string;
208
270
  block_hash: string;
@@ -210,12 +272,26 @@ export interface IsTxExecutedInBlockParams {
210
272
  export interface GetAssetParams {
211
273
  asset: string;
212
274
  }
275
+ export interface GetPeersResult {
276
+ peers: Peer[];
277
+ total_peers: number;
278
+ hidden_peers: number;
279
+ }
213
280
  export declare enum BlockType {
214
281
  Sync = "Sync",
215
282
  Normal = "Normal",
216
283
  Side = "Side",
217
284
  Orphaned = "Orphaned"
218
285
  }
286
+ export interface GetBlockTemplateResult {
287
+ template: string;
288
+ height: number;
289
+ difficulty: number;
290
+ }
291
+ export interface HasNonceParams {
292
+ address: string;
293
+ topoheight?: number;
294
+ }
219
295
  export declare enum RPCMethod {
220
296
  GetVersion = "get_version",
221
297
  GetInfo = "get_info",
@@ -228,6 +304,8 @@ export declare enum RPCMethod {
228
304
  GetBlockByHash = "get_block_by_hash",
229
305
  GetTopBlock = "get_top_block",
230
306
  GetNonce = "get_nonce",
307
+ GetNonceAtTopoheight = "get_nonce_at_topoheight",
308
+ HasNonce = "has_nonce",
231
309
  GetBalance = "get_balance",
232
310
  HasBalance = "has_balance",
233
311
  GetBalanceAtTopoHeight = "get_balance_at_topoheight",
@@ -256,15 +334,17 @@ export declare enum RPCMethod {
256
334
  }
257
335
  export declare enum RPCEvent {
258
336
  NewBlock = "new_block",
337
+ BlockOrdered = "block_ordered",
338
+ BlockOrphaned = "block_orphaned",
339
+ StableHeightChanged = "stable_height_changed",
340
+ TransactionOrphaned = "transaction_orphaned",
259
341
  TransactionAddedInMempool = "transaction_added_in_mempool",
260
342
  TransactionExecuted = "transaction_executed",
261
- BlockOrdered = "block_ordered",
262
343
  TransactionSCResult = "transaction_sc_result",
263
344
  NewAsset = "new_asset",
264
345
  PeerConnected = "peer_connected",
265
346
  PeerDisconnected = "peer_disconnected",
266
- PeerStateUpdated = "peer_state_updated",
267
347
  PeerPeerListUpdated = "peer_peer_list_updated",
268
- PeerPeerDisconnected = "peer_peer_disconnected",
269
- BlockOrphaned = "block_orphaned"
348
+ PeerStateUpdated = "peer_state_updated",
349
+ PeerPeerDisconnected = "peer_peer_disconnected"
270
350
  }
package/daemon/types.js CHANGED
@@ -1,3 +1,9 @@
1
+ export var BalanceType;
2
+ (function (BalanceType) {
3
+ BalanceType["Input"] = "input";
4
+ BalanceType["Output"] = "output";
5
+ BalanceType["Both"] = "both";
6
+ })(BalanceType || (BalanceType = {}));
1
7
  export var BlockType;
2
8
  (function (BlockType) {
3
9
  BlockType["Sync"] = "Sync";
@@ -18,6 +24,8 @@ export var RPCMethod;
18
24
  RPCMethod["GetBlockByHash"] = "get_block_by_hash";
19
25
  RPCMethod["GetTopBlock"] = "get_top_block";
20
26
  RPCMethod["GetNonce"] = "get_nonce";
27
+ RPCMethod["GetNonceAtTopoheight"] = "get_nonce_at_topoheight";
28
+ RPCMethod["HasNonce"] = "has_nonce";
21
29
  RPCMethod["GetBalance"] = "get_balance";
22
30
  RPCMethod["HasBalance"] = "has_balance";
23
31
  RPCMethod["GetBalanceAtTopoHeight"] = "get_balance_at_topoheight";
@@ -47,15 +55,17 @@ export var RPCMethod;
47
55
  export var RPCEvent;
48
56
  (function (RPCEvent) {
49
57
  RPCEvent["NewBlock"] = "new_block";
58
+ RPCEvent["BlockOrdered"] = "block_ordered";
59
+ RPCEvent["BlockOrphaned"] = "block_orphaned";
60
+ RPCEvent["StableHeightChanged"] = "stable_height_changed";
61
+ RPCEvent["TransactionOrphaned"] = "transaction_orphaned";
50
62
  RPCEvent["TransactionAddedInMempool"] = "transaction_added_in_mempool";
51
63
  RPCEvent["TransactionExecuted"] = "transaction_executed";
52
- RPCEvent["BlockOrdered"] = "block_ordered";
53
64
  RPCEvent["TransactionSCResult"] = "transaction_sc_result";
54
65
  RPCEvent["NewAsset"] = "new_asset";
55
66
  RPCEvent["PeerConnected"] = "peer_connected";
56
67
  RPCEvent["PeerDisconnected"] = "peer_disconnected";
57
- RPCEvent["PeerStateUpdated"] = "peer_state_updated";
58
68
  RPCEvent["PeerPeerListUpdated"] = "peer_peer_list_updated";
69
+ RPCEvent["PeerStateUpdated"] = "peer_state_updated";
59
70
  RPCEvent["PeerPeerDisconnected"] = "peer_peer_disconnected";
60
- RPCEvent["BlockOrphaned"] = "block_orphaned";
61
71
  })(RPCEvent || (RPCEvent = {}));
@@ -1,5 +1,5 @@
1
1
  import { MessageEvent } from 'ws';
2
- import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetBalanceResult, HeightRangeParams, BlockOrdered, GetBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceParams, GetNonceResult, GetAccountHistoryParams, AccounHistory, Peer, PeerPeerListUpdated, PeerPeerDisconnected, DevFee, DiskSize, AssetWithData, AssetData, GetAssetParams, HasBalanceParams, HasBalanceResult, IsTxExecutedInBlockParams, BlockOrphaned } from './types';
2
+ import { Block, GetInfoResult, GetPeersResult, RPCEventResult, TopoHeightRangeParams, P2PStatusResult, GetBalanceAtTopoHeightParams, GetBalanceResult, HeightRangeParams, BlockOrdered, GetBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceParams, GetNonceResult, GetAccountHistoryParams, AccounHistory, Peer, PeerPeerListUpdated, PeerPeerDisconnected, DevFee, DiskSize, AssetWithData, AssetData, GetAssetParams, HasBalanceParams, HasBalanceResult, IsTxExecutedInBlockParams, BlockOrphaned, VersionedBalance, StableHeightChanged, HasNonceResult, HasNonceParams, TransactionResponse } from './types';
3
3
  import { WS as BaseWS } from '../lib/websocket';
4
4
  export declare class DaemonMethods {
5
5
  ws: BaseWS;
@@ -8,8 +8,8 @@ export declare class DaemonMethods {
8
8
  listenEvent<T>(event: string, onData: (msgEvent: MessageEvent, data?: T, err?: Error) => void): Promise<() => Promise<void>>;
9
9
  dataCall<T>(method: string, params?: any): Promise<T>;
10
10
  onNewBlock(onData: (msgEvent: MessageEvent, data?: Block & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
11
- onTransactionAddedInMempool(onData: (msgEvent: MessageEvent, data?: Transaction & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
12
- onTransactionExecuted(onData: (msgEvent: MessageEvent, data?: Transaction & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
11
+ onTransactionAddedInMempool(onData: (msgEvent: MessageEvent, data?: TransactionResponse & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
12
+ onTransactionExecuted(onData: (msgEvent: MessageEvent, data?: TransactionResponse & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
13
13
  onBlockOrdered(onData: (msgEvent: MessageEvent, data?: BlockOrdered & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
14
14
  onPeerConnected(onData: (msgEvent: MessageEvent, data?: Peer & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
15
15
  onPeerDisconnected(onData: (msgEvent: MessageEvent, data?: number & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
@@ -18,8 +18,9 @@ export declare class DaemonMethods {
18
18
  onPeerStateUpdated(onData: (msgEvent: MessageEvent, data?: Peer & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
19
19
  onNewAsset(onData: (msgEvent: MessageEvent, data?: AssetWithData & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
20
20
  onBlockOrphaned(onData: (msgEvent: MessageEvent, data?: BlockOrphaned & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
21
+ onTransactionOrphaned(onData: (msgEvent: MessageEvent, data?: TransactionResponse & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
22
+ onStableHeightChanged(onData: (msgEvent: MessageEvent, data?: StableHeightChanged & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
21
23
  getVersion(): Promise<string>;
22
- getInfo(): Promise<GetInfoResult>;
23
24
  getHeight(): Promise<number>;
24
25
  getTopoHeight(): Promise<number>;
25
26
  getStableHeight(): Promise<number>;
@@ -28,33 +29,36 @@ export declare class DaemonMethods {
28
29
  getBlocksAtHeight(params: GetBlocksAtHeightParams): Promise<Block[]>;
29
30
  getBlockByHash(params: GetBlockByHashParams): Promise<Block>;
30
31
  getTopBlock(params: GetTopBlockParams): Promise<Block>;
31
- getNonce(params: GetNonceParams): Promise<GetNonceResult>;
32
+ submitBlock(blockTemplate: string): Promise<boolean>;
32
33
  getBalance(params: GetBalanceParams): Promise<GetBalanceResult>;
33
34
  hasBalance(params: HasBalanceParams): Promise<HasBalanceResult>;
34
- getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<Balance>;
35
+ getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<VersionedBalance>;
36
+ getInfo(): Promise<GetInfoResult>;
37
+ getNonce(params: GetNonceParams): Promise<GetNonceResult>;
38
+ hasNonce(params: HasNonceParams): Promise<HasNonceResult>;
35
39
  getAsset(params: GetAssetParams): Promise<AssetData>;
36
40
  getAssets(): Promise<string[]>;
41
+ countAssets(): Promise<number>;
42
+ countAccounts(): Promise<number>;
37
43
  countTransactions(): Promise<number>;
38
- getTips(): Promise<string[]>;
44
+ submitTransaction(hexData: string): Promise<boolean>;
45
+ getTransaction(hash: string): Promise<TransactionResponse>;
39
46
  p2pStatus(): Promise<P2PStatusResult>;
47
+ getPeers(): Promise<GetPeersResult>;
48
+ getMemPool(): Promise<TransactionResponse[]>;
49
+ getTips(): Promise<string[]>;
40
50
  getDAGOrder(params: TopoHeightRangeParams): Promise<string[]>;
41
- getMemPool(): Promise<Transaction[]>;
42
- getTransaction(hash: string): Promise<Transaction>;
43
- getTransactions(txHashes: string[]): Promise<Transaction[]>;
44
51
  getBlocksRangeByTopoheight(params: TopoHeightRangeParams): Promise<Block[]>;
45
52
  getBlocksRangeByHeight(params: HeightRangeParams): Promise<Block[]>;
46
- getAccounts(params: GetAccountsParams): Promise<string[]>;
47
- submitBlock(blockTemplate: string): Promise<boolean>;
48
- submitTransaction(hexData: string): Promise<boolean>;
49
- countAccounts(): Promise<number>;
53
+ getTransactions(txHashes: string[]): Promise<TransactionResponse[]>;
50
54
  getAccountHistory(params: GetAccountHistoryParams): Promise<AccounHistory[]>;
51
55
  getAccountAssets(address: string): Promise<string[]>;
52
- getPeers(): Promise<Peer[]>;
56
+ getAccounts(params: GetAccountsParams): Promise<string[]>;
57
+ isTxExecutedInBlock(params: IsTxExecutedInBlockParams): Promise<boolean>;
53
58
  getDevFeeThresholds(): Promise<DevFee[]>;
54
59
  getSizeOnDisk(): Promise<DiskSize>;
55
- isTxExecutedInBlock(params: IsTxExecutedInBlockParams): Promise<boolean>;
56
60
  }
57
- declare class WS extends BaseWS {
61
+ export declare class WS extends BaseWS {
58
62
  methods: DaemonMethods;
59
63
  constructor();
60
64
  }
@@ -44,12 +44,15 @@ export class DaemonMethods {
44
44
  onBlockOrphaned(onData) {
45
45
  return this.listenEvent(RPCEvent.BlockOrphaned, onData);
46
46
  }
47
+ onTransactionOrphaned(onData) {
48
+ return this.listenEvent(RPCEvent.TransactionOrphaned, onData);
49
+ }
50
+ onStableHeightChanged(onData) {
51
+ return this.listenEvent(RPCEvent.StableHeightChanged, onData);
52
+ }
47
53
  getVersion() {
48
54
  return this.dataCall(RPCMethod.GetVersion);
49
55
  }
50
- getInfo() {
51
- return this.dataCall(RPCMethod.GetInfo);
52
- }
53
56
  getHeight() {
54
57
  return this.dataCall(RPCMethod.GetHeight);
55
58
  }
@@ -74,8 +77,8 @@ export class DaemonMethods {
74
77
  getTopBlock(params) {
75
78
  return this.dataCall(RPCMethod.GetTopBlock, params);
76
79
  }
77
- getNonce(params) {
78
- return this.dataCall(RPCMethod.GetNonce, params);
80
+ submitBlock(blockTemplate) {
81
+ return this.dataCall(RPCMethod.SubmitBlock, { block_template: blockTemplate });
79
82
  }
80
83
  getBalance(params) {
81
84
  return this.dataCall(RPCMethod.GetBalance, params);
@@ -86,32 +89,50 @@ export class DaemonMethods {
86
89
  getBalanceAtTopoHeight(params) {
87
90
  return this.dataCall(RPCMethod.GetBalanceAtTopoHeight, params);
88
91
  }
92
+ getInfo() {
93
+ return this.dataCall(RPCMethod.GetInfo);
94
+ }
95
+ getNonce(params) {
96
+ return this.dataCall(RPCMethod.GetNonce, params);
97
+ }
98
+ hasNonce(params) {
99
+ return this.dataCall(RPCMethod.HasNonce, params);
100
+ }
89
101
  getAsset(params) {
90
102
  return this.dataCall(RPCMethod.GetAsset, params);
91
103
  }
92
104
  getAssets() {
93
105
  return this.dataCall(RPCMethod.GetAssets);
94
106
  }
107
+ countAssets() {
108
+ return this.dataCall(RPCMethod.CountAssets);
109
+ }
110
+ countAccounts() {
111
+ return this.dataCall(RPCMethod.CountAccounts);
112
+ }
95
113
  countTransactions() {
96
114
  return this.dataCall(RPCMethod.CountTransactions);
97
115
  }
98
- getTips() {
99
- return this.dataCall(RPCMethod.GetTips);
116
+ submitTransaction(hexData) {
117
+ return this.dataCall(RPCMethod.SubmitTransaction, { data: hexData });
118
+ }
119
+ getTransaction(hash) {
120
+ return this.dataCall(RPCMethod.GetTransaction, { hash });
100
121
  }
101
122
  p2pStatus() {
102
123
  return this.dataCall(RPCMethod.P2PStatus);
103
124
  }
104
- getDAGOrder(params) {
105
- return this.dataCall(RPCMethod.GetDAGOrder, params);
125
+ getPeers() {
126
+ return this.dataCall(RPCMethod.GetPeers);
106
127
  }
107
128
  getMemPool() {
108
129
  return this.dataCall(RPCMethod.GetMempool);
109
130
  }
110
- getTransaction(hash) {
111
- return this.dataCall(RPCMethod.GetTransaction, { hash });
131
+ getTips() {
132
+ return this.dataCall(RPCMethod.GetTips);
112
133
  }
113
- getTransactions(txHashes) {
114
- return this.dataCall(RPCMethod.GetTransactions, { tx_hashes: txHashes });
134
+ getDAGOrder(params) {
135
+ return this.dataCall(RPCMethod.GetDAGOrder, params);
115
136
  }
116
137
  getBlocksRangeByTopoheight(params) {
117
138
  return this.dataCall(RPCMethod.GetBlocksRangeByTopoheight, params);
@@ -119,17 +140,8 @@ export class DaemonMethods {
119
140
  getBlocksRangeByHeight(params) {
120
141
  return this.dataCall(RPCMethod.GetBlocksRangeByHeight, params);
121
142
  }
122
- getAccounts(params) {
123
- return this.dataCall(RPCMethod.GetAccounts, params);
124
- }
125
- submitBlock(blockTemplate) {
126
- return this.dataCall(RPCMethod.SubmitBlock, { block_template: blockTemplate });
127
- }
128
- submitTransaction(hexData) {
129
- return this.dataCall(RPCMethod.SubmitTransaction, { data: hexData });
130
- }
131
- countAccounts() {
132
- return this.dataCall(RPCMethod.CountAccounts);
143
+ getTransactions(txHashes) {
144
+ return this.dataCall(RPCMethod.GetTransactions, { tx_hashes: txHashes });
133
145
  }
134
146
  getAccountHistory(params) {
135
147
  return this.dataCall(RPCMethod.GetAccountHistory, params);
@@ -137,8 +149,11 @@ export class DaemonMethods {
137
149
  getAccountAssets(address) {
138
150
  return this.dataCall(RPCMethod.GetAccountAssets, { address });
139
151
  }
140
- getPeers() {
141
- return this.dataCall(RPCMethod.GetPeers);
152
+ getAccounts(params) {
153
+ return this.dataCall(RPCMethod.GetAccounts, params);
154
+ }
155
+ isTxExecutedInBlock(params) {
156
+ return this.dataCall(RPCMethod.IsTxExecutedInBlock, params);
142
157
  }
143
158
  getDevFeeThresholds() {
144
159
  return this.dataCall(RPCMethod.GetDevFeeThresholds);
@@ -146,11 +161,8 @@ export class DaemonMethods {
146
161
  getSizeOnDisk() {
147
162
  return this.dataCall(RPCMethod.GetSizeOnDisk);
148
163
  }
149
- isTxExecutedInBlock(params) {
150
- return this.dataCall(RPCMethod.IsTxExecutedInBlock, params);
151
- }
152
164
  }
153
- class WS extends BaseWS {
165
+ export class WS extends BaseWS {
154
166
  constructor() {
155
167
  super();
156
168
  this.methods = new DaemonMethods(this);
package/lib/websocket.js CHANGED
@@ -5,7 +5,7 @@ export class WS {
5
5
  this.connectionTries = 0;
6
6
  this.methodIdIncrement = 0;
7
7
  this.endpoint = "";
8
- this.timeout = 3000;
8
+ this.timeout = 15000; // default to 15s
9
9
  this.events = {};
10
10
  this.unsubscribeSuspense = 1000;
11
11
  this.maxConnectionTries = 3;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0",
2
+ "version": "0.7.0",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {
package/react/daemon.d.ts CHANGED
@@ -10,6 +10,7 @@ interface NodeSocket {
10
10
  }
11
11
  interface NodeSocketProviderProps {
12
12
  endpoint: string;
13
+ timeout?: number;
13
14
  }
14
15
  export declare const NodeSocketProvider: (props: PropsWithChildren<NodeSocketProviderProps>) => React.JSX.Element;
15
16
  interface NodeSocketSubscribeProps<T> {
package/react/daemon.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import React, { createContext, useContext, useEffect, useState } from 'react';
2
2
  import to from 'await-to-js';
3
3
  import DaemonWS from '../daemon/websocket';
4
- const daemon = new DaemonWS();
5
4
  export const INITIATING = -1;
5
+ const daemon = new DaemonWS();
6
6
  const Context = createContext({
7
7
  err: undefined,
8
8
  daemon,
9
9
  readyState: INITIATING
10
10
  });
11
11
  export const NodeSocketProvider = (props) => {
12
- const { children, endpoint } = props;
12
+ const { children, endpoint, timeout } = props;
13
13
  const [readyState, setReadyState] = useState(INITIATING);
14
14
  const [err, setErr] = useState();
15
15
  useEffect(() => {
@@ -21,6 +21,11 @@ export const NodeSocketProvider = (props) => {
21
21
  };
22
22
  connect();
23
23
  }, [endpoint]);
24
+ useEffect(() => {
25
+ if (!timeout)
26
+ return;
27
+ daemon.timeout = timeout;
28
+ }, [timeout]);
24
29
  useEffect(() => {
25
30
  if (!daemon.socket)
26
31
  return;
package/wallet/rpc.d.ts CHANGED
@@ -1,23 +1,27 @@
1
- import { Transaction, GetAssetParams } from '../daemon/types';
2
- import { GetAddressParams, SplitAddressParams, SplitAddressResult, BuildTransactionParams, BuildTransactionResult, ListTransactionParams } from './types';
1
+ import { GetAssetParams, HasBalanceResult, TransactionData } from '../daemon/types';
2
+ import { GetAddressParams, SplitAddressParams, SplitAddressResult, BuildTransactionParams, BuildTransactionResult, ListTransactionParams, Signature, TransactionEntry } from './types';
3
3
  import { RPC as BaseRPC } from '../lib/rpc';
4
4
  import { RPCResponse } from '../lib/types';
5
- declare class RPC extends BaseRPC {
5
+ export declare class RPC extends BaseRPC {
6
6
  auth: string;
7
7
  constructor(endpoint: string, username: string, password: string);
8
8
  post<T>(method: string, params?: any): Promise<RPCResponse<T>>;
9
9
  getVersion(): Promise<RPCResponse<string>>;
10
+ getNetwork(): Promise<RPCResponse<string>>;
10
11
  getNonce(): Promise<RPCResponse<number>>;
11
12
  getTopoheight(): Promise<RPCResponse<number>>;
12
13
  getAddress(params?: GetAddressParams): Promise<RPCResponse<string>>;
13
- rescan(): Promise<RPCResponse<void>>;
14
14
  splitAddress(params: SplitAddressParams): Promise<RPCResponse<SplitAddressResult>>;
15
+ rescan(): Promise<RPCResponse<void>>;
15
16
  getBalance(asset?: string): Promise<RPCResponse<number>>;
17
+ hasBalance(asset?: string): Promise<RPCResponse<HasBalanceResult>>;
16
18
  getTrackedAssets(): Promise<RPCResponse<string[]>>;
17
19
  getAssetPrecision(params: GetAssetParams): Promise<RPCResponse<number>>;
18
- getTransaction(hash: string): Promise<RPCResponse<Transaction>>;
20
+ getTransaction(hash: string): Promise<RPCResponse<TransactionEntry>>;
19
21
  buildTransaction(params: BuildTransactionParams): Promise<RPCResponse<BuildTransactionResult>>;
20
- listTransactions(params?: ListTransactionParams): Promise<RPCResponse<Transaction[]>>;
22
+ listTransactions(params?: ListTransactionParams): Promise<RPCResponse<TransactionEntry[]>>;
21
23
  isOnline(): Promise<RPCResponse<boolean>>;
24
+ signData(data: any): Promise<RPCResponse<Signature>>;
25
+ estimateFees(txData: TransactionData): Promise<RPCResponse<number>>;
22
26
  }
23
27
  export default RPC;
package/wallet/rpc.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Base64 } from 'js-base64';
2
2
  import { RPCMethod } from './types';
3
3
  import { RPC as BaseRPC } from '../lib/rpc';
4
- class RPC extends BaseRPC {
4
+ export class RPC extends BaseRPC {
5
5
  constructor(endpoint, username, password) {
6
6
  super(endpoint);
7
7
  const authValue = Base64.encode(`${username}:${password}`);
@@ -15,6 +15,9 @@ class RPC extends BaseRPC {
15
15
  getVersion() {
16
16
  return this.post(RPCMethod.GetVersion);
17
17
  }
18
+ getNetwork() {
19
+ return this.post(RPCMethod.GetNetwork);
20
+ }
18
21
  getNonce() {
19
22
  return this.post(RPCMethod.GetNonce);
20
23
  }
@@ -24,15 +27,18 @@ class RPC extends BaseRPC {
24
27
  getAddress(params = {}) {
25
28
  return this.post(RPCMethod.GetAddress, params);
26
29
  }
27
- rescan() {
28
- return this.post(RPCMethod.Rescan);
29
- }
30
30
  splitAddress(params) {
31
31
  return this.post(RPCMethod.SplitAddress, params);
32
32
  }
33
+ rescan() {
34
+ return this.post(RPCMethod.Rescan);
35
+ }
33
36
  getBalance(asset) {
34
37
  return this.post(RPCMethod.GetBalance, { asset });
35
38
  }
39
+ hasBalance(asset) {
40
+ return this.post(RPCMethod.HasBalance, { asset });
41
+ }
36
42
  getTrackedAssets() {
37
43
  return this.post(RPCMethod.GetTrackedAssets);
38
44
  }
@@ -51,5 +57,11 @@ class RPC extends BaseRPC {
51
57
  isOnline() {
52
58
  return this.post(RPCMethod.IsOnline);
53
59
  }
60
+ signData(data) {
61
+ return this.post(RPCMethod.SignData, data);
62
+ }
63
+ estimateFees(txData) {
64
+ return this.post(RPCMethod.EstimateFees, { tx_type: txData });
65
+ }
54
66
  }
55
67
  export default RPC;
package/wallet/types.d.ts CHANGED
@@ -27,6 +27,31 @@ export interface ListTransactionParams {
27
27
  accept_coinbase?: boolean;
28
28
  accept_burn?: boolean;
29
29
  }
30
+ export interface Signature {
31
+ s: number[];
32
+ e: number[];
33
+ }
34
+ export interface TxCoinbase {
35
+ reward: number;
36
+ }
37
+ export interface TxBurn {
38
+ asset: string;
39
+ amount: number;
40
+ }
41
+ export interface TxIncoming {
42
+ from: string;
43
+ transfers: any;
44
+ }
45
+ export interface TxOutgoing {
46
+ transfers: any;
47
+ fees: number;
48
+ nonce: number;
49
+ }
50
+ export interface TransactionEntry {
51
+ hash: string;
52
+ topoheight: number;
53
+ entry: TxCoinbase | TxBurn | TxIncoming | TxOutgoing;
54
+ }
30
55
  export declare enum RPCMethod {
31
56
  GetVersion = "get_version",
32
57
  GetNetwork = "get_network",
@@ -36,6 +61,7 @@ export declare enum RPCMethod {
36
61
  SplitAddress = "split_address",
37
62
  Rescan = "rescan",
38
63
  GetBalance = "get_balance",
64
+ HasBalance = "has_balance",
39
65
  GetTrackedAssets = "get_tracked_assets",
40
66
  GetAssetPrecision = "get_asset_precision",
41
67
  GetTransaction = "get_transaction",
package/wallet/types.js CHANGED
@@ -8,6 +8,7 @@ export var RPCMethod;
8
8
  RPCMethod["SplitAddress"] = "split_address";
9
9
  RPCMethod["Rescan"] = "rescan";
10
10
  RPCMethod["GetBalance"] = "get_balance";
11
+ RPCMethod["HasBalance"] = "has_balance";
11
12
  RPCMethod["GetTrackedAssets"] = "get_tracked_assets";
12
13
  RPCMethod["GetAssetPrecision"] = "get_asset_precision";
13
14
  RPCMethod["GetTransaction"] = "get_transaction";
@@ -1,6 +1,6 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
- import { GetAssetParams, Transaction } from '../daemon/types';
3
- import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult } from './types';
2
+ import { GetAssetParams, TransactionData } from '../daemon/types';
3
+ import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult, Signature, TransactionEntry } from './types';
4
4
  export declare class WalletMethods {
5
5
  ws: BaseWS;
6
6
  prefix: string;
@@ -11,17 +11,19 @@ export declare class WalletMethods {
11
11
  getNonce(): Promise<number>;
12
12
  getTopoheight(): Promise<number>;
13
13
  getAddress(params?: GetAddressParams): Promise<string>;
14
- rescan(): Promise<void>;
15
14
  splitAddress(params: SplitAddressParams): Promise<SplitAddressResult>;
15
+ rescan(): Promise<void>;
16
16
  getBalance(asset?: string): Promise<number>;
17
17
  getTrackedAssets(): Promise<string[]>;
18
18
  getAssetPrecision(params: GetAssetParams): Promise<number>;
19
- getTransaction(hash: string): Promise<Transaction>;
19
+ getTransaction(hash: string): Promise<TransactionEntry>;
20
20
  buildTransaction(params: BuildTransactionParams): Promise<BuildTransactionResult>;
21
- listTransactions(params?: ListTransactionParams): Promise<Transaction[]>;
21
+ listTransactions(params?: ListTransactionParams): Promise<TransactionEntry[]>;
22
22
  isOnline(): Promise<boolean>;
23
+ signData(data: any): Promise<Signature>;
24
+ estimateFees(txData: TransactionData): Promise<number>;
23
25
  }
24
- declare class WS extends BaseWS {
26
+ export declare class WS extends BaseWS {
25
27
  methods: WalletMethods;
26
28
  constructor(username: string, password: string);
27
29
  }
@@ -23,12 +23,12 @@ export class WalletMethods {
23
23
  getAddress(params = {}) {
24
24
  return this.dataCall(RPCMethod.GetAddress, params);
25
25
  }
26
- rescan() {
27
- return this.dataCall(RPCMethod.Rescan);
28
- }
29
26
  splitAddress(params) {
30
27
  return this.dataCall(RPCMethod.SplitAddress, params);
31
28
  }
29
+ rescan() {
30
+ return this.dataCall(RPCMethod.Rescan);
31
+ }
32
32
  getBalance(asset) {
33
33
  return this.dataCall(RPCMethod.GetBalance, { asset });
34
34
  }
@@ -50,8 +50,14 @@ export class WalletMethods {
50
50
  isOnline() {
51
51
  return this.dataCall(RPCMethod.IsOnline);
52
52
  }
53
+ signData(data) {
54
+ return this.dataCall(RPCMethod.SignData, data);
55
+ }
56
+ estimateFees(txData) {
57
+ return this.dataCall(RPCMethod.EstimateFees, { tx_type: txData });
58
+ }
53
59
  }
54
- class WS extends BaseWS {
60
+ export class WS extends BaseWS {
55
61
  constructor(username, password) {
56
62
  super({ auth: `${username}:${password}` });
57
63
  this.methods = new WalletMethods(this);
@@ -2,7 +2,7 @@ import { WS as BaseWS } from '../lib/websocket';
2
2
  import { ApplicationData } from '../wallet/types';
3
3
  import { DaemonMethods } from '../daemon/websocket';
4
4
  import { WalletMethods } from '../wallet/websocket';
5
- declare class WS extends BaseWS {
5
+ export declare class WS extends BaseWS {
6
6
  daemon: DaemonMethods;
7
7
  wallet: WalletMethods;
8
8
  constructor();
package/xswd/websocket.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
2
  import { DaemonMethods } from '../daemon/websocket';
3
3
  import { WalletMethods } from '../wallet/websocket';
4
- class WS extends BaseWS {
4
+ export class WS extends BaseWS {
5
5
  constructor() {
6
6
  super();
7
7
  this.timeout = 0;