@xelis/sdk 0.3.3 → 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 +3 -1
- package/daemon/rpc.js +32 -26
- package/daemon/types.d.ts +21 -9
- package/daemon/types.js +2 -0
- package/daemon/websocket.d.ts +2 -0
- package/daemon/websocket.js +6 -0
- package/package.json +1 -2
- package/dist +0 -44
package/daemon/rpc.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams
|
|
|
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>>;
|
|
@@ -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
43
|
getBlockAtTopoHeight(params) {
|
|
44
|
-
return this.
|
|
44
|
+
return this.post(RPCMethod.GetBlockAtTopoHeight, params);
|
|
45
45
|
}
|
|
46
46
|
getBlocksAtHeight(params) {
|
|
47
|
-
return this.
|
|
47
|
+
return this.post(RPCMethod.GetBlocksAtHeight, params);
|
|
48
48
|
}
|
|
49
49
|
getBlockByHash(params) {
|
|
50
|
-
return this.
|
|
50
|
+
return this.post(RPCMethod.GetBlockByHash, params);
|
|
51
51
|
}
|
|
52
52
|
getTopBlock(params) {
|
|
53
|
-
return this.
|
|
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;
|
|
@@ -150,7 +160,9 @@ export declare enum RPCMethod {
|
|
|
150
160
|
GetTransactions = "get_transactions",
|
|
151
161
|
GetBlocksRangeByTopoheight = "get_blocks_range_by_topoheight",
|
|
152
162
|
GetBlocksRangeByHeight = "get_blocks_range_by_height",
|
|
153
|
-
GetAccounts = "get_accounts"
|
|
163
|
+
GetAccounts = "get_accounts",
|
|
164
|
+
SubmitBlock = "submit_block",
|
|
165
|
+
SubmitTransaction = "submit_transaction"
|
|
154
166
|
}
|
|
155
167
|
export declare enum RPCEvent {
|
|
156
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
|
@@ -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
|
@@ -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
|
-
```
|