@xelis/sdk 0.5.6 → 0.5.8
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 +2 -1
- package/daemon/rpc.js +3 -0
- package/daemon/types.d.ts +14 -1
- package/daemon/types.js +1 -0
- package/daemon/websocket.d.ts +2 -1
- package/daemon/websocket.js +3 -0
- package/lib/websocket.d.ts +6 -0
- package/lib/websocket.js +15 -9
- package/package.json +2 -2
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 } from './types';
|
|
1
|
+
import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams, GetAccountHistoryParams, AccounHistory, Peer } 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>>;
|
|
@@ -31,5 +31,6 @@ declare class RPC extends BaseRPC {
|
|
|
31
31
|
submitTransaction(hexData: string): Promise<import("../lib/types").RPCResponse<boolean>>;
|
|
32
32
|
getAccountHistory(params: GetAccountHistoryParams): Promise<import("../lib/types").RPCResponse<AccounHistory[]>>;
|
|
33
33
|
getAccountAssets(address: string): Promise<import("../lib/types").RPCResponse<string[]>>;
|
|
34
|
+
getPeers(): Promise<import("../lib/types").RPCResponse<Peer[]>>;
|
|
34
35
|
}
|
|
35
36
|
export default RPC;
|
package/daemon/rpc.js
CHANGED
package/daemon/types.d.ts
CHANGED
|
@@ -74,6 +74,18 @@ export interface HeightRangeParams {
|
|
|
74
74
|
export interface RPCEventResult {
|
|
75
75
|
event: string;
|
|
76
76
|
}
|
|
77
|
+
export interface Peer {
|
|
78
|
+
addr: string;
|
|
79
|
+
cumulative_difficulty: number;
|
|
80
|
+
height: number;
|
|
81
|
+
id: number;
|
|
82
|
+
last_ping: number;
|
|
83
|
+
pruned_topoheight: number;
|
|
84
|
+
tag: string;
|
|
85
|
+
top_block_hash: string;
|
|
86
|
+
topoheight: number;
|
|
87
|
+
version: string;
|
|
88
|
+
}
|
|
77
89
|
export interface BlockOrdered {
|
|
78
90
|
topoheight: number;
|
|
79
91
|
block_hash: string;
|
|
@@ -179,7 +191,8 @@ export declare enum RPCMethod {
|
|
|
179
191
|
SubmitTransaction = "submit_transaction",
|
|
180
192
|
CountAccounts = "count_accounts",
|
|
181
193
|
GetAccountHistory = "get_account_history",
|
|
182
|
-
GetAccountAssets = "get_account_assets"
|
|
194
|
+
GetAccountAssets = "get_account_assets",
|
|
195
|
+
GetPeers = "get_peers"
|
|
183
196
|
}
|
|
184
197
|
export declare enum RPCEvent {
|
|
185
198
|
NewBlock = "NewBlock",
|
package/daemon/types.js
CHANGED
|
@@ -30,6 +30,7 @@ export var RPCMethod;
|
|
|
30
30
|
RPCMethod["CountAccounts"] = "count_accounts";
|
|
31
31
|
RPCMethod["GetAccountHistory"] = "get_account_history";
|
|
32
32
|
RPCMethod["GetAccountAssets"] = "get_account_assets";
|
|
33
|
+
RPCMethod["GetPeers"] = "get_peers";
|
|
33
34
|
})(RPCMethod || (RPCMethod = {}));
|
|
34
35
|
export var RPCEvent;
|
|
35
36
|
(function (RPCEvent) {
|
package/daemon/websocket.d.ts
CHANGED
|
@@ -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 } 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 } 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>>;
|
|
@@ -35,5 +35,6 @@ declare class WS extends BaseWS {
|
|
|
35
35
|
countAccounts(): Promise<number>;
|
|
36
36
|
getAccountHistory(params: GetAccountHistoryParams): Promise<AccounHistory[]>;
|
|
37
37
|
getAccountAssets(address: string): Promise<string[]>;
|
|
38
|
+
getPeers(): Promise<Peer[]>;
|
|
38
39
|
}
|
|
39
40
|
export default WS;
|
package/daemon/websocket.js
CHANGED
package/lib/websocket.d.ts
CHANGED
|
@@ -9,13 +9,19 @@ export declare class WS {
|
|
|
9
9
|
reconnectOnConnectionLoss: boolean;
|
|
10
10
|
maxConnectionTries: number;
|
|
11
11
|
connectionTries: number;
|
|
12
|
+
methodIdIncrement: number;
|
|
12
13
|
private events;
|
|
13
14
|
constructor();
|
|
14
15
|
connect(endpoint: string): Promise<unknown>;
|
|
15
16
|
tryReconnect(): void;
|
|
17
|
+
close(): void;
|
|
16
18
|
private clearEvent;
|
|
17
19
|
closeAllListens(event: string): Promise<void>;
|
|
18
20
|
listenEvent<T>(event: string, onData: (msgEvent: MessageEvent, data?: T, err?: Error) => void): Promise<() => Promise<void>>;
|
|
19
21
|
call<T>(method: string, params?: any): Promise<RPCResponse<T>>;
|
|
20
22
|
dataCall<T>(method: string, params?: any): Promise<T>;
|
|
23
|
+
createRequestMethod(method: string, params?: any): {
|
|
24
|
+
data: string;
|
|
25
|
+
id: number;
|
|
26
|
+
};
|
|
21
27
|
}
|
package/lib/websocket.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
2
|
import to from 'await-to-js';
|
|
3
|
-
function createRequestMethod(method, params) {
|
|
4
|
-
const id = Math.floor(Date.now() * Math.random());
|
|
5
|
-
const request = { id: id, jsonrpc: `2.0`, method };
|
|
6
|
-
if (params)
|
|
7
|
-
request.params = params;
|
|
8
|
-
const data = JSON.stringify(request);
|
|
9
|
-
return { data, id };
|
|
10
|
-
}
|
|
11
3
|
export class WS {
|
|
12
4
|
constructor() {
|
|
13
5
|
this.connectionTries = 0;
|
|
6
|
+
this.methodIdIncrement = 0;
|
|
14
7
|
this.endpoint = "";
|
|
15
8
|
this.timeout = 3000;
|
|
16
9
|
this.events = {};
|
|
@@ -58,6 +51,11 @@ export class WS {
|
|
|
58
51
|
this.tryReconnect();
|
|
59
52
|
});
|
|
60
53
|
}
|
|
54
|
+
close() {
|
|
55
|
+
if (!this.socket)
|
|
56
|
+
return;
|
|
57
|
+
this.socket.close();
|
|
58
|
+
}
|
|
61
59
|
clearEvent(event) {
|
|
62
60
|
this.events[event].listeners.forEach(listener => {
|
|
63
61
|
this.socket && this.socket.removeEventListener(`message`, listener);
|
|
@@ -147,7 +145,7 @@ export class WS {
|
|
|
147
145
|
}
|
|
148
146
|
call(method, params) {
|
|
149
147
|
return new Promise((resolve, reject) => {
|
|
150
|
-
const { data, id } = createRequestMethod(method, params);
|
|
148
|
+
const { data, id } = this.createRequestMethod(method, params);
|
|
151
149
|
let timeoutId = null;
|
|
152
150
|
const onMessage = (msgEvent) => {
|
|
153
151
|
if (typeof msgEvent.data === `string`) {
|
|
@@ -181,4 +179,12 @@ export class WS {
|
|
|
181
179
|
return resolve(res.result);
|
|
182
180
|
});
|
|
183
181
|
}
|
|
182
|
+
createRequestMethod(method, params) {
|
|
183
|
+
const id = this.methodIdIncrement++;
|
|
184
|
+
const request = { id: id, jsonrpc: `2.0`, method };
|
|
185
|
+
if (params)
|
|
186
|
+
request.params = params;
|
|
187
|
+
const data = JSON.stringify(request);
|
|
188
|
+
return { data, id };
|
|
189
|
+
}
|
|
184
190
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.5.
|
|
2
|
+
"version": "0.5.8",
|
|
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": "npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
|
|
12
|
+
"build": "rm -r ./dist && npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
|
|
13
13
|
"publish": "cd ./dist && npm publish"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|