@xelis/sdk 0.5.3 → 0.5.5

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, GetNonceResult, GetNonceParams } from './types';
1
+ import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams, GetAccountHistoryParams, GetAccountHistoryResult } 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>>;
@@ -29,5 +29,7 @@ declare class RPC extends BaseRPC {
29
29
  getAccounts(params: GetAccountsParams): Promise<import("../lib/types").RPCResponse<string[]>>;
30
30
  submitBlock(blockTemplate: string): Promise<import("../lib/types").RPCResponse<boolean>>;
31
31
  submitTransaction(hexData: string): Promise<import("../lib/types").RPCResponse<boolean>>;
32
+ getAccountHistory(params: GetAccountHistoryParams): Promise<import("../lib/types").RPCResponse<GetAccountHistoryResult>>;
33
+ getAccountAssets(address: string): Promise<import("../lib/types").RPCResponse<string[]>>;
32
34
  }
33
35
  export default RPC;
package/daemon/rpc.js CHANGED
@@ -85,5 +85,11 @@ class RPC extends BaseRPC {
85
85
  submitTransaction(hexData) {
86
86
  return this.post(RPCMethod.SubmitTransaction, { data: hexData });
87
87
  }
88
+ getAccountHistory(params) {
89
+ return this.post(RPCMethod.GetAccountHistory, params);
90
+ }
91
+ getAccountAssets(address) {
92
+ return this.post(RPCMethod.GetAccountAssets, { address });
93
+ }
88
94
  }
89
95
  export default RPC;
