@xelis/sdk 0.3.2 → 0.3.4
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 +8 -6
- package/daemon/rpc.js +36 -30
- package/daemon/types.d.ts +36 -9
- package/daemon/types.js +2 -0
- package/daemon/websocket.d.ts +7 -5
- package/daemon/websocket.js +14 -8
- package/package.json +1 -2
- package/dist +0 -44
package/daemon/rpc.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
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);
|
|
5
|
-
|
|
5
|
+
post<T>(method: RPCMethod, params?: any): Promise<RPCResponse<T>>;
|
|
6
6
|
getVersion(): Promise<RPCResponse<string>>;
|
|
7
7
|
getInfo(): Promise<RPCResponse<GetInfoResult>>;
|
|
8
8
|
getHeight(): Promise<RPCResponse<number>>;
|
|
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>>;
|
|
@@ -28,5 +28,7 @@ declare class RPC {
|
|
|
28
28
|
getBlocksRangeByTopoheight(params: TopoHeightRangeParams): Promise<RPCResponse<Block[]>>;
|
|
29
29
|
getBlocksRangeByHeight(params: HeightRangeParams): Promise<RPCResponse<Block[]>>;
|
|
30
30
|
getAccounts(params: GetAccountsParams): Promise<RPCResponse<string[]>>;
|
|
31
|
+
submitBlock(blockTemplate: string): Promise<RPCResponse<boolean>>;
|
|
32
|
+
submitTransaction(hexData: string): Promise<RPCResponse<boolean>>;
|
|
31
33
|
}
|
|
32
34
|
export default RPC;
|
package/daemon/rpc.js
CHANGED
|
@@ -3,7 +3,7 @@ class RPC {
|
|
|
3
3
|
constructor(endpoint) {
|
|
4
4
|
this.endpoint = endpoint;
|
|
5
5
|
}
|
|
6
|
-
async
|
|
6
|
+
async post(method, params) {
|
|
7
7
|
try {
|
|
8
8
|
const body = JSON.stringify({ id: 1, jsonrpc: '2.0', method: method, params });
|
|
9
9
|
const res = await fetch(this.endpoint, { method: `POST`, body });
|
|
@@ -23,79 +23,85 @@ class RPC {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
getVersion() {
|
|
26
|
-
return this.
|
|
26
|
+
return this.post(RPCMethod.GetVersion);
|
|
27
27
|
}
|
|
28
28
|
getInfo() {
|
|
29
|
-
return this.
|
|
29
|
+
return this.post(RPCMethod.GetInfo);
|
|
30
30
|
}
|
|
31
31
|
getHeight() {
|
|
32
|
-
return this.
|
|
32
|
+
return this.post(RPCMethod.GetHeight);
|
|
33
33
|
}
|
|
34
34
|
getTopoHeight() {
|
|
35
|
-
return this.
|
|
35
|
+
return this.post(RPCMethod.GetTopoHeight);
|
|
36
36
|
}
|
|
37
37
|
getStableHeight() {
|
|
38
|
-
return this.
|
|
38
|
+
return this.post(RPCMethod.GetStableHeight);
|
|
39
39
|
}
|
|
40
40
|
getBlockTemplate(address) {
|
|
41
|
-
return this.
|
|
41
|
+
return this.post(RPCMethod.GetBlockTemplate, { address });
|
|
42
42
|
}
|
|
43
|
-
getBlockAtTopoHeight(
|
|
44
|
-
return this.
|
|
43
|
+
getBlockAtTopoHeight(params) {
|
|
44
|
+
return this.post(RPCMethod.GetBlockAtTopoHeight, params);
|
|
45
45
|
}
|
|
46
|
-
getBlocksAtHeight(
|
|
47
|
-
return this.
|
|
46
|
+
getBlocksAtHeight(params) {
|
|
47
|
+
return this.post(RPCMethod.GetBlocksAtHeight, params);
|
|
48
48
|
}
|
|
49
|
-
getBlockByHash(
|
|
50
|
-
return this.
|
|
49
|
+
getBlockByHash(params) {
|
|
50
|
+
return this.post(RPCMethod.GetBlockByHash, params);
|
|
51
51
|
}
|
|
52
|
-
getTopBlock() {
|
|
53
|
-
return this.
|
|
52
|
+
getTopBlock(params) {
|
|
53
|
+
return this.post(RPCMethod.GetTopBlock, params);
|
|
54
54
|
}
|
|
55
55
|
getNonce(address) {
|
|
56
|
-
return this.
|
|
56
|
+
return this.post(RPCMethod.GetNonce, { address });
|
|
57
57
|
}
|
|
58
58
|
getLastBalance(params) {
|
|
59
|
-
return this.
|
|
59
|
+
return this.post(RPCMethod.GetLastBalance, params);
|
|
60
60
|
}
|
|
61
61
|
getBalanceAtTopoHeight(params) {
|
|
62
|
-
return this.
|
|
62
|
+
return this.post(RPCMethod.GetBalanceAtTopoHeight, params);
|
|
63
63
|
}
|
|
64
64
|
getAssets() {
|
|
65
|
-
return this.
|
|
65
|
+
return this.post(RPCMethod.GetAssets);
|
|
66
66
|
}
|
|
67
67
|
countTransactions() {
|
|
68
|
-
return this.
|
|
68
|
+
return this.post(RPCMethod.CountTransactions);
|
|
69
69
|
}
|
|
70
70
|
countAssets() {
|
|
71
|
-
return this.
|
|
71
|
+
return this.post(RPCMethod.CountAssets);
|
|
72
72
|
}
|
|
73
73
|
getTips() {
|
|
74
|
-
return this.
|
|
74
|
+
return this.post(RPCMethod.GetTips);
|
|
75
75
|
}
|
|
76
76
|
p2pStatus() {
|
|
77
|
-
return this.
|
|
77
|
+
return this.post(RPCMethod.P2PStatus);
|
|
78
78
|
}
|
|
79
79
|
getDAGOrder(params) {
|
|
80
|
-
return this.
|
|
80
|
+
return this.post(RPCMethod.GetDAGOrder, params);
|
|
81
81
|
}
|
|
82
82
|
getMemPool() {
|
|
83
|
-
return this.
|
|
83
|
+
return this.post(RPCMethod.GetMempool);
|
|
84
84
|
}
|
|
85
85
|
getTransaction(hash) {
|
|
86
|
-
return this.
|
|
86
|
+
return this.post(RPCMethod.GetTransaction, { hash });
|
|
87
87
|
}
|
|
88
88
|
getTransactions(txHashes) {
|
|
89
|
-
return this.
|
|
89
|
+
return this.post(RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
90
90
|
}
|
|
91
91
|
getBlocksRangeByTopoheight(params) {
|
|
92
|
-
return this.
|
|
92
|
+
return this.post(RPCMethod.GetBlocksRangeByTopoheight, params);
|
|
93
93
|
}
|
|
94
94
|
getBlocksRangeByHeight(params) {
|
|
95
|
-
return this.
|
|
95
|
+
return this.post(RPCMethod.GetBlocksRangeByHeight, params);
|
|
96
96
|
}
|
|
97
97
|
getAccounts(params) {
|
|
98
|
-
return this.
|
|
98
|
+
return this.post(RPCMethod.GetAccounts, params);
|
|
99
|
+
}
|
|
100
|
+
submitBlock(blockTemplate) {
|
|
101
|
+
return this.post(RPCMethod.SubmitBlock, { block_template: blockTemplate });
|
|
102
|
+
}
|
|
103
|
+
submitTransaction(hexData) {
|
|
104
|
+
return this.post(RPCMethod.SubmitTransaction, { data: hexData });
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
export default RPC;
|
package/daemon/types.d.ts
CHANGED
|
@@ -88,17 +88,27 @@ export interface BlockOrdered {
|
|
|
88
88
|
block_hash: string;
|
|
89
89
|
block_type: string;
|
|
90
90
|
}
|
|
91
|
+
export interface Transfer {
|
|
92
|
+
amount: number;
|
|
93
|
+
asset: string;
|
|
94
|
+
extra_data?: any;
|
|
95
|
+
to: string;
|
|
96
|
+
}
|
|
97
|
+
export interface TransactionData {
|
|
98
|
+
transfers: Transfer[];
|
|
99
|
+
burn: {
|
|
100
|
+
asset: string;
|
|
101
|
+
amount: number;
|
|
102
|
+
};
|
|
103
|
+
call_contract: {
|
|
104
|
+
contract: string;
|
|
105
|
+
};
|
|
106
|
+
deploy_contract: string;
|
|
107
|
+
}
|
|
91
108
|
export interface Transaction {
|
|
92
109
|
hash: string;
|
|
93
110
|
blocks: string[];
|
|
94
|
-
data:
|
|
95
|
-
Transfer: {
|
|
96
|
-
amount: number;
|
|
97
|
-
asset: string;
|
|
98
|
-
extra_data: any;
|
|
99
|
-
to: string;
|
|
100
|
-
}[];
|
|
101
|
-
};
|
|
111
|
+
data: TransactionData;
|
|
102
112
|
fee: number;
|
|
103
113
|
nonce: number;
|
|
104
114
|
owner: string;
|
|
@@ -110,6 +120,21 @@ export interface GetAccountsParams {
|
|
|
110
120
|
minimum_topoheight?: number;
|
|
111
121
|
maximum_topoheight?: number;
|
|
112
122
|
}
|
|
123
|
+
export interface GetBlockAtTopoHeightParams {
|
|
124
|
+
topoheight: number;
|
|
125
|
+
include_txs?: boolean;
|
|
126
|
+
}
|
|
127
|
+
export interface GetBlocksAtHeightParams {
|
|
128
|
+
height: number;
|
|
129
|
+
include_txs?: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface GetBlockByHashParams {
|
|
132
|
+
hash: string;
|
|
133
|
+
include_txs?: boolean;
|
|
134
|
+
}
|
|
135
|
+
export interface GetTopBlockParams {
|
|
136
|
+
include_txs?: boolean;
|
|
137
|
+
}
|
|
113
138
|
export declare enum RPCMethod {
|
|
114
139
|
GetVersion = "get_version",
|
|
115
140
|
GetInfo = "get_info",
|
|
@@ -135,7 +160,9 @@ export declare enum RPCMethod {
|
|
|
135
160
|
GetTransactions = "get_transactions",
|
|
136
161
|
GetBlocksRangeByTopoheight = "get_blocks_range_by_topoheight",
|
|
137
162
|
GetBlocksRangeByHeight = "get_blocks_range_by_height",
|
|
138
|
-
GetAccounts = "get_accounts"
|
|
163
|
+
GetAccounts = "get_accounts",
|
|
164
|
+
SubmitBlock = "submit_block",
|
|
165
|
+
SubmitTransaction = "submit_transaction"
|
|
139
166
|
}
|
|
140
167
|
export declare enum RPCEvent {
|
|
141
168
|
NewBlock = "NewBlock",
|
package/daemon/types.js
CHANGED
|
@@ -25,6 +25,8 @@ export var RPCMethod;
|
|
|
25
25
|
RPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
|
|
26
26
|
RPCMethod["GetBlocksRangeByHeight"] = "get_blocks_range_by_height";
|
|
27
27
|
RPCMethod["GetAccounts"] = "get_accounts";
|
|
28
|
+
RPCMethod["SubmitBlock"] = "submit_block";
|
|
29
|
+
RPCMethod["SubmitTransaction"] = "submit_transaction";
|
|
28
30
|
})(RPCMethod || (RPCMethod = {}));
|
|
29
31
|
export var RPCEvent;
|
|
30
32
|
(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, 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;
|
|
@@ -28,10 +28,10 @@ declare class WS {
|
|
|
28
28
|
getTopoHeight(): Promise<number>;
|
|
29
29
|
getStableHeight(): Promise<number>;
|
|
30
30
|
getBlockTemplate(address: string): Promise<string>;
|
|
31
|
-
getBlockAtTopoHeight(
|
|
32
|
-
getBlocksAtHeight(
|
|
33
|
-
getBlockByHash(
|
|
34
|
-
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>;
|
|
35
35
|
getNonce(address: string): Promise<number>;
|
|
36
36
|
getLastBalance(params: GetLastBalanceParams): Promise<GetLastBalanceResult>;
|
|
37
37
|
getBalanceAtTopoHeight(params: GetBalanceAtTopoHeightParams): Promise<Balance>;
|
|
@@ -46,5 +46,7 @@ declare class WS {
|
|
|
46
46
|
getBlocksRangeByTopoheight(params: TopoHeightRangeParams): Promise<Block[]>;
|
|
47
47
|
getBlocksRangeByHeight(params: HeightRangeParams): Promise<Block[]>;
|
|
48
48
|
getAccounts(params: GetAccountsParams): Promise<string[]>;
|
|
49
|
+
submitBlock(blockTemplate: string): Promise<boolean>;
|
|
50
|
+
submitTransaction(hexData: string): Promise<boolean>;
|
|
49
51
|
}
|
|
50
52
|
export default WS;
|
package/daemon/websocket.js
CHANGED
|
@@ -196,17 +196,17 @@ class WS {
|
|
|
196
196
|
getBlockTemplate(address) {
|
|
197
197
|
return this.dataCall(RPCMethod.GetBlockTemplate, { address });
|
|
198
198
|
}
|
|
199
|
-
getBlockAtTopoHeight(
|
|
200
|
-
return this.dataCall(RPCMethod.GetBlockAtTopoHeight,
|
|
199
|
+
getBlockAtTopoHeight(params) {
|
|
200
|
+
return this.dataCall(RPCMethod.GetBlockAtTopoHeight, params);
|
|
201
201
|
}
|
|
202
|
-
getBlocksAtHeight(
|
|
203
|
-
return this.dataCall(RPCMethod.GetBlocksAtHeight,
|
|
202
|
+
getBlocksAtHeight(params) {
|
|
203
|
+
return this.dataCall(RPCMethod.GetBlocksAtHeight, params);
|
|
204
204
|
}
|
|
205
|
-
getBlockByHash(
|
|
206
|
-
return this.dataCall(RPCMethod.GetBlockByHash,
|
|
205
|
+
getBlockByHash(params) {
|
|
206
|
+
return this.dataCall(RPCMethod.GetBlockByHash, params);
|
|
207
207
|
}
|
|
208
|
-
getTopBlock() {
|
|
209
|
-
return this.dataCall(RPCMethod.GetTopBlock);
|
|
208
|
+
getTopBlock(params) {
|
|
209
|
+
return this.dataCall(RPCMethod.GetTopBlock, params);
|
|
210
210
|
}
|
|
211
211
|
getNonce(address) {
|
|
212
212
|
return this.dataCall(RPCMethod.GetNonce, { address });
|
|
@@ -250,5 +250,11 @@ class WS {
|
|
|
250
250
|
getAccounts(params) {
|
|
251
251
|
return this.dataCall(RPCMethod.GetAccounts, params);
|
|
252
252
|
}
|
|
253
|
+
submitBlock(blockTemplate) {
|
|
254
|
+
return this.dataCall(RPCMethod.SubmitBlock, { block_template: blockTemplate });
|
|
255
|
+
}
|
|
256
|
+
submitTransaction(hexData) {
|
|
257
|
+
return this.dataCall(RPCMethod.SubmitTransaction, { data: hexData });
|
|
258
|
+
}
|
|
253
259
|
}
|
|
254
260
|
export default WS;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.
|
|
2
|
+
"version": "0.3.4",
|
|
3
3
|
"name": "@xelis/sdk",
|
|
4
4
|
"description": "Xelis software development kit for JS",
|
|
5
5
|
"repository": {
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"build": "npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
|
|
13
|
-
"prepublishOnly": "npm run build",
|
|
14
13
|
"publish": "cd ./dist && npm publish"
|
|
15
14
|
},
|
|
16
15
|
"devDependencies": {
|
package/dist
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
```
|