@xelis/sdk 0.4.0 → 0.5.1

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/daemon/rpc.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams } from '../lib/types';
1
+ import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
3
  declare class RPC extends BaseRPC {
4
4
  getVersion(): Promise<import("../lib/types").RPCResponse<string>>;
package/daemon/rpc.js CHANGED
@@ -1,86 +1,86 @@
1
- import { DaemonRPCMethod } from '../lib/types';
1
+ import { RPCMethod } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
3
  class RPC extends BaseRPC {
4
4
  getVersion() {
5
- return this.post(DaemonRPCMethod.GetVersion);
5
+ return this.post(RPCMethod.GetVersion);
6
6
  }
7
7
  getInfo() {
8
- return this.post(DaemonRPCMethod.GetInfo);
8
+ return this.post(RPCMethod.GetInfo);
9
9
  }
10
10
  getHeight() {
11
- return this.post(DaemonRPCMethod.GetHeight);
11
+ return this.post(RPCMethod.GetHeight);
12
12
  }
13
13
  getTopoHeight() {
14
- return this.post(DaemonRPCMethod.GetTopoHeight);
14
+ return this.post(RPCMethod.GetTopoHeight);
15
15
  }
16
16
  getStableHeight() {
17
- return this.post(DaemonRPCMethod.GetStableHeight);
17
+ return this.post(RPCMethod.GetStableHeight);
18
18
  }
19
19
  getBlockTemplate(address) {
20
- return this.post(DaemonRPCMethod.GetBlockTemplate, { address });
20
+ return this.post(RPCMethod.GetBlockTemplate, { address });
21
21
  }
22
22
  getBlockAtTopoHeight(params) {
23
- return this.post(DaemonRPCMethod.GetBlockAtTopoHeight, params);
23
+ return this.post(RPCMethod.GetBlockAtTopoHeight, params);
24
24
  }
25
25
  getBlocksAtHeight(params) {
26
- return this.post(DaemonRPCMethod.GetBlocksAtHeight, params);
26
+ return this.post(RPCMethod.GetBlocksAtHeight, params);
27
27
  }
28
28
  getBlockByHash(params) {
29
- return this.post(DaemonRPCMethod.GetBlockByHash, params);
29
+ return this.post(RPCMethod.GetBlockByHash, params);
30
30
  }
31
31
  getTopBlock(params) {
32
- return this.post(DaemonRPCMethod.GetTopBlock, params);
32
+ return this.post(RPCMethod.GetTopBlock, params);
33
33
  }
34
34
  getNonce(address) {
35
- return this.post(DaemonRPCMethod.GetNonce, { address });
35
+ return this.post(RPCMethod.GetNonce, { address });
36
36
  }
37
37
  getLastBalance(params) {
38
- return this.post(DaemonRPCMethod.GetLastBalance, params);
38
+ return this.post(RPCMethod.GetLastBalance, params);
39
39
  }
40
40
  getBalanceAtTopoHeight(params) {
41
- return this.post(DaemonRPCMethod.GetBalanceAtTopoHeight, params);
41
+ return this.post(RPCMethod.GetBalanceAtTopoHeight, params);
42
42
  }
43
43
  getAssets() {
44
- return this.post(DaemonRPCMethod.GetAssets);
44
+ return this.post(RPCMethod.GetAssets);
45
45
  }
46
46
  countTransactions() {
47
- return this.post(DaemonRPCMethod.CountTransactions);
47
+ return this.post(RPCMethod.CountTransactions);
48
48
  }
49
49
  countAssets() {
50
- return this.post(DaemonRPCMethod.CountAssets);
50
+ return this.post(RPCMethod.CountAssets);
51
51
  }
52
52
  getTips() {
53
- return this.post(DaemonRPCMethod.GetTips);
53
+ return this.post(RPCMethod.GetTips);
54
54
  }
55
55
  p2pStatus() {
56
- return this.post(DaemonRPCMethod.P2PStatus);
56
+ return this.post(RPCMethod.P2PStatus);
57
57
  }
58
58
  getDAGOrder(params) {
59
- return this.post(DaemonRPCMethod.GetDAGOrder, params);
59
+ return this.post(RPCMethod.GetDAGOrder, params);
60
60
  }
61
61
  getMemPool() {
62
- return this.post(DaemonRPCMethod.GetMempool);
62
+ return this.post(RPCMethod.GetMempool);
63
63
  }
64
64
  getTransaction(hash) {
65
- return this.post(DaemonRPCMethod.GetTransaction, { hash });
65
+ return this.post(RPCMethod.GetTransaction, { hash });
66
66
  }
67
67
  getTransactions(txHashes) {
68
- return this.post(DaemonRPCMethod.GetTransactions, { tx_hashes: txHashes });
68
+ return this.post(RPCMethod.GetTransactions, { tx_hashes: txHashes });
69
69
  }
70
70
  getBlocksRangeByTopoheight(params) {
71
- return this.post(DaemonRPCMethod.GetBlocksRangeByTopoheight, params);
71
+ return this.post(RPCMethod.GetBlocksRangeByTopoheight, params);
72
72
  }
73
73
  getBlocksRangeByHeight(params) {
74
- return this.post(DaemonRPCMethod.GetBlocksRangeByHeight, params);
74
+ return this.post(RPCMethod.GetBlocksRangeByHeight, params);
75
75
  }
76
76
  getAccounts(params) {
77
- return this.post(DaemonRPCMethod.GetAccounts, params);
77
+ return this.post(RPCMethod.GetAccounts, params);
78
78
  }
79
79
  submitBlock(blockTemplate) {
80
- return this.post(DaemonRPCMethod.SubmitBlock, { block_template: blockTemplate });
80
+ return this.post(RPCMethod.SubmitBlock, { block_template: blockTemplate });
81
81
  }
82
82
  submitTransaction(hexData) {
83
- return this.post(DaemonRPCMethod.SubmitTransaction, { data: hexData });
83
+ return this.post(RPCMethod.SubmitTransaction, { data: hexData });
84
84
  }
85
85
  }
86
86
  export default RPC;
@@ -0,0 +1,157 @@
1
+ export interface GetInfoResult {
2
+ block_time_target: number;
3
+ difficulty: number;
4
+ height: number;
5
+ mempool_size: number;
6
+ native_supply: number;
7
+ stableheight: number;
8
+ top_hash: string;
9
+ version: string;
10
+ network: string;
11
+ topoheight: number;
12
+ }
13
+ export interface Block {
14
+ block_type: string;
15
+ cumulative_difficulty: number;
16
+ supply: number;
17
+ difficulty: number;
18
+ reward: number;
19
+ extra_nonce: string;
20
+ hash: string;
21
+ height: number;
22
+ miner_tx: {
23
+ owner: string;
24
+ signature: null;
25
+ variant: string;
26
+ };
27
+ miner: string;
28
+ nonce: number;
29
+ tips: string[];
30
+ topoheight: number;
31
+ total_fees: number;
32
+ total_size_in_bytes: number;
33
+ txs_hashes: string[];
34
+ }
35
+ export interface GetLastBalanceParams {
36
+ address: string;
37
+ asset: string;
38
+ }
39
+ export interface GetBalanceAtTopoHeightParams {
40
+ address: string;
41
+ asset: string;
42
+ topoheight: number;
43
+ }
44
+ export interface Balance {
45
+ balance: number;
46
+ previous_topoheight: number;
47
+ }
48
+ export interface GetLastBalanceResult {
49
+ topoheight: number;
50
+ balance: Balance;
51
+ }
52
+ export interface P2PStatusResult {
53
+ peer_count: number;
54
+ tag?: string;
55
+ peer_id: number;
56
+ our_topoheight: number;
57
+ best_topoheight: number;
58
+ max_peers: number;
59
+ }
60
+ export interface TopoHeightRangeParams {
61
+ start_topoheight?: number;
62
+ end_topoheight?: number;
63
+ }
64
+ export interface HeightRangeParams {
65
+ start_height?: number;
66
+ end_height?: number;
67
+ }
68
+ export interface RPCEventResult {
69
+ event: string;
70
+ }
71
+ export interface BlockOrdered {
72
+ topoheight: number;
73
+ block_hash: string;
74
+ block_type: string;
75
+ }
76
+ export interface Transfer {
77
+ amount: number;
78
+ asset: string;
79
+ extra_data?: any;
80
+ to: string;
81
+ }
82
+ export interface TransactionData {
83
+ transfers: Transfer[];
84
+ burn: {
85
+ asset: string;
86
+ amount: number;
87
+ };
88
+ call_contract: {
89
+ contract: string;
90
+ };
91
+ deploy_contract: string;
92
+ }
93
+ export interface Transaction {
94
+ hash: string;
95
+ blocks: string[];
96
+ data: TransactionData;
97
+ fee: number;
98
+ nonce: number;
99
+ owner: string;
100
+ signature: string;
101
+ }
102
+ export interface GetAccountsParams {
103
+ skip?: number;
104
+ maximum?: number;
105
+ minimum_topoheight?: number;
106
+ maximum_topoheight?: number;
107
+ }
108
+ export interface GetBlockAtTopoHeightParams {
109
+ topoheight: number;
110
+ include_txs?: boolean;
111
+ }
112
+ export interface GetBlocksAtHeightParams {
113
+ height: number;
114
+ include_txs?: boolean;
115
+ }
116
+ export interface GetBlockByHashParams {
117
+ hash: string;
118
+ include_txs?: boolean;
119
+ }
120
+ export interface GetTopBlockParams {
121
+ include_txs?: boolean;
122
+ }
123
+ export declare enum RPCMethod {
124
+ GetVersion = "get_version",
125
+ GetInfo = "get_info",
126
+ GetHeight = "get_height",
127
+ GetTopoHeight = "get_topoheight",
128
+ GetStableHeight = "get_stableheight",
129
+ GetBlockTemplate = "get_block_template",
130
+ GetBlockAtTopoHeight = "get_block_at_topoheight",
131
+ GetBlocksAtHeight = "get_blocks_at_height",
132
+ GetBlockByHash = "get_block_by_hash",
133
+ GetTopBlock = "get_top_block",
134
+ GetNonce = "get_nonce",
135
+ GetLastBalance = "get_last_balance",
136
+ GetBalanceAtTopoHeight = "get_balance_at_topoheight",
137
+ GetAssets = "get_assets",
138
+ CountAssets = "count_assets",
139
+ CountTransactions = "count_transactions",
140
+ GetTips = "get_tips",
141
+ P2PStatus = "p2p_status",
142
+ GetDAGOrder = "get_dag_order",
143
+ GetMempool = "get_mempool",
144
+ GetTransaction = "get_transaction",
145
+ GetTransactions = "get_transactions",
146
+ GetBlocksRangeByTopoheight = "get_blocks_range_by_topoheight",
147
+ GetBlocksRangeByHeight = "get_blocks_range_by_height",
148
+ GetAccounts = "get_accounts",
149
+ SubmitBlock = "submit_block",
150
+ SubmitTransaction = "submit_transaction"
151
+ }
152
+ export declare enum RPCEvent {
153
+ NewBlock = "NewBlock",
154
+ TransactionAddedInMempool = "TransactionAddedInMempool",
155
+ TransactionExecuted = "TransactionExecuted",
156
+ BlockOrdered = "BlockOrdered"
157
+ }
@@ -0,0 +1,37 @@
1
+ export var RPCMethod;
2
+ (function (RPCMethod) {
3
+ RPCMethod["GetVersion"] = "get_version";
4
+ RPCMethod["GetInfo"] = "get_info";
5
+ RPCMethod["GetHeight"] = "get_height";
6
+ RPCMethod["GetTopoHeight"] = "get_topoheight";
7
+ RPCMethod["GetStableHeight"] = "get_stableheight";
8
+ RPCMethod["GetBlockTemplate"] = "get_block_template";
9
+ RPCMethod["GetBlockAtTopoHeight"] = "get_block_at_topoheight";
10
+ RPCMethod["GetBlocksAtHeight"] = "get_blocks_at_height";
11
+ RPCMethod["GetBlockByHash"] = "get_block_by_hash";
12
+ RPCMethod["GetTopBlock"] = "get_top_block";
13
+ RPCMethod["GetNonce"] = "get_nonce";
14
+ RPCMethod["GetLastBalance"] = "get_last_balance";
15
+ RPCMethod["GetBalanceAtTopoHeight"] = "get_balance_at_topoheight";
16
+ RPCMethod["GetAssets"] = "get_assets";
17
+ RPCMethod["CountAssets"] = "count_assets";
18
+ RPCMethod["CountTransactions"] = "count_transactions";
19
+ RPCMethod["GetTips"] = "get_tips";
20
+ RPCMethod["P2PStatus"] = "p2p_status";
21
+ RPCMethod["GetDAGOrder"] = "get_dag_order";
22
+ RPCMethod["GetMempool"] = "get_mempool";
23
+ RPCMethod["GetTransaction"] = "get_transaction";
24
+ RPCMethod["GetTransactions"] = "get_transactions";
25
+ RPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
26
+ RPCMethod["GetBlocksRangeByHeight"] = "get_blocks_range_by_height";
27
+ RPCMethod["GetAccounts"] = "get_accounts";
28
+ RPCMethod["SubmitBlock"] = "submit_block";
29
+ RPCMethod["SubmitTransaction"] = "submit_transaction";
30
+ })(RPCMethod || (RPCMethod = {}));
31
+ export var RPCEvent;
32
+ (function (RPCEvent) {
33
+ RPCEvent["NewBlock"] = "NewBlock";
34
+ RPCEvent["TransactionAddedInMempool"] = "TransactionAddedInMempool";
35
+ RPCEvent["TransactionExecuted"] = "TransactionExecuted";
36
+ RPCEvent["BlockOrdered"] = "BlockOrdered";
37
+ })(RPCEvent || (RPCEvent = {}));
@@ -1,5 +1,5 @@
1
1
  import { MessageEvent } from 'ws';
2
- import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams } from '../lib/types';
2
+ import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams } from './types';
3
3
  import { WS as BaseWS } from '../lib/websocket';