package/daemon/types.d.ts CHANGED
@@ -129,6 +129,29 @@ export interface GetBlockByHashParams {
129
129
  export interface GetTopBlockParams {
130
130
  include_txs?: boolean;
131
131
  }
132
+ export interface GetAccountHistoryParams {
133
+ address: string;
134
+ asset?: string;
135
+ minimum_topoheight?: number;
136
+ maximum_topoheight?: number;
137
+ }
138
+ export interface GetAccountHistoryResult {
139
+ topoheight: number;
140
+ block_timestamp: number;
141
+ hash: string;
142
+ mining?: {
143
+ reward: number;
144
+ };
145
+ burn?: {
146
+ amount: number;
147
+ };
148
+ outgoing?: {
149
+ amount: number;
150
+ };
151
+ incoming?: {
152
+ amount: number;
153
+ };
154
+ }
132
155
  export declare enum RPCMethod {
133
156
  GetVersion = "get_version",
134
157
  GetInfo = "get_info",
@@ -157,7 +180,9 @@ export declare enum RPCMethod {
157
180
  GetAccounts = "get_accounts",
158
181
  SubmitBlock = "submit_block",
159
182
  SubmitTransaction = "submit_transaction",
160
- CountAccounts = "count_accounts"
183
+ CountAccounts = "count_accounts",
184
+ GetAccountHistory = "get_account_history",
185
+ GetAccountAssets = "get_account_assets"
161
186
  }
162
187
  export declare enum RPCEvent {
163
188
  NewBlock = "NewBlock",
package/daemon/types.js CHANGED
@@ -28,6 +28,8 @@ export var RPCMethod;
28
28
  RPCMethod["SubmitBlock"] = "submit_block";
29
29
  RPCMethod["SubmitTransaction"] = "submit_transaction";
30
30
  RPCMethod["CountAccounts"] = "count_accounts";
31
+ RPCMethod["GetAccountHistory"] = "get_account_history";
32
+ RPCMethod["GetAccountAssets"] = "get_account_assets";
31
33
  })(RPCMethod || (RPCMethod = {}));
32
34
  export var RPCEvent;
33
35
  (function (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 } from './types';
2
+ import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceParams, GetNonceResult, GetAccountHistoryParams, GetAccountHistoryResult } 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>>;
@@ -33,5 +33,7 @@ declare class WS extends BaseWS {
33
33
  submitBlock(blockTemplate: string): Promise<boolean>;
34
34
  submitTransaction(hexData: string): Promise<boolean>;
35
35
  countAccounts(): Promise<number>;
36
+ getAccountHistory(params: GetAccountHistoryParams): Promise<GetAccountHistoryResult>;
37
+ getAccountAssets(address: string): Promise<string[]>;
36
38
  }
37
39
  export default WS;
@@ -94,5 +94,11 @@ class WS extends BaseWS {
94
94
  countAccounts() {
95
95
  return this.dataCall(RPCMethod.CountAccounts);
96
96
  }
97
+ getAccountHistory(params) {
98
+ return this.dataCall(RPCMethod.GetAccountHistory, params);
99
+ }
100
+ getAccountAssets(address) {
101
+ return this.dataCall(RPCMethod.GetAccountAssets, { address });
102
+ }
97
103
  }
98
104
  export default WS;
package/lib/websocket.js CHANGED
@@ -23,6 +23,7 @@ export class WS {
23
23
  if (this.socket && this.socket.readyState === WebSocket.OPEN) {
24
24
  this.socket.close();
25
25
  }
26
+ this.events = {};
26
27
  this.connectionTries = 0;
27
28
  return new Promise((resolve, reject) => {
28
29
  this.socket = new WebSocket(endpoint);
@@ -33,7 +34,7 @@ export class WS {
33
34
  this.socket.addEventListener(`close`, (event) => {
34
35
  if (this.reconnectOnConnectionLoss && !event.wasClean) {
35
36
  this.tryReconnect();
36
- reject(new Error(`Reconnecting.`));
37
+ reject(new Error(`Unhandled close. Reconnecting...`));
37
38
  }
38
39
  else {
39
40
  reject(event);
@@ -50,6 +51,9 @@ export class WS {
50
51
  return;
51
52
  }
52
53
  this.socket = new WebSocket(this.endpoint);
54
+ this.socket.addEventListener(`open`, () => {
55
+ this.connectionTries = 0;
56
+ });
53
57
  this.socket.addEventListener(`close`, (event) => {
54
58
  this.tryReconnect();
55
59
  });
@@ -101,7 +105,7 @@ export class WS {
101
105
  this.events[event].listeners.push(onMessage);
102
106
  }
103
107
  else {
104
- // important if multiple listenEvent are called without await atleast we store listener before getting id
108
+ // important if multiple listenEvent are called without await at least we store listener before getting id
105
109
  this.events[event] = { listeners: [onMessage] };
106
110
  const [err, res] = await to(this.call(`subscribe`, { notify: event }));
107
111
  if (err) {
@@ -121,12 +125,19 @@ export class WS {
121
125
  break;
122
126
  }
123
127
  }
128
+ // no more listener so we unsubscribe from daemon websocket if socket still open
124
129
  if (listeners.length === 0) {
125
- this.events[event].unsubscribeTimeoutId = setTimeout(async () => {
126
- // no more listener so we unsubscribe from daemon websocket
127
- this.call(`unsubscribe`, { notify: event });
130
+ if (this.socket && this.socket.readyState === WebSocket.OPEN) {
131
+ // we use a grace period to unsubscribe (mostly because of react useEffect and avoid unecessary subscribe)
132
+ this.events[event].unsubscribeTimeoutId = setTimeout(async () => {
133
+ this.call(`unsubscribe`, { notify: event });
134
+ Reflect.deleteProperty(this.events, event);
135
+ }, this.unsubscribeSuspense);
136
+ }
137
+ else {
138
+ // socket is closed so we don't send unsubscribe and no grace period delete right away
128
139
  Reflect.deleteProperty(this.events, event);
129
- }, this.unsubscribeSuspense);
140
+ }
130
141
  }
131
142
  }
132
143
  this.socket && this.socket.removeEventListener(`message`, onMessage);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.3",
2
+ "version": "0.5.5",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {