@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 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
- 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>>;
9
9
  getTopoHeight(): Promise<RPCResponse<number>>;
10
10
  getStableHeight(): Promise<RPCResponse<number>>;
11
11
  getBlockTemplate(address: string): Promise<RPCResponse<string>>;
12
- getBlockAtTopoHeight(topoHeight: number): Promise<RPCResponse<Block>>;
13
- getBlocksAtHeight(height: number): Promise<RPCResponse<Block[]>>;
14
- getBlockByHash(hash: string): Promise<RPCResponse<Block>>;
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 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
- getBlockAtTopoHeight(topoHeight) {
44
- return this.fetch(RPCMethod.GetBlockAtTopoHeight, { topoheight: topoHeight });
43
+ getBlockAtTopoHeight(params) {
44
+ return this.post(RPCMethod.GetBlockAtTopoHeight, params);
45
45
  }
46
- getBlocksAtHeight(height) {
47
- return this.fetch(RPCMethod.GetBlocksAtHeight, { height });
46
+ getBlocksAtHeight(params) {
47
+ return this.post(RPCMethod.GetBlocksAtHeight, params);
48
48
  }
49
- getBlockByHash(hash) {
50
- return this.fetch(RPCMethod.GetBlockByHash, { hash });
49
+ getBlockByHash(params) {
50
+ return this.post(RPCMethod.GetBlockByHash, params);
51
51
  }
52
- getTopBlock() {
53
- return this.fetch(RPCMethod.GetTopBlock);
52
+ 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;
@@ -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) {
@@ -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(topoHeight: number): Promise<Block>;
32
- getBlocksAtHeight(height: number): Promise<Block[]>;
33
- getBlockByHash(hash: string): Promise<Block>;
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;
@@ -196,17 +196,17 @@ class WS {
196
196
  getBlockTemplate(address) {
197
197
  return this.dataCall(RPCMethod.GetBlockTemplate, { address });
198
198
  }
199
- getBlockAtTopoHeight(topoHeight) {
200
- return this.dataCall(RPCMethod.GetBlockAtTopoHeight, { topoheight: topoHeight });
199
+ getBlockAtTopoHeight(params) {
200
+ return this.dataCall(RPCMethod.GetBlockAtTopoHeight, params);
201
201
  }
202
- getBlocksAtHeight(height) {
203
- return this.dataCall(RPCMethod.GetBlocksAtHeight, { height });
202
+ getBlocksAtHeight(params) {
203
+ return this.dataCall(RPCMethod.GetBlocksAtHeight, params);
204
204
  }
205
- getBlockByHash(hash) {
206
- return this.dataCall(RPCMethod.GetBlockByHash, { hash });
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",
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
- ```