@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 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
- fetch<T>(method: RPCMethod, params?: any): Promise<RPCResponse<T>>;
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 fetch(method, params) {
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.fetch(RPCMethod.GetVersion);
26
+ return this.post(RPCMethod.GetVersion);
27
27
  }
28
28
  getInfo() {
29
- return this.fetch(RPCMethod.GetInfo);
29
+ return this.post(RPCMethod.GetInfo);
30
30
  }
31
31
  getHeight() {
32
- return this.fetch(RPCMethod.GetHeight);
32
+ return this.post(RPCMethod.GetHeight);
33
33
  }
34
34
  getTopoHeight() {
35
- return this.fetch(RPCMethod.GetTopoHeight);
35
+ return this.post(RPCMethod.GetTopoHeight);
36
36
  }
37
37
  getStableHeight() {
38
- return this.fetch(RPCMethod.GetStableHeight);
38
+ return this.post(RPCMethod.GetStableHeight);
39
39
  }
40
40
  getBlockTemplate(address) {
41
- return this.fetch(RPCMethod.GetBlockTemplate, { address });
41
+ return this.post(RPCMethod.GetBlockTemplate, { address });
42
42
  }
43
43
  getBlockAtTopoHeight(params) {
44
- return this.fetch(RPCMethod.GetBlockAtTopoHeight, params);
44
+ return this.post(RPCMethod.GetBlockAtTopoHeight, params);
45
45
  }
46
46
  getBlocksAtHeight(params) {
47
- return this.fetch(RPCMethod.GetBlocksAtHeight, params);
47
+ return this.post(RPCMethod.GetBlocksAtHeight, params);
48
48
  }
49
49
  getBlockByHash(params) {
50
- return this.fetch(RPCMethod.GetBlockByHash, params);
50
+ return this.post(RPCMethod.GetBlockByHash, params);
51
51
  }
52
52
  getTopBlock(params) {
53
- return this.fetch(RPCMethod.GetTopBlock, params);
53
+ return this.post(RPCMethod.GetTopBlock, params);
54
54
  }
55
55
  getNonce(address) {
56
- return this.fetch(RPCMethod.GetNonce, { address });
56
+ return this.post(RPCMethod.GetNonce, { address });
57
57
  }
58
58
  getLastBalance(params) {
59
- return this.fetch(RPCMethod.GetLastBalance, params);
59
+ return this.post(RPCMethod.GetLastBalance, params);
60
60
  }
61
61
  getBalanceAtTopoHeight(params) {
62
- return this.fetch(RPCMethod.GetBalanceAtTopoHeight, params);
62
+ return this.post(RPCMethod.GetBalanceAtTopoHeight, params);
63
63
  }
64
64
  getAssets() {
65
- return this.fetch(RPCMethod.GetAssets);
65
+ return this.post(RPCMethod.GetAssets);
66
66
  }
67
67
  countTransactions() {
68
- return this.fetch(RPCMethod.CountTransactions);
68
+ return this.post(RPCMethod.CountTransactions);
69
69
  }
70
70
  countAssets() {
71
- return this.fetch(RPCMethod.CountAssets);
71
+ return this.post(RPCMethod.CountAssets);
72
72
  }
73
73
  getTips() {
74
- return this.fetch(RPCMethod.GetTips);
74
+ return this.post(RPCMethod.GetTips);
75
75
  }
76
76
  p2pStatus() {
77
- return this.fetch(RPCMethod.P2PStatus);
77
+ return this.post(RPCMethod.P2PStatus);
78
78
  }
79
79
  getDAGOrder(params) {
80
- return this.fetch(RPCMethod.GetDAGOrder, params);
80
+ return this.post(RPCMethod.GetDAGOrder, params);
81
81
  }
82
82
  getMemPool() {
83
- return this.fetch(RPCMethod.GetMempool);
83
+ return this.post(RPCMethod.GetMempool);
84
84
  }
85
85
  getTransaction(hash) {
86
- return this.fetch(RPCMethod.GetTransaction, { hash });
86
+ return this.post(RPCMethod.GetTransaction, { hash });
87
87
  }
88
88
  getTransactions(txHashes) {
89
- return this.fetch(RPCMethod.GetTransactions, { tx_hashes: txHashes });
89
+ return this.post(RPCMethod.GetTransactions, { tx_hashes: txHashes });
90
90
  }
91
91
  getBlocksRangeByTopoheight(params) {
92
- return this.fetch(RPCMethod.GetBlocksRangeByTopoheight, params);
92
+ return this.post(RPCMethod.GetBlocksRangeByTopoheight, params);
93
93
  }
94
94
  getBlocksRangeByHeight(params) {
95
- return this.fetch(RPCMethod.GetBlocksRangeByHeight, params);
95
+ return this.post(RPCMethod.GetBlocksRangeByHeight, params);
96
96
  }
97
97
  getAccounts(params) {
98
- return this.fetch(RPCMethod.GetAccounts, params);
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) {
@@ -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;
@@ -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.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
- ```