@xelis/sdk 0.5.10 → 0.5.12

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,11 +15,11 @@ Import library and start working :).
15
15
  Use http/rpc connection.
16
16
 
17
17
  ```js
18
- import { DEV_NODE_RPC } from '@xelis/sdk/config/nodes'
18
+ import { TESTNET_NODE_RPC } from '@xelis/sdk/config/nodes'
19
19
  import DaemonRPC from '@xelis/sdk/daemon/rpc'
20
20
 
21
21
  const main = async () => {
22
- const daemonRPC = new DaemonRPC(DEV_NODE_RPC)
22
+ const daemonRPC = new DaemonRPC(TESTNET_NODE_RPC)
23
23
  const info = await daemonRPC.getInfo()
24
24
  console.log(info)
25
25
  }
@@ -30,12 +30,12 @@ main()
30
30
  Use websocket connection.
31
31
 
32
32
  ```js
33
- import { DEV_NODE_RPC } from '@xelis/sdk/config/nodes'
33
+ import { TESTNET_NODE_WS } from '@xelis/sdk/config/nodes'
34
34
  import DaemonWS from '@xelis/sdk/daemon/websocket'
35
35
 
36
36
  const main = async () => {
37
37
  const daemonWS = new DaemonWS()
38
- await daemonWS.connect(DEV_NODE_RPC)
38
+ await daemonWS.connect(TESTNET_NODE_WS)
39
39
  const info = await daemonWS.getInfo()
40
40
  console.log(info)
41
41
  }
package/config/nodes.d.ts CHANGED
@@ -1,21 +1,15 @@
1
1
  export declare const NODE_URL = "node.xelis.io";
2
2
  export declare const TESTNET_NODE_URL = "testnet-node.xelis.io";
3
- export declare const DEV_NODE_URL = "dev-node.xelis.io";
4
3
  export declare const NODE_RPC: string;
5
4
  export declare const TESTNET_NODE_RPC: string;
6
- export declare const DEV_NODE_RPC: string;
7
5
  export declare const NODE_WS: string;
8
6
  export declare const TESTNET_NODE_WS: string;
9
- export declare const DEV_NODE_WS: string;
10
7
  declare const _default: {
11
8
  NODE_URL: string;
12
9
  TESTNET_NODE_URL: string;
13
- DEV_NODE_URL: string;
14
10
  NODE_RPC: string;
15
11
  TESTNET_NODE_RPC: string;
16
- DEV_NODE_RPC: string;
17
12
  NODE_WS: string;
18
13
  TESTNET_NODE_WS: string;
19
- DEV_NODE_WS: string;
20
14
  };
21
15
  export default _default;
package/config/nodes.js CHANGED
@@ -1,14 +1,11 @@
1
1
  export const NODE_URL = `node.xelis.io`;
2
2
  export const TESTNET_NODE_URL = `testnet-node.xelis.io`;
3
- export const DEV_NODE_URL = `dev-node.xelis.io`;
4
3
  export const NODE_RPC = `https://${NODE_URL}/json_rpc`;
5
4
  export const TESTNET_NODE_RPC = `https://${TESTNET_NODE_URL}/json_rpc`;
6
- export const DEV_NODE_RPC = `https://${DEV_NODE_URL}/json_rpc`;
7
- export const NODE_WS = `wss://${NODE_URL}/ws`;
8
- export const TESTNET_NODE_WS = `wss://${TESTNET_NODE_URL}/ws`;
9
- export const DEV_NODE_WS = `wss://${DEV_NODE_URL}/ws`;
5
+ export const NODE_WS = `wss://${NODE_URL}/json_rpc`;
6
+ export const TESTNET_NODE_WS = `wss://${TESTNET_NODE_URL}/json_rpc`;
10
7
  export default {
11
- NODE_URL, TESTNET_NODE_URL, DEV_NODE_URL,
12
- NODE_RPC, TESTNET_NODE_RPC, DEV_NODE_RPC,
13
- NODE_WS, TESTNET_NODE_WS, DEV_NODE_WS
8
+ NODE_URL, TESTNET_NODE_URL,
9
+ NODE_RPC, TESTNET_NODE_RPC,
10
+ NODE_WS, TESTNET_NODE_WS
14
11
  };
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, GetNonceResult, GetNonceParams, GetAccountHistoryParams, AccounHistory, Peer } from './types';
1
+ import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams, GetAccountHistoryParams, AccounHistory, Peer, DevFee, DiskSize } 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>>;
@@ -32,5 +32,7 @@ declare class RPC extends BaseRPC {
32
32
  getAccountHistory(params: GetAccountHistoryParams): Promise<import("../lib/types").RPCResponse<AccounHistory[]>>;
33
33
  getAccountAssets(address: string): Promise<import("../lib/types").RPCResponse<string[]>>;
34
34
  getPeers(): Promise<import("../lib/types").RPCResponse<Peer[]>>;
35
+ getDevFeeThresholds(): Promise<import("../lib/types").RPCResponse<DevFee[]>>;
36
+ getSizeOnDisk(): Promise<import("../lib/types").RPCResponse<DiskSize>>;
35
37
  }
