@xelis/sdk 0.5.0 → 0.5.2

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 './types';
1
+ import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams } 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>>;
@@ -11,12 +11,13 @@ declare class RPC extends BaseRPC {
11
11
  getBlocksAtHeight(params: GetBlocksAtHeightParams): Promise<import("../lib/types").RPCResponse<Block[]>>;
12
12
  getBlockByHash(params: GetBlockByHashParams): Promise<import("../lib/types").RPCResponse<Block>>;
13
13
  getTopBlock(params: GetTopBlockParams): Promise<import("../lib/types").RPCResponse<Block>>;
14
- getNonce(address: string): Promise<import("../lib/types").RPCResponse<number>>;
14
+ getNonce(params: GetNonceParams): Promise<import("../lib/types").RPCResponse<GetNonceResult>>;
15
15
  getLastBalance(params: GetLastBalanceParams): Promise<import("../lib/types").RPCResponse<GetLastBalanceResult>>;
16
16
  getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<import("../lib/types").RPCResponse<Balance>>;
17
17
  getAssets(): Promise<import("../lib/types").RPCResponse<string[]>>;
18
18
  countTransactions(): Promise<import("../lib/types").RPCResponse<number>>;
19
19
  countAssets(): Promise<import("../lib/types").RPCResponse<number>>;
20
+ countAccounts(): Promise<import("../lib/types").RPCResponse<number>>;
20
21
  getTips(): Promise<import("../lib/types").RPCResponse<string[]>>;
21
22
  p2pStatus(): Promise<import("../lib/types").RPCResponse<P2PStatusResult>>;
22
23
  getDAGOrder(params: TopoHeightRangeParams): Promise<import("../lib/types").RPCResponse<string[]>>;
package/daemon/rpc.js CHANGED
@@ -31,8 +31,8 @@ class RPC extends BaseRPC {
31
31
  getTopBlock(params) {
32
32
  return this.post(RPCMethod.GetTopBlock, params);
33
33
  }
34
- getNonce(address) {
35
- return this.post(RPCMethod.GetNonce, { address });
34
+ getNonce(params) {
35
+ return this.post(RPCMethod.GetNonce, params);
36
36
  }
37
37
  getLastBalance(params) {
38
38
  return this.post(RPCMethod.GetLastBalance, params);
@@ -49,6 +49,9 @@ class RPC extends BaseRPC {
49
49
  countAssets() {
50
50
  return this.post(RPCMethod.CountAssets);
51
51
  }
52
+ countAccounts() {
53
+ return this.post(RPCMethod.CountAccounts);
54
+ }
52
55
  getTips() {
53
56
  return this.post(RPCMethod.GetTips);
54
57
  }
package/daemon/types.d.ts CHANGED
@@ -41,6 +41,15 @@ export interface GetBalanceAtTopoHeightParams {
41
41
  asset: string;
42
42
  topoheight: number;
43
43
  }
44
+ export interface GetNonceParams {
45
+ address: string;
46
+ topoheight: number;
47
+ }
48
+ export interface GetNonceResult {
49
+ nonce: number;
50
+ previous_topoheight: number;
51
+ topoheight: number;
52
+ }
44
53
  export interface Balance {
45
54
  balance: number;
46
55
  previous_topoheight: number;
@@ -147,7 +156,8 @@ export declare enum RPCMethod {
147
156
  GetBlocksRangeByHeight = "get_blocks_range_by_height",
148
157
  GetAccounts = "get_accounts",
149
158
  SubmitBlock = "submit_block",
150
- SubmitTransaction = "submit_transaction"
159
+ SubmitTransaction = "submit_transaction",
160
+ CountAccounts = "count_accounts"
151
161
  }
152
162
  export declare enum RPCEvent {
153
163
  NewBlock = "NewBlock",
package/daemon/types.js CHANGED
@@ -27,6 +27,7 @@ export var RPCMethod;
27
27
  RPCMethod["GetAccounts"] = "get_accounts";
28
28
  RPCMethod["SubmitBlock"] = "submit_block";
29
29
  RPCMethod["SubmitTransaction"] = "submit_transaction";
30
+ RPCMethod["CountAccounts"] = "count_accounts";
30
31
  })(RPCMethod || (RPCMethod = {}));
31
32
  export var RPCEvent;
32
33
  (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 } from './types';
2
+ import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceParams, GetNonceResult } 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>>;
@@ -16,7 +16,7 @@ declare class WS extends BaseWS {
16
16
  getBlocksAtHeight(params: GetBlocksAtHeightParams): Promise<Block[]>;
17
17
  getBlockByHash(params: GetBlockByHashParams): Promise<Block>;
18
18
  getTopBlock(params: GetTopBlockParams): Promise<Block>;
19
- getNonce(address: string): Promise<number>;
19
+ getNonce(params: GetNonceParams): Promise<GetNonceResult>;
20
20
  getLastBalance(params: GetLastBalanceParams): Promise<GetLastBalanceResult>;
21
21
  getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<Balance>;
22
22
  getAssets(): Promise<string[]>;
@@ -32,5 +32,6 @@ declare class WS extends BaseWS {
32
32
  getAccounts(params: GetAccountsParams): Promise<string[]>;
33
33
  submitBlock(blockTemplate: string): Promise<boolean>;
34
34
  submitTransaction(hexData: string): Promise<boolean>;
35
+ countAccounts(): Promise<number>;
35
36
  }
36
37
  export default WS;
@@ -43,8 +43,8 @@ class WS extends BaseWS {
43
43
  getTopBlock(params) {
44
44
  return this.dataCall(RPCMethod.GetTopBlock, params);
45
45
  }
46
- getNonce(address) {
47
- return this.dataCall(RPCMethod.GetNonce, { address });
46
+ getNonce(params) {
47
+ return this.dataCall(RPCMethod.GetNonce, params);
48
48
  }
49
49
  getLastBalance(params) {
50
50
  return this.dataCall(RPCMethod.GetLastBalance, params);
@@ -91,5 +91,8 @@ class WS extends BaseWS {
91
91
  submitTransaction(hexData) {
92
92
  return this.dataCall(RPCMethod.SubmitTransaction, { data: hexData });
93
93
  }
94
+ countAccounts() {
95
+ return this.dataCall(RPCMethod.CountAccounts);
96
+ }
94
97
  }
95
98
  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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.0",
2
+ "version": "0.5.2",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {