@xelis/sdk 0.3.1 → 0.3.3
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 +5 -5
- package/daemon/rpc.js +8 -8
- package/daemon/types.d.ts +15 -0
- package/daemon/websocket.d.ts +6 -5
- package/daemon/websocket.js +32 -15
- package/package.json +1 -1
package/daemon/rpc.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, RPCMethod, RPCResponse, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams } from './types';
|
|
1
|
+
import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, RPCMethod, RPCResponse, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams } from './types';
|
|
2
2
|
declare class RPC {
|
|
3
3
|
endpoint: string;
|
|
4
4
|
constructor(endpoint: string);
|
|
@@ -9,10 +9,10 @@ declare class RPC {
|
|
|
9
9
|
getTopoHeight(): Promise<RPCResponse<number>>;
|
|
10
10
|
getStableHeight(): Promise<RPCResponse<number>>;
|
|
11
11
|
getBlockTemplate(address: string): Promise<RPCResponse<string>>;
|
|
12
|
-
getBlockAtTopoHeight(
|
|
13
|
-
getBlocksAtHeight(
|
|
14
|
-
getBlockByHash(
|
|
15
|
-
getTopBlock(): Promise<RPCResponse<Block>>;
|
|
12
|
+
getBlockAtTopoHeight(params: GetBlockAtTopoHeightParams): Promise<RPCResponse<Block>>;
|
|
13
|
+
getBlocksAtHeight(params: GetBlocksAtHeightParams): Promise<RPCResponse<Block[]>>;
|
|
14
|
+
getBlockByHash(params: GetBlockByHashParams): Promise<RPCResponse<Block>>;
|
|
15
|
+
getTopBlock(params: GetTopBlockParams): Promise<RPCResponse<Block>>;
|
|
16
16
|
getNonce(address: string): Promise<RPCResponse<number>>;
|
|
17
17
|
getLastBalance(params: GetLastBalanceParams): Promise<RPCResponse<GetLastBalanceResult>>;
|
|
18
18
|
getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<RPCResponse<Balance>>;
|
package/daemon/rpc.js
CHANGED
|
@@ -40,17 +40,17 @@ class RPC {
|
|
|
40
40
|
getBlockTemplate(address) {
|
|
41
41
|
return this.fetch(RPCMethod.GetBlockTemplate, { address });
|
|
42
42
|
}
|
|
43
|
-
getBlockAtTopoHeight(
|
|
44
|
-
return this.fetch(RPCMethod.GetBlockAtTopoHeight,
|
|
43
|
+
getBlockAtTopoHeight(params) {
|
|
44
|
+
return this.fetch(RPCMethod.GetBlockAtTopoHeight, params);
|
|
45
45
|
}
|
|
46
|
-
getBlocksAtHeight(
|
|
47
|
-
return this.fetch(RPCMethod.GetBlocksAtHeight,
|
|
46
|
+
getBlocksAtHeight(params) {
|
|
47
|
+
return this.fetch(RPCMethod.GetBlocksAtHeight, params);
|
|
48
48
|
}
|
|
49
|
-
getBlockByHash(
|
|
50
|
-
return this.fetch(RPCMethod.GetBlockByHash,
|
|
49
|
+
getBlockByHash(params) {
|
|
50
|
+
return this.fetch(RPCMethod.GetBlockByHash, params);
|
|
51
51
|
}
|
|
52
|
-
getTopBlock() {
|
|
53
|
-
return this.fetch(RPCMethod.GetTopBlock);
|
|
52
|
+
getTopBlock(params) {
|
|
53
|
+
return this.fetch(RPCMethod.GetTopBlock, params);
|
|
54
54
|
}
|
|
55
55
|
getNonce(address) {
|
|
56
56
|
return this.fetch(RPCMethod.GetNonce, { address });
|
package/daemon/types.d.ts
CHANGED
|
@@ -110,6 +110,21 @@ export interface GetAccountsParams {
|
|
|
110
110
|
minimum_topoheight?: number;
|
|
111
111
|
maximum_topoheight?: number;
|
|
112
112
|
}
|
|
113
|
+
export interface GetBlockAtTopoHeightParams {
|
|
114
|
+
topoheight: number;
|
|
115
|
+
include_txs?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface GetBlocksAtHeightParams {
|
|
118
|
+
height: number;
|
|
119
|
+
include_txs?: boolean;
|
|
120
|
+
}
|
|
121
|
+
export interface GetBlockByHashParams {
|
|
122
|
+
hash: string;
|
|
123
|
+
include_txs?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface GetTopBlockParams {
|
|
126
|
+
include_txs?: boolean;
|
|
127
|
+
}
|
|
113
128
|
export declare enum RPCMethod {
|
|
114
129
|
GetVersion = "get_version",
|
|
115
130
|
GetInfo = "get_info",
|
package/daemon/websocket.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { MessageEvent } from 'ws';
|
|
3
3
|
import WebSocket from 'isomorphic-ws';
|
|
4
|
-
import { Block, RPCResponse, GetInfoResult, RPCEvent, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams } from './types';
|
|
4
|
+
import { Block, RPCResponse, GetInfoResult, RPCEvent, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams } from './types';
|
|
5
5
|
declare class WS {
|
|
6
6
|
endpoint: string;
|
|
7
7
|
socket?: WebSocket;
|
|
8
8
|
timeout: number;
|
|
9
9
|
connected: boolean;
|
|
10
|
+
unsubscribeSuspense: number;
|
|
10
11
|
private events;
|
|
11
12
|
constructor();
|
|
12
13
|
connect(endpoint: string): Promise<unknown>;
|
|
@@ -27,10 +28,10 @@ declare class WS {
|
|
|
27
28
|
getTopoHeight(): Promise<number>;
|
|
28
29
|
getStableHeight(): Promise<number>;
|
|
29
30
|
getBlockTemplate(address: string): Promise<string>;
|
|
30
|
-
getBlockAtTopoHeight(
|
|
31
|
-
getBlocksAtHeight(
|
|
32
|
-
getBlockByHash(
|
|
33
|
-
getTopBlock(): Promise<Block>;
|
|
31
|
+
getBlockAtTopoHeight(params: GetBlockAtTopoHeightParams): Promise<Block>;
|
|
32
|
+
getBlocksAtHeight(params: GetBlocksAtHeightParams): Promise<Block[]>;
|
|
33
|
+
getBlockByHash(params: GetBlockByHashParams): Promise<Block>;
|
|
34
|
+
getTopBlock(params: GetTopBlockParams): Promise<Block>;
|
|
34
35
|
getNonce(address: string): Promise<number>;
|
|
35
36
|
getLastBalance(params: GetLastBalanceParams): Promise<GetLastBalanceResult>;
|
|
36
37
|
getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<Balance>;
|
package/daemon/websocket.js
CHANGED
|
@@ -15,6 +15,7 @@ class WS {
|
|
|
15
15
|
this.timeout = 3000;
|
|
16
16
|
this.connected = false;
|
|
17
17
|
this.events = {};
|
|
18
|
+
this.unsubscribeSuspense = 1000;
|
|
18
19
|
}
|
|
19
20
|
connect(endpoint) {
|
|
20
21
|
if (this.socket && this.socket.readyState !== WebSocket.CLOSED) {
|
|
@@ -92,6 +93,12 @@ class WS {
|
|
|
92
93
|
}
|
|
93
94
|
};
|
|
94
95
|
if (this.events[event]) {
|
|
96
|
+
const { unsubscribeTimeoutId } = this.events[event];
|
|
97
|
+
if (unsubscribeTimeoutId) {
|
|
98
|
+
// clear timeout to unsubscribe
|
|
99
|
+
// because we got a new registered event and want to cancel the pending unsubscribe grace period
|
|
100
|
+
clearTimeout(unsubscribeTimeoutId);
|
|
101
|
+
}
|
|
95
102
|
this.events[event].listeners.push(onMessage);
|
|
96
103
|
}
|
|
97
104
|
else {
|
|
@@ -105,13 +112,23 @@ class WS {
|
|
|
105
112
|
this.events[event].id = res.id;
|
|
106
113
|
}
|
|
107
114
|
this.socket && this.socket.addEventListener(`message`, onMessage);
|
|
108
|
-
const closeListen =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
const closeListen = () => {
|
|
116
|
+
const eventData = this.events[event];
|
|
117
|
+
if (eventData) {
|
|
118
|
+
const listeners = eventData.listeners;
|
|
119
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
120
|
+
if (listeners[i] === onMessage) {
|
|
121
|
+
listeners.splice(i, 1);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (listeners.length === 0) {
|
|
126
|
+
this.events[event].unsubscribeTimeoutId = setTimeout(async () => {
|
|
127
|
+
// no more listener so we unsubscribe from daemon websocket
|
|
128
|
+
this.call(`unsubscribe`, { notify: event });
|
|
129
|
+
Reflect.deleteProperty(this.events, event);
|
|
130
|
+
}, this.unsubscribeSuspense);
|
|
131
|
+
}
|
|
115
132
|
}
|
|
116
133
|
this.socket && this.socket.removeEventListener(`message`, onMessage);
|
|
117
134
|
return Promise.resolve();
|
|
@@ -179,17 +196,17 @@ class WS {
|
|
|
179
196
|
getBlockTemplate(address) {
|
|
180
197
|
return this.dataCall(RPCMethod.GetBlockTemplate, { address });
|
|
181
198
|
}
|
|
182
|
-
getBlockAtTopoHeight(
|
|
183
|
-
return this.dataCall(RPCMethod.GetBlockAtTopoHeight,
|
|
199
|
+
getBlockAtTopoHeight(params) {
|
|
200
|
+
return this.dataCall(RPCMethod.GetBlockAtTopoHeight, params);
|
|
184
201
|
}
|
|
185
|
-
getBlocksAtHeight(
|
|
186
|
-
return this.dataCall(RPCMethod.GetBlocksAtHeight,
|
|
202
|
+
getBlocksAtHeight(params) {
|
|
203
|
+
return this.dataCall(RPCMethod.GetBlocksAtHeight, params);
|
|
187
204
|
}
|
|
188
|
-
getBlockByHash(
|
|
189
|
-
return this.dataCall(RPCMethod.GetBlockByHash,
|
|
205
|
+
getBlockByHash(params) {
|
|
206
|
+
return this.dataCall(RPCMethod.GetBlockByHash, params);
|
|
190
207
|
}
|
|
191
|
-
getTopBlock() {
|
|
192
|
-
return this.dataCall(RPCMethod.GetTopBlock);
|
|
208
|
+
getTopBlock(params) {
|
|
209
|
+
return this.dataCall(RPCMethod.GetTopBlock, params);
|
|
193
210
|
}
|
|
194
211
|
getNonce(address) {
|
|
195
212
|
return this.dataCall(RPCMethod.GetNonce, { address });
|
package/package.json
CHANGED