36
38
  export default RPC;
package/daemon/rpc.js CHANGED
@@ -94,5 +94,11 @@ class RPC extends BaseRPC {
94
94
  getPeers() {
95
95
  return this.post(RPCMethod.GetPeers);
96
96
  }
97
+ getDevFeeThresholds() {
98
+ return this.post(RPCMethod.GetDevFeeThresholds);
99
+ }
100
+ getSizeOnDisk() {
101
+ return this.post(RPCMethod.GetSizeOnDisk);
102
+ }
97
103
  }
98
104
  export default RPC;
package/daemon/types.d.ts CHANGED
@@ -3,9 +3,10 @@ export interface GetInfoResult {
3
3
  difficulty: number;
4
4
  height: number;
5
5
  mempool_size: number;
6
- native_supply: number;
6
+ circulating_supply: number;
7
+ maximum_supply: number;
7
8
  stableheight: number;
8
- top_hash: string;
9
+ top_block_hash: string;
9
10
  version: string;
10
11
  network: string;
11
12
  topoheight: number;
@@ -74,6 +75,9 @@ export interface HeightRangeParams {
74
75
  export interface RPCEventResult {
75
76
  event: string;
76
77
  }
78
+ export type PeerPeers = {
79
+ [ip: string]: `In` | `Out` | `Both`;
80
+ };
77
81
  export interface Peer {
78
82
  id: number;
79
83
  addr: string;
@@ -84,7 +88,7 @@ export interface Peer {
84
88
  height: number;
85
89
  last_ping: number;
86
90
  pruned_topoheight: number;
87
- peers: string[];
91
+ peers: PeerPeers;
88
92
  cumulative_difficulty: number;
89
93
  }
90
94
  export interface BlockOrdered {
@@ -171,6 +175,21 @@ export interface PeerPeerDisconnected {
171
175
  peer_id: number;
172
176
  peer_addr: string;
173
177
  }
178
+ export interface DevFee {
179
+ fee_percentage: number;
180
+ height: number;
181
+ }
182
+ export interface DiskSize {
183
+ size_bytes: number;
184
+ size_formatted: string;
185
+ }
186
+ export interface AssetData {
187
+ asset: string;
188
+ data: {
189
+ topoheight: number;
190
+ decimals: number;
191
+ };
192
+ }
174
193
  export declare enum RPCMethod {
175
194
  GetVersion = "get_version",
176
195
  GetInfo = "get_info",
@@ -202,16 +221,20 @@ export declare enum RPCMethod {
202
221
  CountAccounts = "count_accounts",
203
222
  GetAccountHistory = "get_account_history",
204
223
  GetAccountAssets = "get_account_assets",
205
- GetPeers = "get_peers"
224
+ GetPeers = "get_peers",
225
+ GetDevFeeThresholds = "get_dev_fee_thresholds",
226
+ GetSizeOnDisk = "get_size_on_disk"
206
227
  }
207
228
  export declare enum RPCEvent {
208
- NewBlock = "NewBlock",
209
- TransactionAddedInMempool = "TransactionAddedInMempool",
210
- TransactionExecuted = "TransactionExecuted",
211
- BlockOrdered = "BlockOrdered",
212
- PeerConnected = "PeerConnected",
213
- PeerDisconnected = "PeerDisconnected",
214
- PeerPeerListUpdated = "PeerPeerListUpdated",
215
- PeerPeerDisconnected = "PeerPeerDisconnected",
216
- PeerStateUpdated = "PeerStateUpdated"
229
+ NewBlock = "new_block",
230
+ TransactionAddedInMempool = "transaction_added_in_mempool",
231
+ TransactionExecuted = "transaction_executed",
232
+ BlockOrdered = "block_ordered",
233
+ TransactionSCResult = "transaction_sc_result",
234
+ NewAsset = "new_asset",
235
+ PeerConnected = "peer_connected",
236
+ PeerDisconnected = "peer_disconnected",
237
+ PeerStateUpdated = "peer_state_updated",
238
+ PeerPeerListUpdated = "peer_peer_list_updated",
239
+ PeerPeerDisconnected = "peer_peer_disconnected"
217
240
  }
package/daemon/types.js CHANGED
@@ -31,16 +31,20 @@ export var RPCMethod;
31
31
  RPCMethod["GetAccountHistory"] = "get_account_history";
32
32
  RPCMethod["GetAccountAssets"] = "get_account_assets";
33
33
  RPCMethod["GetPeers"] = "get_peers";
34
+ RPCMethod["GetDevFeeThresholds"] = "get_dev_fee_thresholds";
35
+ RPCMethod["GetSizeOnDisk"] = "get_size_on_disk";
34
36
  })(RPCMethod || (RPCMethod = {}));
35
37
  export var RPCEvent;
36
38
  (function (RPCEvent) {
37
- RPCEvent["NewBlock"] = "NewBlock";
38
- RPCEvent["TransactionAddedInMempool"] = "TransactionAddedInMempool";
39
- RPCEvent["TransactionExecuted"] = "TransactionExecuted";
40
- RPCEvent["BlockOrdered"] = "BlockOrdered";
41
- RPCEvent["PeerConnected"] = "PeerConnected";
42
- RPCEvent["PeerDisconnected"] = "PeerDisconnected";
43
- RPCEvent["PeerPeerListUpdated"] = "PeerPeerListUpdated";
44
- RPCEvent["PeerPeerDisconnected"] = "PeerPeerDisconnected";
45
- RPCEvent["PeerStateUpdated"] = "PeerStateUpdated";
39
+ RPCEvent["NewBlock"] = "new_block";
40
+ RPCEvent["TransactionAddedInMempool"] = "transaction_added_in_mempool";
41
+ RPCEvent["TransactionExecuted"] = "transaction_executed";
42
+ RPCEvent["BlockOrdered"] = "block_ordered";
43
+ RPCEvent["TransactionSCResult"] = "transaction_sc_result";
44
+ RPCEvent["NewAsset"] = "new_asset";
45
+ RPCEvent["PeerConnected"] = "peer_connected";
46
+ RPCEvent["PeerDisconnected"] = "peer_disconnected";
47
+ RPCEvent["PeerStateUpdated"] = "peer_state_updated";
48
+ RPCEvent["PeerPeerListUpdated"] = "peer_peer_list_updated";
49
+ RPCEvent["PeerPeerDisconnected"] = "peer_peer_disconnected";
46
50
  })(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, GetNonceParams, GetNonceResult, GetAccountHistoryParams, AccounHistory, Peer, PeerPeerListUpdated, PeerPeerDisconnected } from './types';
2
+ import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceParams, GetNonceResult, GetAccountHistoryParams, AccounHistory, Peer, PeerPeerListUpdated, PeerPeerDisconnected, DevFee, DiskSize, AssetData } 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>>;
@@ -11,6 +11,7 @@ declare class WS extends BaseWS {
11
11
  onPeerPeerListUpdated(onData: (msgEvent: MessageEvent, data?: PeerPeerListUpdated & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
12
12
  onPeerPeerDisconnected(onData: (msgEvent: MessageEvent, data?: PeerPeerDisconnected & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
13
13
  onPeerStateUpdated(onData: (msgEvent: MessageEvent, data?: Peer & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
14
+ onNewAsset(onData: (msgEvent: MessageEvent, data?: AssetData & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
14
15
  getVersion(): Promise<string>;
15
16
  getInfo(): Promise<GetInfoResult>;
16
17
  getHeight(): Promise<number>;
@@ -41,5 +42,7 @@ declare class WS extends BaseWS {
41
42
  getAccountHistory(params: GetAccountHistoryParams): Promise<AccounHistory[]>;
42
43
  getAccountAssets(address: string): Promise<string[]>;
43
44
  getPeers(): Promise<Peer[]>;
45
+ getDevFeeThresholds(): Promise<DevFee[]>;
46
+ getSizeOnDisk(): Promise<DiskSize>;
44
47
  }
45
48
  export default WS;
@@ -28,6 +28,9 @@ class WS extends BaseWS {
28
28
  onPeerStateUpdated(onData) {
29
29
  return this.listenEvent(RPCEvent.PeerStateUpdated, onData);
30
30
  }
31
+ onNewAsset(onData) {
32
+ return this.listenEvent(RPCEvent.NewAsset, onData);
33
+ }
31
34
  getVersion() {
32
35
  return this.dataCall(RPCMethod.GetVersion);
33
36
  }
@@ -118,5 +121,11 @@ class WS extends BaseWS {
118
121
  getPeers() {
119
122
  return this.dataCall(RPCMethod.GetPeers);
120
123
  }
124
+ getDevFeeThresholds() {
125
+ return this.dataCall(RPCMethod.GetDevFeeThresholds);
126
+ }
127
+ getSizeOnDisk() {
128
+ return this.dataCall(RPCMethod.GetSizeOnDisk);
129
+ }
121
130
  }
122
131
  export default WS;
package/lib/websocket.js CHANGED
@@ -145,6 +145,10 @@ export class WS {
145
145
  }
146
146
  call(method, params) {
147
147
  return new Promise((resolve, reject) => {
148
+ if (!this.socket)
149
+ return reject(new Error(`Socket is not initialized.`));
150
+ if (this.socket.readyState !== WebSocket.OPEN)
151
+ return reject(new Error(`Can't send msg. Socket is not opened.`));
148
152
  const { data, id } = this.createRequestMethod(method, params);
149
153
  let timeoutId = null;
150
154
  const onMessage = (msgEvent) => {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.10",
2
+ "version": "0.5.12",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {
@@ -9,7 +9,7 @@
9
9
  "homepage": "https://github.com/xelis-project/xelis-js-sdk#readme",
10
10
  "scripts": {
11
11
  "test": "jest",
12
- "build": "rm -r ./dist && npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
12
+ "build": "rm -rf ./dist && npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
13
13
  "publish": "cd ./dist && npm publish"
14
14
  },
15
15
  "devDependencies": {