4
4
  declare class WS extends BaseWS {
5
5
  onNewBlock(onData: (msgEvent: MessageEvent, data?: Block & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
@@ -1,4 +1,4 @@
1
- import { RPCEvent, DaemonRPCMethod } from '../lib/types';
1
+ import { RPCEvent, RPCMethod } from './types';
2
2
  import { WS as BaseWS } from '../lib/websocket';
3
3
  class WS extends BaseWS {
4
4
  onNewBlock(onData) {
@@ -14,82 +14,82 @@ class WS extends BaseWS {
14
14
  return this.listenEvent(RPCEvent.BlockOrdered, onData);
15
15
  }
16
16
  getVersion() {
17
- return this.dataCall(DaemonRPCMethod.GetVersion);
17
+ return this.dataCall(RPCMethod.GetVersion);
18
18
  }
19
19
  getInfo() {
20
- return this.dataCall(DaemonRPCMethod.GetInfo);
20
+ return this.dataCall(RPCMethod.GetInfo);
21
21
  }
22
22
  getHeight() {
23
- return this.dataCall(DaemonRPCMethod.GetHeight);
23
+ return this.dataCall(RPCMethod.GetHeight);
24
24
  }
25
25
  getTopoHeight() {
26
- return this.dataCall(DaemonRPCMethod.GetTopoHeight);
26
+ return this.dataCall(RPCMethod.GetTopoHeight);
27
27
  }
28
28
  getStableHeight() {
29
- return this.dataCall(DaemonRPCMethod.GetStableHeight);
29
+ return this.dataCall(RPCMethod.GetStableHeight);
30
30
  }
31
31
  getBlockTemplate(address) {
32
- return this.dataCall(DaemonRPCMethod.GetBlockTemplate, { address });
32
+ return this.dataCall(RPCMethod.GetBlockTemplate, { address });
33
33
  }
34
34
  getBlockAtTopoHeight(params) {
35
- return this.dataCall(DaemonRPCMethod.GetBlockAtTopoHeight, params);
35
+ return this.dataCall(RPCMethod.GetBlockAtTopoHeight, params);
36
36
  }
37
37
  getBlocksAtHeight(params) {
38
- return this.dataCall(DaemonRPCMethod.GetBlocksAtHeight, params);
38
+ return this.dataCall(RPCMethod.GetBlocksAtHeight, params);
39
39
  }
40
40
  getBlockByHash(params) {
41
- return this.dataCall(DaemonRPCMethod.GetBlockByHash, params);
41
+ return this.dataCall(RPCMethod.GetBlockByHash, params);
42
42
  }
43
43
  getTopBlock(params) {
44
- return this.dataCall(DaemonRPCMethod.GetTopBlock, params);
44
+ return this.dataCall(RPCMethod.GetTopBlock, params);
45
45
  }
46
46
  getNonce(address) {
47
- return this.dataCall(DaemonRPCMethod.GetNonce, { address });
47
+ return this.dataCall(RPCMethod.GetNonce, { address });
48
48
  }
49
49
  getLastBalance(params) {
50
- return this.dataCall(DaemonRPCMethod.GetLastBalance, params);
50
+ return this.dataCall(RPCMethod.GetLastBalance, params);
51
51
  }
52
52
  getBalanceAtTopoHeight(params) {
53
- return this.dataCall(DaemonRPCMethod.GetBalanceAtTopoHeight, params);
53
+ return this.dataCall(RPCMethod.GetBalanceAtTopoHeight, params);
54
54
  }
55
55
  getAssets() {
56
- return this.dataCall(DaemonRPCMethod.GetAssets);
56
+ return this.dataCall(RPCMethod.GetAssets);
57
57
  }
58
58
  countTransactions() {
59
- return this.dataCall(DaemonRPCMethod.CountTransactions);
59
+ return this.dataCall(RPCMethod.CountTransactions);
60
60
  }
61
61
  getTips() {
62
- return this.dataCall(DaemonRPCMethod.GetTips);
62
+ return this.dataCall(RPCMethod.GetTips);
63
63
  }
64
64
  p2pStatus() {
65
- return this.dataCall(DaemonRPCMethod.P2PStatus);
65
+ return this.dataCall(RPCMethod.P2PStatus);
66
66
  }
67
67
  getDAGOrder(params) {
68
- return this.dataCall(DaemonRPCMethod.GetDAGOrder, params);
68
+ return this.dataCall(RPCMethod.GetDAGOrder, params);
69
69
  }
70
70
  getMemPool() {
71
- return this.dataCall(DaemonRPCMethod.GetMempool);
71
+ return this.dataCall(RPCMethod.GetMempool);
72
72
  }
73
73
  getTransaction(hash) {
74
- return this.dataCall(DaemonRPCMethod.GetTransaction, { hash });
74
+ return this.dataCall(RPCMethod.GetTransaction, { hash });
75
75
  }
76
76
  getTransactions(txHashes) {
77
- return this.dataCall(DaemonRPCMethod.GetTransactions, { tx_hashes: txHashes });
77
+ return this.dataCall(RPCMethod.GetTransactions, { tx_hashes: txHashes });
78
78
  }
79
79
  getBlocksRangeByTopoheight(params) {
80
- return this.dataCall(DaemonRPCMethod.GetBlocksRangeByTopoheight, params);
80
+ return this.dataCall(RPCMethod.GetBlocksRangeByTopoheight, params);
81
81
  }
82
82
  getBlocksRangeByHeight(params) {
83
- return this.dataCall(DaemonRPCMethod.GetBlocksRangeByHeight, params);
83
+ return this.dataCall(RPCMethod.GetBlocksRangeByHeight, params);
84
84
  }
85
85
  getAccounts(params) {
86
- return this.dataCall(DaemonRPCMethod.GetAccounts, params);
86
+ return this.dataCall(RPCMethod.GetAccounts, params);
87
87
  }
88
88
  submitBlock(blockTemplate) {
89
- return this.dataCall(DaemonRPCMethod.SubmitBlock, { block_template: blockTemplate });
89
+ return this.dataCall(RPCMethod.SubmitBlock, { block_template: blockTemplate });
90
90
  }
91
91
  submitTransaction(hexData) {
92
- return this.dataCall(DaemonRPCMethod.SubmitTransaction, { data: hexData });
92
+ return this.dataCall(RPCMethod.SubmitTransaction, { data: hexData });
93
93
  }
94
94
  }
95
95
  export default WS;
package/lib/rpc.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RPCResponse } from './types';
2
2
  export declare class RPC {
3
3
  endpoint: string;
4
+ timeout: number;
4
5
  constructor(endpoint: string);
5
6
  post<T>(method: string, params?: any): Promise<RPCResponse<T>>;
6
7
  }
package/lib/rpc.js CHANGED
@@ -1,11 +1,21 @@
1
1
  export class RPC {
2
2
  constructor(endpoint) {
3
3
  this.endpoint = endpoint;
4
+ this.timeout = 3000;
4
5
  }
5
6
  async post(method, params) {
6
7
  try {
8
+ const controller = new AbortController();
7
9
  const body = JSON.stringify({ id: 1, jsonrpc: '2.0', method: method, params });
8
- const res = await fetch(this.endpoint, { method: `POST`, body });
10
+ const timeoutId = setTimeout(() => {
11
+ controller.abort();
12
+ }, this.timeout);
13
+ const res = await fetch(this.endpoint, {
14
+ method: `POST`,
15
+ body,
16
+ signal: controller.signal
17
+ });
18
+ clearTimeout(timeoutId);
9
19
  if (res.ok) {
10
20
  const data = await res.json();
11
21
  if (data.error) {
package/lib/types.d.ts CHANGED
@@ -13,201 +13,3 @@ export interface RPCResponse<T> {
13
13
  result: T;
14
14
  error?: RPCError;
15
15
  }
16
- export interface GetInfoResult {
17
- block_time_target: number;
18
- difficulty: number;
19
- height: number;
20
- mempool_size: number;
21
- native_supply: number;
22
- stableheight: number;
23
- top_hash: string;
24
- version: string;
25
- network: string;
26
- topoheight: number;
27
- }
28
- export interface Block {
29
- block_type: string;
30
- cumulative_difficulty: number;
31
- supply: number;
32
- difficulty: number;
33
- reward: number;
34
- extra_nonce: string;
35
- hash: string;
36
- height: number;
37
- miner_tx: {
38
- owner: string;
39
- signature: null;
40
- variant: string;
41
- };
42
- miner: string;
43
- nonce: number;
44
- tips: string[];
45
- topoheight: number;
46
- total_fees: number;
47
- total_size_in_bytes: number;
48
- txs_hashes: string[];
49
- }
50
- export interface GetLastBalanceParams {
51
- address: string;
52
- asset: string;
53
- }
54
- export interface GetBalanceAtTopoHeightParams {
55
- address: string;
56
- asset: string;
57
- topoheight: number;
58
- }
59
- export interface Balance {
60
- balance: number;
61
- previous_topoheight: number;
62
- }
63
- export interface GetLastBalanceResult {
64
- topoheight: number;
65
- balance: Balance;
66
- }
67
- export interface P2PStatusResult {
68
- peer_count: number;
69
- tag?: string;
70
- peer_id: number;
71
- our_topoheight: number;
72
- best_topoheight: number;
73
- max_peers: number;
74
- }
75
- export interface TopoHeightRangeParams {
76
- start_topoheight?: number;
77
- end_topoheight?: number;
78
- }
79
- export interface HeightRangeParams {
80
- start_height?: number;
81
- end_height?: number;
82
- }
83
- export interface RPCEventResult {
84
- event: string;
85
- }
86
- export interface BlockOrdered {
87
- topoheight: number;
88
- block_hash: string;
89
- block_type: string;
90
- }
91
- export interface Transfer {
92
- amount: number;
93
- asset: string;
94
- extra_data?: any;
95
- to: string;
96
- }
97
- export interface TransactionData {
98
- transfers: Transfer[];
99
- burn: {
100
- asset: string;
101
- amount: number;
102
- };
103
- call_contract: {
104
- contract: string;
105
- };
106
- deploy_contract: string;
107
- }
108
- export interface Transaction {
109
- hash: string;
110
- blocks: string[];
111
- data: TransactionData;
112
- fee: number;
113
- nonce: number;
114
- owner: string;
115
- signature: string;
116
- }
117
- export interface GetAccountsParams {
118
- skip?: number;
119
- maximum?: number;
120
- minimum_topoheight?: number;
121
- maximum_topoheight?: number;
122
- }
123
- export interface GetBlockAtTopoHeightParams {
124
- topoheight: number;
125
- include_txs?: boolean;
126
- }
127
- export interface GetBlocksAtHeightParams {
128
- height: number;
129
- include_txs?: boolean;
130
- }
131
- export interface GetBlockByHashParams {
132
- hash: string;
133
- include_txs?: boolean;
134
- }
135
- export interface GetTopBlockParams {
136
- include_txs?: boolean;
137
- }
138
- export interface GetAddressParams {
139
- integrated_data?: string;
140
- }
141
- export interface SplitAddressParams {
142
- address: string;
143
- }
144
- export interface SplitAddressResult {
145
- address: string;
146
- integrated_data: string;
147
- }
148
- export interface BuildTransactionParams {
149
- tx_type: TransactionData;
150
- broadcast: boolean;
151
- fee?: number;
152
- }
153
- export interface BuildTransactionResult {
154
- hash: string;
155
- data: Transaction;
156
- }
157
- export interface ListTransactionParams {
158
- min_topoheight?: number;
159
- max_topoheight?: number;
160
- address?: string;
161
- accept_incoming?: boolean;
162
- accept_outgoing?: boolean;
163
- accept_coinbase?: boolean;
164
- accept_burn?: boolean;
165
- }
166
- export declare enum WalletRPCMethod {
167
- GetVersion = "get_version",
168
- GetNetwork = "get_network",
169
- GetNonce = "get_nonce",
170
- GetTopoheight = "get_topoheight",
171
- GetAddress = "get_address",
172
- SplitAddress = "split_address",
173
- GetBalance = "get_balance",
174
- GetTrackedAssets = "get_tracked_assets",
175
- GetTransaction = "get_transaction",
176
- BuildTransaction = "build_transaction",
177
- ListTransactions = "list_transactions"
178
- }
179
- export declare enum DaemonRPCMethod {
180
- GetVersion = "get_version",
181
- GetInfo = "get_info",
182
- GetHeight = "get_height",
183
- GetTopoHeight = "get_topoheight",
184
- GetStableHeight = "get_stableheight",
185
- GetBlockTemplate = "get_block_template",
186
- GetBlockAtTopoHeight = "get_block_at_topoheight",
187
- GetBlocksAtHeight = "get_blocks_at_height",
188
- GetBlockByHash = "get_block_by_hash",
189
- GetTopBlock = "get_top_block",
190
- GetNonce = "get_nonce",
191
- GetLastBalance = "get_last_balance",
192
- GetBalanceAtTopoHeight = "get_balance_at_topoheight",
193
- GetAssets = "get_assets",
194
- CountAssets = "count_assets",
195
- CountTransactions = "count_transactions",
196
- GetTips = "get_tips",
197
- P2PStatus = "p2p_status",
198
- GetDAGOrder = "get_dag_order",
199
- GetMempool = "get_mempool",
200
- GetTransaction = "get_transaction",
201
- GetTransactions = "get_transactions",
202
- GetBlocksRangeByTopoheight = "get_blocks_range_by_topoheight",
203
- GetBlocksRangeByHeight = "get_blocks_range_by_height",
204
- GetAccounts = "get_accounts",
205
- SubmitBlock = "submit_block",
206
- SubmitTransaction = "submit_transaction"
207
- }
208
- export declare enum RPCEvent {
209
- NewBlock = "NewBlock",
210
- TransactionAddedInMempool = "TransactionAddedInMempool",
211
- TransactionExecuted = "TransactionExecuted",
212
- BlockOrdered = "BlockOrdered"
213
- }
package/lib/types.js CHANGED
@@ -1,51 +1 @@
1
- export var WalletRPCMethod;
2
- (function (WalletRPCMethod) {
3
- WalletRPCMethod["GetVersion"] = "get_version";
4
- WalletRPCMethod["GetNetwork"] = "get_network";
5
- WalletRPCMethod["GetNonce"] = "get_nonce";
6
- WalletRPCMethod["GetTopoheight"] = "get_topoheight";
7
- WalletRPCMethod["GetAddress"] = "get_address";
8
- WalletRPCMethod["SplitAddress"] = "split_address";
9
- WalletRPCMethod["GetBalance"] = "get_balance";
10
- WalletRPCMethod["GetTrackedAssets"] = "get_tracked_assets";
11
- WalletRPCMethod["GetTransaction"] = "get_transaction";
12
- WalletRPCMethod["BuildTransaction"] = "build_transaction";
13
- WalletRPCMethod["ListTransactions"] = "list_transactions";
14
- })(WalletRPCMethod || (WalletRPCMethod = {}));
15
- export var DaemonRPCMethod;
16
- (function (DaemonRPCMethod) {
17
- DaemonRPCMethod["GetVersion"] = "get_version";
18
- DaemonRPCMethod["GetInfo"] = "get_info";
19
- DaemonRPCMethod["GetHeight"] = "get_height";
20
- DaemonRPCMethod["GetTopoHeight"] = "get_topoheight";
21
- DaemonRPCMethod["GetStableHeight"] = "get_stableheight";
22
- DaemonRPCMethod["GetBlockTemplate"] = "get_block_template";
23
- DaemonRPCMethod["GetBlockAtTopoHeight"] = "get_block_at_topoheight";
24
- DaemonRPCMethod["GetBlocksAtHeight"] = "get_blocks_at_height";
25
- DaemonRPCMethod["GetBlockByHash"] = "get_block_by_hash";
26
- DaemonRPCMethod["GetTopBlock"] = "get_top_block";
27
- DaemonRPCMethod["GetNonce"] = "get_nonce";
28
- DaemonRPCMethod["GetLastBalance"] = "get_last_balance";
29
- DaemonRPCMethod["GetBalanceAtTopoHeight"] = "get_balance_at_topoheight";
30
- DaemonRPCMethod["GetAssets"] = "get_assets";
31
- DaemonRPCMethod["CountAssets"] = "count_assets";
32
- DaemonRPCMethod["CountTransactions"] = "count_transactions";
33
- DaemonRPCMethod["GetTips"] = "get_tips";
34
- DaemonRPCMethod["P2PStatus"] = "p2p_status";
35
- DaemonRPCMethod["GetDAGOrder"] = "get_dag_order";
36
- DaemonRPCMethod["GetMempool"] = "get_mempool";
37
- DaemonRPCMethod["GetTransaction"] = "get_transaction";
38
- DaemonRPCMethod["GetTransactions"] = "get_transactions";
39
- DaemonRPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
40
- DaemonRPCMethod["GetBlocksRangeByHeight"] = "get_blocks_range_by_height";
41
- DaemonRPCMethod["GetAccounts"] = "get_accounts";
42
- DaemonRPCMethod["SubmitBlock"] = "submit_block";
43
- DaemonRPCMethod["SubmitTransaction"] = "submit_transaction";
44
- })(DaemonRPCMethod || (DaemonRPCMethod = {}));
45
- export var RPCEvent;
46
- (function (RPCEvent) {
47
- RPCEvent["NewBlock"] = "NewBlock";
48
- RPCEvent["TransactionAddedInMempool"] = "TransactionAddedInMempool";
49
- RPCEvent["TransactionExecuted"] = "TransactionExecuted";
50
- RPCEvent["BlockOrdered"] = "BlockOrdered";
51
- })(RPCEvent || (RPCEvent = {}));
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { MessageEvent } from 'ws';
3
3
  import WebSocket from 'isomorphic-ws';
4
- import { RPCResponse, RPCEvent, RPCEventResult } from './types';
4
+ import { RPCResponse } from './types';
5
5
  export declare class WS {
6
6
  endpoint: string;
7
7
  socket?: WebSocket;
@@ -15,8 +15,8 @@ export declare class WS {
15
15
  onClose(cb: (event: WebSocket.CloseEvent) => void): void;
16
16
  onError(cb: (err: WebSocket.ErrorEvent) => void): void;
17
17
  private clearEvent;
18
- closeAllListens(event: RPCEvent): Promise<void>;
19
- listenEvent<T>(event: RPCEvent, onData: (msgEvent: MessageEvent, data?: T & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
18
+ closeAllListens(event: string): Promise<void>;
19
+ listenEvent<T>(event: string, onData: (msgEvent: MessageEvent, data?: T, err?: Error) => void): Promise<() => Promise<void>>;
20
20
  call<T>(method: string, params?: any): Promise<RPCResponse<T>>;
21
21
  dataCall<T>(method: string, params?: any): Promise<T>;
22
22
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.0",
2
+ "version": "0.5.1",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {
package/react/daemon.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
2
  import { MessageEvent } from 'ws';
3
3
  import DaemonWS from '../daemon/websocket';
4
- import { RPCEvent } from '../lib/types';
4
+ import { RPCEvent } from '../daemon/types';
5
5
  interface NodeSocket {
6
6
  daemon: DaemonWS;
7
7
  loading: boolean;
package/wallet/rpc.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Transaction, GetAddressParams, SplitAddressParams, SplitAddressResult, BuildTransactionParams, BuildTransactionResult, ListTransactionParams } from '../lib/types';
1
+ import { Transaction } from '../daemon/types';
2
+ import { GetAddressParams, SplitAddressParams, SplitAddressResult, BuildTransactionParams, BuildTransactionResult, ListTransactionParams } from './types';
2
3
  import { RPC as BaseRPC } from '../lib/rpc';
3
4
  declare class RPC extends BaseRPC {
4
5
  getVersion(): Promise<import("../lib/types").RPCResponse<string>>;
package/wallet/rpc.js CHANGED
@@ -1,35 +1,35 @@
1
- import { WalletRPCMethod } from '../lib/types';
1
+ import { RPCMethod } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
3
  class RPC extends BaseRPC {
4
4
  getVersion() {
5
- return this.post(WalletRPCMethod.GetVersion);
5
+ return this.post(RPCMethod.GetVersion);
6
6
  }
7
7
  getNonce() {
8
- return this.post(WalletRPCMethod.GetNonce);
8
+ return this.post(RPCMethod.GetNonce);
9
9
  }
10
10
  getTopoheight() {
11
- return this.post(WalletRPCMethod.GetTopoheight);
11
+ return this.post(RPCMethod.GetTopoheight);
12
12
  }
13
13
  getAddress(params) {
14
- return this.post(WalletRPCMethod.GetAddress, params);
14
+ return this.post(RPCMethod.GetAddress, params);
15
15
  }
16
16
  splitAddress(params) {
17
- return this.post(WalletRPCMethod.SplitAddress, params);
17
+ return this.post(RPCMethod.SplitAddress, params);
18
18
  }
19
19
  getBalance(asset) {
20
- return this.post(WalletRPCMethod.GetBalance, { asset });
20
+ return this.post(RPCMethod.GetBalance, { asset });
21
21
  }
22
22
  getTrackedAssets() {
23
- return this.post(WalletRPCMethod.GetTrackedAssets);
23
+ return this.post(RPCMethod.GetTrackedAssets);
24
24
  }
25
25
  getTransaction(hash) {
26
- return this.post(WalletRPCMethod.GetTransaction, { hash });
26
+ return this.post(RPCMethod.GetTransaction, { hash });
27
27
  }
28
28
  buildTransaction(params) {
29
- return this.post(WalletRPCMethod.BuildTransaction, params);
29
+ return this.post(RPCMethod.BuildTransaction, params);
30
30
  }
31
31
  listTransactions(params) {
32
- return this.post(WalletRPCMethod.ListTransactions, params);
32
+ return this.post(RPCMethod.ListTransactions, params);
33
33
  }
34
34
  }
35
35
  export default RPC;
@@ -0,0 +1,42 @@
1
+ import { TransactionData, Transaction } from '../daemon/types';
2
+ export interface GetAddressParams {
3
+ integrated_data?: string;
4
+ }
5
+ export interface SplitAddressParams {
6
+ address: string;
7
+ }
8
+ export interface SplitAddressResult {
9
+ address: string;
10
+ integrated_data: string;
11
+ }
12
+ export interface BuildTransactionParams {
13
+ tx_type: TransactionData;
14
+ broadcast: boolean;
15
+ fee?: number;
16
+ }
17
+ export interface BuildTransactionResult {
18
+ hash: string;
19
+ data: Transaction;
20
+ }
21
+ export interface ListTransactionParams {
22
+ min_topoheight?: number;
23
+ max_topoheight?: number;
24
+ address?: string;
25
+ accept_incoming?: boolean;
26
+ accept_outgoing?: boolean;
27
+ accept_coinbase?: boolean;
28
+ accept_burn?: boolean;
29
+ }
30
+ export declare enum RPCMethod {
31
+ GetVersion = "get_version",
32
+ GetNetwork = "get_network",
33
+ GetNonce = "get_nonce",
34
+ GetTopoheight = "get_topoheight",
35
+ GetAddress = "get_address",
36
+ SplitAddress = "split_address",
37
+ GetBalance = "get_balance",
38
+ GetTrackedAssets = "get_tracked_assets",
39
+ GetTransaction = "get_transaction",
40
+ BuildTransaction = "build_transaction",
41
+ ListTransactions = "list_transactions"
42
+ }
@@ -0,0 +1,14 @@
1
+ export var RPCMethod;
2
+ (function (RPCMethod) {
3
+ RPCMethod["GetVersion"] = "get_version";
4
+ RPCMethod["GetNetwork"] = "get_network";
5
+ RPCMethod["GetNonce"] = "get_nonce";
6
+ RPCMethod["GetTopoheight"] = "get_topoheight";
7
+ RPCMethod["GetAddress"] = "get_address";
8
+ RPCMethod["SplitAddress"] = "split_address";
9
+ RPCMethod["GetBalance"] = "get_balance";
10
+ RPCMethod["GetTrackedAssets"] = "get_tracked_assets";
11
+ RPCMethod["GetTransaction"] = "get_transaction";
12
+ RPCMethod["BuildTransaction"] = "build_transaction";
13
+ RPCMethod["ListTransactions"] = "list_transactions";
14
+ })(RPCMethod || (RPCMethod = {}));
@@ -1,5 +1,6 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
- import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult, Transaction } from '../lib/types';
2
+ import { Transaction } from '../daemon/types';
3
+ import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult } from './types';
3
4
  declare class WS extends BaseWS {
4
5
  getVersion(): Promise<string>;
5
6
  getNetwork(): Promise<string>;
@@ -1,38 +1,38 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
- import { WalletRPCMethod } from '../lib/types';
2
+ import { RPCMethod } from './types';
3
3
  class WS extends BaseWS {
4
4
  getVersion() {
5
- return this.dataCall(WalletRPCMethod.GetVersion);
5
+ return this.dataCall(RPCMethod.GetVersion);
6
6
  }
7
7
  getNetwork() {
8
- return this.dataCall(WalletRPCMethod.GetNetwork);
8
+ return this.dataCall(RPCMethod.GetNetwork);
9
9
  }
10
10
  getNonce() {
11
- return this.dataCall(WalletRPCMethod.GetNonce);
11
+ return this.dataCall(RPCMethod.GetNonce);
12
12
  }
13
13
  getTopoheight() {
14
- return this.dataCall(WalletRPCMethod.GetTopoheight);
14
+ return this.dataCall(RPCMethod.GetTopoheight);
15
15
  }
16
16
  getAddress(params) {
17
- return this.dataCall(WalletRPCMethod.GetAddress, params);
17
+ return this.dataCall(RPCMethod.GetAddress, params);
18
18
  }
19
19
  splitAddress(params) {
20
- return this.dataCall(WalletRPCMethod.SplitAddress, params);
20
+ return this.dataCall(RPCMethod.SplitAddress, params);
21
21
  }
22
22
  getBalance(asset) {
23
- return this.dataCall(WalletRPCMethod.GetBalance, { asset });
23
+ return this.dataCall(RPCMethod.GetBalance, { asset });
24
24
  }
25
25
  getTrackedAssets() {
26
- return this.dataCall(WalletRPCMethod.GetTrackedAssets);
26
+ return this.dataCall(RPCMethod.GetTrackedAssets);
27
27
  }
28
28
  getTransaction(hash) {
29
- return this.dataCall(WalletRPCMethod.GetTransaction, { hash });
29
+ return this.dataCall(RPCMethod.GetTransaction, { hash });
30
30
  }
31
31
  buildTransaction(params) {
32
- return this.dataCall(WalletRPCMethod.BuildTransaction, params);
32
+ return this.dataCall(RPCMethod.BuildTransaction, params);
33
33
  }
34
34
  listTransactions(params) {
35
- return this.dataCall(WalletRPCMethod.GetTransaction, params);
35
+ return this.dataCall(RPCMethod.GetTransaction, params);
36
36
  }
37
37
  }
38
38
  export default WS;