@xelis/sdk 0.2.0 → 0.3.1
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 +6 -4
- package/daemon/rpc.js +12 -3
- package/daemon/types.d.ts +21 -8
- package/daemon/types.js +3 -1
- package/daemon/websocket.d.ts +4 -4
- package/daemon/websocket.js +3 -3
- package/dist +44 -0
- package/package.json +2 -2
package/daemon/rpc.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, RPCMethod, RPCResponse, Transaction,
|
|
1
|
+
import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetLastBalanceResult, P2PStatusResult, RPCMethod, RPCResponse, Transaction, GetLastBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams } from './types';
|
|
2
2
|
declare class RPC {
|
|
3
3
|
endpoint: string;
|
|
4
4
|
constructor(endpoint: string);
|
|
5
5
|
fetch<T>(method: RPCMethod, params?: any): Promise<RPCResponse<T>>;
|
|
6
|
+
getVersion(): Promise<RPCResponse<string>>;
|
|
6
7
|
getInfo(): Promise<RPCResponse<GetInfoResult>>;
|
|
7
8
|
getHeight(): Promise<RPCResponse<number>>;
|
|
8
9
|
getTopoHeight(): Promise<RPCResponse<number>>;
|
|
@@ -13,18 +14,19 @@ declare class RPC {
|
|
|
13
14
|
getBlockByHash(hash: string): Promise<RPCResponse<Block>>;
|
|
14
15
|
getTopBlock(): Promise<RPCResponse<Block>>;
|
|
15
16
|
getNonce(address: string): Promise<RPCResponse<number>>;
|
|
16
|
-
getLastBalance(params:
|
|
17
|
-
getBalanceAtTopoHeight(params:
|
|
17
|
+
getLastBalance(params: GetLastBalanceParams): Promise<RPCResponse<GetLastBalanceResult>>;
|
|
18
|
+
getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<RPCResponse<Balance>>;
|
|
18
19
|
getAssets(): Promise<RPCResponse<string[]>>;
|
|
19
20
|
countTransactions(): Promise<RPCResponse<number>>;
|
|
21
|
+
countAssets(): Promise<RPCResponse<number>>;
|
|
20
22
|
getTips(): Promise<RPCResponse<string[]>>;
|
|
21
23
|
p2pStatus(): Promise<RPCResponse<P2PStatusResult>>;
|
|
22
24
|
getDAGOrder(params: TopoHeightRangeParams): Promise<RPCResponse<string[]>>;
|
|
23
25
|
getMemPool(): Promise<RPCResponse<Transaction[]>>;
|
|
24
26
|
getTransaction(hash: string): Promise<RPCResponse<Transaction>>;
|
|
25
27
|
getTransactions(txHashes: string[]): Promise<RPCResponse<Transaction[]>>;
|
|
26
|
-
getBlocks(params: TopoHeightRangeParams): Promise<RPCResponse<Block[]>>;
|
|
27
28
|
getBlocksRangeByTopoheight(params: TopoHeightRangeParams): Promise<RPCResponse<Block[]>>;
|
|
28
29
|
getBlocksRangeByHeight(params: HeightRangeParams): Promise<RPCResponse<Block[]>>;
|
|
30
|
+
getAccounts(params: GetAccountsParams): Promise<RPCResponse<string[]>>;
|
|
29
31
|
}
|
|
30
32
|
export default RPC;
|
package/daemon/rpc.js
CHANGED
|
@@ -9,6 +9,9 @@ class RPC {
|
|
|
9
9
|
const res = await fetch(this.endpoint, { method: `POST`, body });
|
|
10
10
|
if (res.ok) {
|
|
11
11
|
const data = await res.json();
|
|
12
|
+
if (data.error) {
|
|
13
|
+
return Promise.reject(new Error(data.error.message));
|
|
14
|
+
}
|
|
12
15
|
return Promise.resolve(data);
|
|
13
16
|
}
|
|
14
17
|
else {
|
|
@@ -19,6 +22,9 @@ class RPC {
|
|
|
19
22
|
return Promise.reject(err);
|
|
20
23
|
}
|
|
21
24
|
}
|
|
25
|
+
getVersion() {
|
|
26
|
+
return this.fetch(RPCMethod.GetVersion);
|
|
27
|
+
}
|
|
22
28
|
getInfo() {
|
|
23
29
|
return this.fetch(RPCMethod.GetInfo);
|
|
24
30
|
}
|
|
@@ -61,6 +67,9 @@ class RPC {
|
|
|
61
67
|
countTransactions() {
|
|
62
68
|
return this.fetch(RPCMethod.CountTransactions);
|
|
63
69
|
}
|
|
70
|
+
countAssets() {
|
|
71
|
+
return this.fetch(RPCMethod.CountAssets);
|
|
72
|
+
}
|
|
64
73
|
getTips() {
|
|
65
74
|
return this.fetch(RPCMethod.GetTips);
|
|
66
75
|
}
|
|
@@ -79,14 +88,14 @@ class RPC {
|
|
|
79
88
|
getTransactions(txHashes) {
|
|
80
89
|
return this.fetch(RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
81
90
|
}
|
|
82
|
-
getBlocks(params) {
|
|
83
|
-
return this.fetch(RPCMethod.GetBlocks, params);
|
|
84
|
-
}
|
|
85
91
|
getBlocksRangeByTopoheight(params) {
|
|
86
92
|
return this.fetch(RPCMethod.GetBlocksRangeByTopoheight, params);
|
|
87
93
|
}
|
|
88
94
|
getBlocksRangeByHeight(params) {
|
|
89
95
|
return this.fetch(RPCMethod.GetBlocksRangeByHeight, params);
|
|
90
96
|
}
|
|
97
|
+
getAccounts(params) {
|
|
98
|
+
return this.fetch(RPCMethod.GetAccounts, params);
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
export default RPC;
|
package/daemon/types.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface RPCError {
|
|
|
11
11
|
export interface RPCResponse<T> {
|
|
12
12
|
id: number;
|
|
13
13
|
result: T;
|
|
14
|
-
error
|
|
14
|
+
error?: RPCError;
|
|
15
15
|
}
|
|
16
16
|
export interface GetInfoResult {
|
|
17
17
|
block_time_target: number;
|
|
@@ -47,10 +47,15 @@ export interface Block {
|
|
|
47
47
|
total_size_in_bytes: number;
|
|
48
48
|
txs_hashes: string[];
|
|
49
49
|
}
|
|
50
|
-
export interface
|
|
50
|
+
export interface GetLastBalanceParams {
|
|
51
51
|
address: string;
|
|
52
52
|
asset: string;
|
|
53
53
|
}
|
|
54
|
+
export interface GetBalanceAtTopoHeightParams {
|
|
55
|
+
address: string;
|
|
56
|
+
asset: string;
|
|
57
|
+
topoheight: number;
|
|
58
|
+
}
|
|
54
59
|
export interface Balance {
|
|
55
60
|
balance: number;
|
|
56
61
|
previous_topoheight: number;
|
|
@@ -60,12 +65,12 @@ export interface GetLastBalanceResult {
|
|
|
60
65
|
balance: Balance;
|
|
61
66
|
}
|
|
62
67
|
export interface P2PStatusResult {
|
|
63
|
-
best_height: number;
|
|
64
|
-
max_peers: number;
|
|
65
|
-
our_height: number;
|
|
66
68
|
peer_count: number;
|
|
67
|
-
peer_id: number;
|
|
68
69
|
tag?: string;
|
|
70
|
+
peer_id: number;
|
|
71
|
+
our_topoheight: number;
|
|
72
|
+
best_topoheight: number;
|
|
73
|
+
max_peers: number;
|
|
69
74
|
}
|
|
70
75
|
export interface TopoHeightRangeParams {
|
|
71
76
|
start_topoheight?: number;
|
|
@@ -99,7 +104,14 @@ export interface Transaction {
|
|
|
99
104
|
owner: string;
|
|
100
105
|
signature: string;
|
|
101
106
|
}
|
|
107
|
+
export interface GetAccountsParams {
|
|
108
|
+
skip?: number;
|
|
109
|
+
maximum?: number;
|
|
110
|
+
minimum_topoheight?: number;
|
|
111
|
+
maximum_topoheight?: number;
|
|
112
|
+
}
|
|
102
113
|
export declare enum RPCMethod {
|
|
114
|
+
GetVersion = "get_version",
|
|
103
115
|
GetInfo = "get_info",
|
|
104
116
|
GetHeight = "get_height",
|
|
105
117
|
GetTopoHeight = "get_topoheight",
|
|
@@ -113,6 +125,7 @@ export declare enum RPCMethod {
|
|
|
113
125
|
GetLastBalance = "get_last_balance",
|
|
114
126
|
GetBalanceAtTopoHeight = "get_balance_at_topoheight",
|
|
115
127
|
GetAssets = "get_assets",
|
|
128
|
+
CountAssets = "count_assets",
|
|
116
129
|
CountTransactions = "count_transactions",
|
|
117
130
|
GetTips = "get_tips",
|
|
118
131
|
P2PStatus = "p2p_status",
|
|
@@ -120,9 +133,9 @@ export declare enum RPCMethod {
|
|
|
120
133
|
GetMempool = "get_mempool",
|
|
121
134
|
GetTransaction = "get_transaction",
|
|
122
135
|
GetTransactions = "get_transactions",
|
|
123
|
-
GetBlocks = "get_blocks",
|
|
124
136
|
GetBlocksRangeByTopoheight = "get_blocks_range_by_topoheight",
|
|
125
|
-
GetBlocksRangeByHeight = "get_blocks_range_by_height"
|
|
137
|
+
GetBlocksRangeByHeight = "get_blocks_range_by_height",
|
|
138
|
+
GetAccounts = "get_accounts"
|
|
126
139
|
}
|
|
127
140
|
export declare enum RPCEvent {
|
|
128
141
|
NewBlock = "NewBlock",
|
package/daemon/types.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export var RPCMethod;
|
|
2
2
|
(function (RPCMethod) {
|
|
3
|
+
RPCMethod["GetVersion"] = "get_version";
|
|
3
4
|
RPCMethod["GetInfo"] = "get_info";
|
|
4
5
|
RPCMethod["GetHeight"] = "get_height";
|
|
5
6
|
RPCMethod["GetTopoHeight"] = "get_topoheight";
|
|
@@ -13,6 +14,7 @@ export var RPCMethod;
|
|
|
13
14
|
RPCMethod["GetLastBalance"] = "get_last_balance";
|
|
14
15
|
RPCMethod["GetBalanceAtTopoHeight"] = "get_balance_at_topoheight";
|
|
15
16
|
RPCMethod["GetAssets"] = "get_assets";
|
|
17
|
+
RPCMethod["CountAssets"] = "count_assets";
|
|
16
18
|
RPCMethod["CountTransactions"] = "count_transactions";
|
|
17
19
|
RPCMethod["GetTips"] = "get_tips";
|
|
18
20
|
RPCMethod["P2PStatus"] = "p2p_status";
|
|
@@ -20,9 +22,9 @@ export var RPCMethod;
|
|
|
20
22
|
RPCMethod["GetMempool"] = "get_mempool";
|
|
21
23
|
RPCMethod["GetTransaction"] = "get_transaction";
|
|
22
24
|
RPCMethod["GetTransactions"] = "get_transactions";
|
|
23
|
-
RPCMethod["GetBlocks"] = "get_blocks";
|
|
24
25
|
RPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
|
|
25
26
|
RPCMethod["GetBlocksRangeByHeight"] = "get_blocks_range_by_height";
|
|
27
|
+
RPCMethod["GetAccounts"] = "get_accounts";
|
|
26
28
|
})(RPCMethod || (RPCMethod = {}));
|
|
27
29
|
export var RPCEvent;
|
|
28
30
|
(function (RPCEvent) {
|
package/daemon/websocket.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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,
|
|
4
|
+
import { Block, RPCResponse, GetInfoResult, RPCEvent, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetLastBalanceResult, HeightRangeParams, BlockOrdered, GetLastBalanceParams, GetAccountsParams } from './types';
|
|
5
5
|
declare class WS {
|
|
6
6
|
endpoint: string;
|
|
7
7
|
socket?: WebSocket;
|
|
@@ -32,8 +32,8 @@ declare class WS {
|
|
|
32
32
|
getBlockByHash(hash: string): Promise<Block>;
|
|
33
33
|
getTopBlock(): Promise<Block>;
|
|
34
34
|
getNonce(address: string): Promise<number>;
|
|
35
|
-
getLastBalance(params:
|
|
36
|
-
getBalanceAtTopoHeight(params:
|
|
35
|
+
getLastBalance(params: GetLastBalanceParams): Promise<GetLastBalanceResult>;
|
|
36
|
+
getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<Balance>;
|
|
37
37
|
getAssets(): Promise<string[]>;
|
|
38
38
|
countTransactions(): Promise<number>;
|
|
39
39
|
getTips(): Promise<string[]>;
|
|
@@ -42,8 +42,8 @@ declare class WS {
|
|
|
42
42
|
getMemPool(): Promise<Transaction[]>;
|
|
43
43
|
getTransaction(hash: string): Promise<Transaction>;
|
|
44
44
|
getTransactions(txHashes: string[]): Promise<Transaction[]>;
|
|
45
|
-
getBlocks(params: TopoHeightRangeParams): Promise<Block[]>;
|
|
46
45
|
getBlocksRangeByTopoheight(params: TopoHeightRangeParams): Promise<Block[]>;
|
|
47
46
|
getBlocksRangeByHeight(params: HeightRangeParams): Promise<Block[]>;
|
|
47
|
+
getAccounts(params: GetAccountsParams): Promise<string[]>;
|
|
48
48
|
}
|
|
49
49
|
export default WS;
|
package/daemon/websocket.js
CHANGED
|
@@ -224,14 +224,14 @@ class WS {
|
|
|
224
224
|
getTransactions(txHashes) {
|
|
225
225
|
return this.dataCall(RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
226
226
|
}
|
|
227
|
-
getBlocks(params) {
|
|
228
|
-
return this.dataCall(RPCMethod.GetBlocks, params);
|
|
229
|
-
}
|
|
230
227
|
getBlocksRangeByTopoheight(params) {
|
|
231
228
|
return this.dataCall(RPCMethod.GetBlocksRangeByTopoheight, params);
|
|
232
229
|
}
|
|
233
230
|
getBlocksRangeByHeight(params) {
|
|
234
231
|
return this.dataCall(RPCMethod.GetBlocksRangeByHeight, params);
|
|
235
232
|
}
|
|
233
|
+
getAccounts(params) {
|
|
234
|
+
return this.dataCall(RPCMethod.GetAccounts, params);
|
|
235
|
+
}
|
|
236
236
|
}
|
|
237
237
|
export default WS;
|
package/dist
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# XELIS-JS-SDK
|
|
2
|
+
|
|
3
|
+
Xelis software development kit for JS.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install library with NPM.
|
|
8
|
+
|
|
9
|
+
`npm i @xelis/sdk`
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Import library and start working :).
|
|
14
|
+
|
|
15
|
+
Use http/rpc connection.
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { DEV_NODE_RPC } from '@xelis/sdk/config/nodes'
|
|
19
|
+
import DaemonRPC from '@xelis/sdk/daemon/rpc'
|
|
20
|
+
|
|
21
|
+
const main = async () => {
|
|
22
|
+
const daemonRPC = new DaemonRPC(DEV_NODE_RPC)
|
|
23
|
+
const info = await daemonRPC.getInfo()
|
|
24
|
+
console.log(info)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
main()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Use websocket connection.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { DEV_NODE_RPC } from '@xelis/sdk/config/nodes'
|
|
34
|
+
import DaemonWS from '@xelis/sdk/daemon/websocket'
|
|
35
|
+
|
|
36
|
+
const main = async () => {
|
|
37
|
+
const daemonWS = new DaemonWS()
|
|
38
|
+
await daemonWS.connect(DEV_NODE_RPC)
|
|
39
|
+
const info = await daemonWS.getInfo()
|
|
40
|
+
console.log(info)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main()
|
|
44
|
+
```
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.3.1",
|
|
3
3
|
"name": "@xelis/sdk",
|
|
4
4
|
"description": "Xelis software development kit for JS",
|
|
5
5
|
"repository": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"build": "npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
|
|
13
|
-
"
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
14
|
"publish": "cd ./dist && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|