@xelis/sdk 0.9.11 → 0.10.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.
Files changed (53) hide show
  1. package/dist/cjs/address/address.js +55 -0
  2. package/dist/cjs/address/bech32.js +167 -0
  3. package/dist/cjs/config.js +4 -2
  4. package/dist/cjs/daemon/rpc.js +122 -71
  5. package/dist/cjs/daemon/types.js +44 -24
  6. package/dist/cjs/daemon/websocket.js +129 -105
  7. package/dist/cjs/data/element.js +84 -0
  8. package/dist/cjs/data/value.js +327 -0
  9. package/dist/cjs/{lib/rpc.js → rpc/http.js} +68 -18
  10. package/dist/cjs/rpc/parse_json/parse_json.js +15 -0
  11. package/dist/cjs/{lib → rpc}/websocket.js +119 -79
  12. package/dist/cjs/wallet/rpc.js +81 -70
  13. package/dist/cjs/wallet/types.js +44 -1
  14. package/dist/cjs/wallet/websocket.js +77 -14
  15. package/dist/cjs/xswd/websocket.js +3 -3
  16. package/dist/esm/address/address.js +53 -0
  17. package/dist/esm/address/bech32.js +161 -0
  18. package/dist/esm/config.js +3 -1
  19. package/dist/esm/daemon/rpc.js +122 -71
  20. package/dist/esm/daemon/types.js +44 -24
  21. package/dist/esm/daemon/websocket.js +130 -106
  22. package/dist/esm/data/element.js +81 -0
  23. package/dist/esm/data/value.js +324 -0
  24. package/dist/esm/{lib/rpc.js → rpc/http.js} +67 -17
  25. package/dist/esm/rpc/parse_json/parse_json.js +8 -0
  26. package/dist/esm/{lib → rpc}/websocket.js +118 -78
  27. package/dist/esm/wallet/rpc.js +81 -70
  28. package/dist/esm/wallet/types.js +43 -0
  29. package/dist/esm/wallet/websocket.js +77 -14
  30. package/dist/esm/xswd/websocket.js +3 -3
  31. package/dist/types/address/address.d.ts +12 -0
  32. package/dist/types/address/bech32.d.ts +6 -0
  33. package/dist/types/config.d.ts +2 -0
  34. package/dist/types/daemon/rpc.d.ts +68 -51
  35. package/dist/types/daemon/types.d.ts +216 -44
  36. package/dist/types/daemon/websocket.d.ts +77 -56
  37. package/dist/types/data/element.d.ts +20 -0
  38. package/dist/types/data/value.d.ts +50 -0
  39. package/dist/types/rpc/http.d.ts +9 -0
  40. package/dist/types/rpc/parse_json/parse_json.d.ts +1 -0
  41. package/dist/types/{lib → rpc}/websocket.d.ts +14 -10
  42. package/dist/types/wallet/rpc.d.ts +45 -26
  43. package/dist/types/wallet/types.d.ts +244 -21
  44. package/dist/types/wallet/websocket.d.ts +47 -22
  45. package/dist/types/xswd/websocket.d.ts +3 -3
  46. package/package.json +5 -4
  47. package/dist/cjs/lib/parse_data.js +0 -15
  48. package/dist/esm/lib/parse_data.js +0 -11
  49. package/dist/types/lib/parse_data.d.ts +0 -1
  50. package/dist/types/lib/rpc.d.ts +0 -7
  51. /package/dist/cjs/{lib → rpc}/types.js +0 -0
  52. /package/dist/esm/{lib → rpc}/types.js +0 -0
  53. /package/dist/types/{lib → rpc}/types.d.ts +0 -0
@@ -39,29 +39,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  exports.__esModule = true;
42
- exports.WS = void 0;
42
+ exports.WSRPC = void 0;
43
43
  var isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
44
44
  var await_to_js_1 = require("await-to-js");
45
- var parse_data_1 = require("./parse_data");
46
- var WS = /** @class */ (function () {
47
- function WS(options) {
45
+ var parse_json_1 = require("./parse_json/parse_json");
46
+ var WSRPC = /** @class */ (function () {
47
+ function WSRPC(options) {
48
48
  this.connectionTries = 0;
49
49
  this.methodIdIncrement = 0;
50
50
  this.endpoint = "";
51
51
  this.timeout = 15000; // default to 15s
52
- this.events = {};
52
+ this.events = new Map();
53
53
  this.unsubscribeSuspense = 1000;
54
54
  this.maxConnectionTries = 3;
55
55
  this.reconnectOnConnectionLoss = true;
56
56
  this.options = options;
57
57
  }
58
- WS.prototype.connect = function (endpoint) {
58
+ WSRPC.prototype.connect = function (endpoint) {
59
59
  var _this = this;
60
60
  // force disconnect if already connected
61
61
  if (this.socket && this.socket.readyState === isomorphic_ws_1["default"].OPEN) {
62
62
  this.socket.close();
63
63
  }
64
- this.events = {};
64
+ this.events = new Map();
65
65
  this.connectionTries = 0;
66
66
  return new Promise(function (resolve, reject) {
67
67
  _this.socket = new isomorphic_ws_1["default"](endpoint, _this.options);
@@ -83,7 +83,7 @@ var WS = /** @class */ (function () {
83
83
  });
84
84
  });
85
85
  };
86
- WS.prototype.tryReconnect = function () {
86
+ WSRPC.prototype.tryReconnect = function () {
87
87
  var _this = this;
88
88
  this.connectionTries++;
89
89
  if (this.connectionTries > this.maxConnectionTries) {
@@ -97,26 +97,29 @@ var WS = /** @class */ (function () {
97
97
  _this.tryReconnect();
98
98
  });
99
99
  };
100
- WS.prototype.close = function () {
100
+ WSRPC.prototype.close = function () {
101
101
  if (!this.socket)
102
102
  return;
103
103
  this.socket.close();
104
104
  };
105
- WS.prototype.clearEvent = function (event) {
105
+ WSRPC.prototype.clearEvent = function (event) {
106
106
  var _this = this;
107
- this.events[event].listeners.forEach(function (listener) {
108
- _this.socket && _this.socket.removeEventListener("message", listener);
109
- });
110
- Reflect.deleteProperty(this.events, event);
107
+ var eventData = this.events.get(event);
108
+ if (eventData) {
109
+ eventData.listeners.forEach(function (listener) {
110
+ _this.socket && _this.socket.removeEventListener("message", listener);
111
+ });
112
+ this.events["delete"](event);
113
+ }
111
114
  };
112
- WS.prototype.closeAllListens = function (event) {
115
+ WSRPC.prototype.closeAllListens = function (event) {
113
116
  return __awaiter(this, void 0, void 0, function () {
114
117
  var _a, err, _;
115
118
  return __generator(this, function (_b) {
116
119
  switch (_b.label) {
117
120
  case 0:
118
- if (!this.events[event]) return [3 /*break*/, 2];
119
- return [4 /*yield*/, (0, await_to_js_1.to)(this.call("unsubscribe", { notify: event }))];
121
+ if (!this.events.has(event)) return [3 /*break*/, 2];
122
+ return [4 /*yield*/, (0, await_to_js_1.to)(this.dataCall("unsubscribe", { notify: event }))];
120
123
  case 1:
121
124
  _a = _b.sent(), err = _a[0], _ = _a[1];
122
125
  if (err)
@@ -128,59 +131,56 @@ var WS = /** @class */ (function () {
128
131
  });
129
132
  });
130
133
  };
131
- WS.prototype.listenEvent = function (event, onData) {
134
+ WSRPC.prototype.listenEvent = function (event, onData) {
132
135
  return __awaiter(this, void 0, void 0, function () {
133
- var onMessage, unsubscribeTimeoutId, _a, err, res, closeListen;
136
+ var onMessage, eventData, idRefObject, _a, err, _, closeListen;
134
137
  var _this = this;
135
138
  return __generator(this, function (_b) {
136
139
  switch (_b.label) {
137
140
  case 0:
138
141
  onMessage = function (msgEvent) {
139
- if (_this.events[event]) {
140
- var id = _this.events[event].id;
141
- if (typeof msgEvent.data === "string") {
142
- try {
143
- var data = (0, parse_data_1.parseData)(msgEvent.data);
144
- if (data.id === id) {
145
- if (data.error) {
146
- onData(msgEvent, undefined, new Error(data.error.message));
147
- }
148
- else {
149
- onData(msgEvent, data.result, undefined);
150
- }
142
+ var eventData = _this.events.get(event);
143
+ if (eventData && typeof msgEvent.data === "string") {
144
+ try {
145
+ var data = (0, parse_json_1.parseJSON)(msgEvent.data);
146
+ if (data.id === eventData.id) {
147
+ if (data.error) {
148
+ onData(msgEvent, undefined, new Error(data.error.message));
149
+ }
150
+ else {
151
+ onData(msgEvent, data.result, undefined);
151
152
  }
152
153
  }
153
- catch (_a) {
154
- // can't parse json -- do nothing
155
- }
154
+ }
155
+ catch (_a) {
156
+ // can't parse json -- do nothing
156
157
  }
157
158
  }
158
159
  };
159
- if (!this.events[event]) return [3 /*break*/, 1];
160
- unsubscribeTimeoutId = this.events[event].unsubscribeTimeoutId;
161
- if (unsubscribeTimeoutId) {
160
+ eventData = this.events.get(event);
161
+ if (!eventData) return [3 /*break*/, 1];
162
+ if (eventData.unsubscribeTimeoutId) {
162
163
  // clear timeout to unsubscribe
163
164
  // because we got a new registered event and want to cancel the pending unsubscribe grace period
164
- clearTimeout(unsubscribeTimeoutId);
165
+ clearTimeout(eventData.unsubscribeTimeoutId);
165
166
  }
166
- this.events[event].listeners.push(onMessage);
167
+ eventData.listeners.push(onMessage);
167
168
  return [3 /*break*/, 3];
168
169
  case 1:
169
- // important if multiple listenEvent are called without await at least we store listener before getting id
170
- this.events[event] = { listeners: [onMessage] };
171
- return [4 /*yield*/, (0, await_to_js_1.to)(this.call("subscribe", { notify: event }))];
170
+ idRefObject = {};
171
+ return [4 /*yield*/, (0, await_to_js_1.to)(this.dataCall("subscribe", { notify: event }, idRefObject))];
172
172
  case 2:
173
- _a = _b.sent(), err = _a[0], res = _a[1];
173
+ _a = _b.sent(), err = _a[0], _ = _a[1];
174
174
  if (err) {
175
175
  this.clearEvent(event);
176
176
  return [2 /*return*/, Promise.reject(err)];
177
177
  }
178
- this.events[event].id = res.id;
178
+ this.events.set(event, { listeners: [onMessage], id: idRefObject.id });
179
179
  _b.label = 3;
180
180
  case 3:
181
181
  this.socket && this.socket.addEventListener("message", onMessage);
182
182
  closeListen = function () {
183
- var eventData = _this.events[event];
183
+ var eventData = _this.events.get(event);
184
184
  if (eventData) {
185
185
  var listeners = eventData.listeners;
186
186
  for (var i = 0; i < listeners.length; i++) {
@@ -193,17 +193,17 @@ var WS = /** @class */ (function () {
193
193
  if (listeners.length === 0) {
194
194
  if (_this.socket && _this.socket.readyState === isomorphic_ws_1["default"].OPEN) {
195
195
  // we use a grace period to unsubscribe (mostly because of react useEffect and avoid unecessary subscribe)
196
- _this.events[event].unsubscribeTimeoutId = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
196
+ eventData.unsubscribeTimeoutId = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
197
197
  return __generator(this, function (_a) {
198
- this.call("unsubscribe", { notify: event });
199
- Reflect.deleteProperty(this.events, event);
198
+ this.dataCall("unsubscribe", { notify: event });
199
+ this.events["delete"](event);
200
200
  return [2 /*return*/];
201
201
  });
202
202
  }); }, _this.unsubscribeSuspense);
203
203
  }
204
204
  else {
205
205
  // socket is closed so we don't send unsubscribe and no grace period delete right away
206
- Reflect.deleteProperty(_this.events, event);
206
+ _this.events["delete"](event);
207
207
  }
208
208
  }
209
209
  }
@@ -215,70 +215,110 @@ var WS = /** @class */ (function () {
215
215
  });
216
216
  });
217
217
  };
218
- WS.prototype.call = function (method, params, overwriteData) {
218
+ WSRPC.prototype.batchCall = function (requests) {
219
+ var _this = this;
220
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
221
+ var id, data, _a, err, res, items;
222
+ return __generator(this, function (_b) {
223
+ switch (_b.label) {
224
+ case 0:
225
+ id = this.methodIdIncrement++;
226
+ requests.forEach(function (request) {
227
+ request.id = id;
228
+ request.jsonrpc = "2.0";
229
+ });
230
+ data = JSON.stringify(requests);
231
+ return [4 /*yield*/, (0, await_to_js_1.to)(this.rawCall(id, data))];
232
+ case 1:
233
+ _a = _b.sent(), err = _a[0], res = _a[1];
234
+ if (err)
235
+ return [2 /*return*/, reject(err)];
236
+ items = [];
237
+ res.forEach(function (v) {
238
+ if (v.error) {
239
+ items.push(new Error(v.error.message));
240
+ }
241
+ else {
242
+ items.push(v.result);
243
+ }
244
+ });
245
+ return [2 /*return*/, resolve(items)];
246
+ }
247
+ });
248
+ }); });
249
+ };
250
+ WSRPC.prototype.rawCall = function (id, body) {
219
251
  var _this = this;
220
252
  return new Promise(function (resolve, reject) {
221
253
  if (!_this.socket)
222
254
  return reject(new Error("Socket is not initialized."));
223
255
  if (_this.socket.readyState !== isomorphic_ws_1["default"].OPEN)
224
256
  return reject(new Error("Can't send msg. Socket is not opened."));
225
- var requestMethod = _this.createRequestMethod(method, params);
226
- // for XSWD we want to send the application data without request method wrapping
227
- if (overwriteData) {
228
- requestMethod.id = null;
229
- requestMethod.data = overwriteData;
230
- }
231
257
  var timeoutId = null;
232
258
  var onMessage = function (msgEvent) {
233
259
  if (typeof msgEvent.data === "string") {
234
- var data = (0, parse_data_1.parseData)(msgEvent.data);
235
- if (data.id === requestMethod.id) {
260
+ var data = (0, parse_json_1.parseJSON)(msgEvent.data);
261
+ console.log(data);
262
+ var valid = false;
263
+ if (Array.isArray(data) && data.length > 0 && data[0].id === id) {
264
+ //@ts-ignore
265
+ resolve(data);
266
+ valid = true;
267
+ }
268
+ else if (data.id === id) {
269
+ resolve(data);
270
+ valid = true;
271
+ }
272
+ else if (data.id === null && id === 0) {
273
+ // special case with xswd sending first call will return null id
274
+ resolve(data);
275
+ valid = true;
276
+ }
277
+ if (valid) {
236
278
  clearTimeout(timeoutId);
237
279
  _this.socket && _this.socket.removeEventListener("message", onMessage);
238
- if (data.error)
239
- return reject(new Error(data.error.message));
240
- else
241
- resolve(data);
242
280
  }
243
281
  }
244
282
  };
245
- // make sure you listen before sending data
246
- _this.socket && _this.socket.addEventListener("message", onMessage); // we don't use { once: true } option because of timeout feature
283
+ _this.socket.addEventListener("message", onMessage);
247
284
  if (_this.timeout > 0) {
248
285
  timeoutId = setTimeout(function () {
249
286
  _this.socket && _this.socket.removeEventListener("message", onMessage);
250
287
  reject(new Error("timeout"));
251
288
  }, _this.timeout);
252
289
  }
253
- if (_this.socket && _this.socket.readyState === isomorphic_ws_1["default"].OPEN) {
254
- _this.socket.send(requestMethod.data);
290
+ if (_this.socket.readyState === isomorphic_ws_1["default"].OPEN) {
291
+ _this.socket.send(body);
255
292
  }
256
293
  });
257
294
  };
258
- WS.prototype.dataCall = function (method, params) {
295
+ WSRPC.prototype.dataCall = function (method, params, idRefObj) {
259
296
  var _this = this;
260
297
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
261
- var _a, err, res;
298
+ var id, request, data, _a, err, res;
262
299
  return __generator(this, function (_b) {
263
300
  switch (_b.label) {
264
- case 0: return [4 /*yield*/, (0, await_to_js_1.to)(this.call(method, params))];
301
+ case 0:
302
+ id = this.methodIdIncrement++;
303
+ if (idRefObj)
304
+ idRefObj.id = id;
305
+ request = { id: id, jsonrpc: "2.0", method: method };
306
+ if (params)
307
+ request.params = params;
308
+ data = JSON.stringify(request);
309
+ return [4 /*yield*/, (0, await_to_js_1.to)(this.rawCall(id, data))];
265
310
  case 1:
266
311
  _a = _b.sent(), err = _a[0], res = _a[1];
267
312
  if (err)
268
313
  return [2 /*return*/, reject(err)];
314
+ if (res.error) {
315
+ return [2 /*return*/, reject(res.error.message)];
316
+ }
269
317
  return [2 /*return*/, resolve(res.result)];
270
318
  }
271
319
  });
272
320
  }); });
273
321
  };
274
- WS.prototype.createRequestMethod = function (method, params) {
275
- var id = this.methodIdIncrement++;
276
- var request = { id: id, jsonrpc: "2.0", method: method };
277
- if (params)
278
- request.params = params;
279
- var data = JSON.stringify(request);
280
- return { data: data, id: id };
281
- };
282
- return WS;
322
+ return WSRPC;
283
323
  }());
284
- exports.WS = WS;
324
+ exports.WSRPC = WSRPC;
@@ -14,124 +14,135 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
17
  exports.__esModule = true;
54
18
  exports.RPC = void 0;
55
19
  var js_base64_1 = require("js-base64");
56
20
  var types_1 = require("./types");
57
- var rpc_1 = require("../lib/rpc");
21
+ var http_1 = require("../rpc/http");
58
22
  var RPC = /** @class */ (function (_super) {
59
23
  __extends(RPC, _super);
60
24
  function RPC(endpoint, username, password) {
61
25
  var _this = _super.call(this, endpoint) || this;
62
26
  var authValue = js_base64_1.Base64.encode("".concat(username, ":").concat(password));
63
- _this.auth = "Basic ".concat(authValue);
27
+ _this.headers.set("Authorization", "Basic ".concat(authValue));
64
28
  return _this;
65
29
  }
66
- RPC.prototype.post = function (method, params) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- var headers;
69
- return __generator(this, function (_a) {
70
- headers = new Headers();
71
- headers.set("Authorization", this.auth);
72
- return [2 /*return*/, _super.prototype.post.call(this, method, params, headers)];
73
- });
74
- });
75
- };
76
30
  RPC.prototype.getVersion = function () {
77
- return this.post(types_1.RPCMethod.GetVersion);
31
+ return this.request(types_1.RPCMethod.GetVersion);
78
32
  };
79
33
  RPC.prototype.getNetwork = function () {
80
- return this.post(types_1.RPCMethod.GetNetwork);
34
+ return this.request(types_1.RPCMethod.GetNetwork);
81
35
  };
82
36
  RPC.prototype.getNonce = function () {
83
- return this.post(types_1.RPCMethod.GetNonce);
37
+ return this.request(types_1.RPCMethod.GetNonce);
84
38
  };
85
39
  RPC.prototype.getTopoheight = function () {
86
- return this.post(types_1.RPCMethod.GetTopoheight);
40
+ return this.request(types_1.RPCMethod.GetTopoheight);
87
41
  };
88
42
  RPC.prototype.getAddress = function (params) {
89
43
  if (params === void 0) { params = {}; }
90
- return this.post(types_1.RPCMethod.GetAddress, params);
44
+ return this.request(types_1.RPCMethod.GetAddress, params);
91
45
  };
92
46
  RPC.prototype.splitAddress = function (params) {
93
- return this.post(types_1.RPCMethod.SplitAddress, params);
47
+ return this.request(types_1.RPCMethod.SplitAddress, params);
94
48
  };
95
49
  RPC.prototype.rescan = function (params) {
96
- return this.post(types_1.RPCMethod.Rescan, params);
50
+ return this.request(types_1.RPCMethod.Rescan, params);
97
51
  };
98
52
  RPC.prototype.getBalance = function (asset) {
99
- return this.post(types_1.RPCMethod.GetBalance, { asset: asset });
53
+ return this.request(types_1.RPCMethod.GetBalance, { asset: asset });
100
54
  };
101
55
  RPC.prototype.hasBalance = function (asset) {
102
- return this.post(types_1.RPCMethod.HasBalance, { asset: asset });
56
+ return this.request(types_1.RPCMethod.HasBalance, { asset: asset });
103
57
  };
104
58
  RPC.prototype.getTrackedAssets = function () {
105
- return this.post(types_1.RPCMethod.GetTrackedAssets);
59
+ return this.request(types_1.RPCMethod.GetTrackedAssets);
106
60
  };
107
61
  RPC.prototype.getAssetPrecision = function (params) {
108
- return this.post(types_1.RPCMethod.GetAssetPrecision, params);
62
+ return this.request(types_1.RPCMethod.GetAssetPrecision, params);
63
+ };
64
+ RPC.prototype.getAssets = function () {
65
+ return this.request(types_1.RPCMethod.GetAssets);
66
+ };
67
+ RPC.prototype.getAsset = function (params) {
68
+ return this.request(types_1.RPCMethod.GetAsset, params);
109
69
  };
110
70
  RPC.prototype.getTransaction = function (hash) {
111
- return this.post(types_1.RPCMethod.GetTransaction, { hash: hash });
71
+ return this.request(types_1.RPCMethod.GetTransaction, { hash: hash });
112
72
  };
113
73
  RPC.prototype.buildTransaction = function (params) {
114
- return this.post(types_1.RPCMethod.BuildTransaction, params);
74
+ return this.request(types_1.RPCMethod.BuildTransaction, params);
75
+ };
76
+ RPC.prototype.buildTransactionOffline = function (params) {
77
+ return this.request(types_1.RPCMethod.BuildTransactionOffline, params);
78
+ };
79
+ RPC.prototype.buildUnsignedTransaction = function (params) {
80
+ return this.request(types_1.RPCMethod.BuildUnsignedTransaction, params);
81
+ };
82
+ RPC.prototype.signUnsignedTransaction = function (params) {
83
+ return this.request(types_1.RPCMethod.SignUnsignedTransaction, params);
84
+ };
85
+ RPC.prototype.finalizeUnsignedTransaction = function (params) {
86
+ return this.request(types_1.RPCMethod.FinalizeUnsignedTransaction, params);
87
+ };
88
+ RPC.prototype.clearTxCache = function () {
89
+ return this.request(types_1.RPCMethod.ClearTxCache);
115
90
  };
116
91
  RPC.prototype.listTransactions = function (params) {
117
- return this.post(types_1.RPCMethod.ListTransactions, params);
92
+ return this.request(types_1.RPCMethod.ListTransactions, params);
118
93
  };
119
94
  RPC.prototype.isOnline = function () {
120
- return this.post(types_1.RPCMethod.IsOnline);
95
+ return this.request(types_1.RPCMethod.IsOnline);
96
+ };
97
+ RPC.prototype.setOnlineMode = function (params) {
98
+ return this.request(types_1.RPCMethod.SetOnlineMode, params);
99
+ };
100
+ RPC.prototype.setOfflineMode = function () {
101
+ return this.request(types_1.RPCMethod.SetOfflineMode);
121
102
  };
122
103
  RPC.prototype.signData = function (data) {
123
- return this.post(types_1.RPCMethod.SignData, data);
104
+ return this.request(types_1.RPCMethod.SignData, data.toObject());
124
105
  };
125
106
  RPC.prototype.estimateFees = function (params) {
126
- return this.post(types_1.RPCMethod.EstimateFees, params);
107
+ return this.request(types_1.RPCMethod.EstimateFees, params);
127
108
  };
128
- RPC.prototype.setOnlineMode = function (params) {
129
- return this.post(types_1.RPCMethod.SetOnlineMode, params);
109
+ RPC.prototype.estimateExtraDataSize = function (params) {
110
+ return this.request(types_1.RPCMethod.EstimateExtraDataSize, params);
130
111
  };
131
- RPC.prototype.setOfflineMode = function () {
132
- return this.post(types_1.RPCMethod.SetOfflineMode);
112
+ RPC.prototype.networkInfo = function () {
113
+ return this.request(types_1.RPCMethod.NetworkInfo);
114
+ };
115
+ RPC.prototype.decryptExtraData = function (params) {
116
+ return this.request(types_1.RPCMethod.DecryptExtraData, params);
117
+ };
118
+ RPC.prototype.decryptCiphertext = function (params) {
119
+ return this.request(types_1.RPCMethod.DecryptCiphertext, params);
120
+ };
121
+ RPC.prototype.getMatchingKeys = function (params) {
122
+ return this.request(types_1.RPCMethod.GetMatchingKeys, params);
123
+ };
124
+ RPC.prototype.countMatchingEntries = function (params) {
125
+ return this.request(types_1.RPCMethod.CountMatchingEntries, params);
126
+ };
127
+ RPC.prototype.getValueFromKey = function (params) {
128
+ return this.request(types_1.RPCMethod.GetValueFromKey, params);
129
+ };
130
+ RPC.prototype.store = function (params) {
131
+ return this.request(types_1.RPCMethod.Store, params);
132
+ };
133
+ RPC.prototype["delete"] = function (params) {
134
+ return this.request(types_1.RPCMethod.Delete, params);
135
+ };
136
+ RPC.prototype.deleteTreeEntries = function (tree) {
137
+ return this.request(types_1.RPCMethod.DeleteTreeEntries, { tree: tree });
138
+ };
139
+ RPC.prototype.hasKey = function (params) {
140
+ return this.request(types_1.RPCMethod.HasKey, params);
141
+ };
142
+ RPC.prototype.queryDB = function (params) {
143
+ return this.request(types_1.RPCMethod.QueryDB, params);
133
144
  };
134
145
  return RPC;
135
- }(rpc_1.RPC));
146
+ }(http_1.HttpRPC));
136
147
  exports.RPC = RPC;
137
148
  exports["default"] = RPC;
@@ -1,6 +1,29 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.Permission = exports.RPCEvent = exports.RPCMethod = void 0;
3
+ exports.Permission = exports.RPCEvent = exports.RPCMethod = exports.ElementType = exports.ValueType = exports.TxRole = void 0;
4
+ var TxRole;
5
+ (function (TxRole) {
6
+ TxRole["Sender"] = "sender";
7
+ TxRole["Receiver"] = "receiver";
8
+ })(TxRole = exports.TxRole || (exports.TxRole = {}));
9
+ var ValueType;
10
+ (function (ValueType) {
11
+ ValueType[ValueType["Bool"] = 0] = "Bool";
12
+ ValueType[ValueType["String"] = 1] = "String";
13
+ ValueType[ValueType["U8"] = 2] = "U8";
14
+ ValueType[ValueType["U16"] = 3] = "U16";
15
+ ValueType[ValueType["U32"] = 4] = "U32";
16
+ ValueType[ValueType["U64"] = 5] = "U64";
17
+ ValueType[ValueType["U128"] = 6] = "U128";
18
+ ValueType[ValueType["Hash"] = 7] = "Hash";
19
+ ValueType[ValueType["Blob"] = 8] = "Blob";
20
+ })(ValueType = exports.ValueType || (exports.ValueType = {}));
21
+ var ElementType;
22
+ (function (ElementType) {
23
+ ElementType[ElementType["Value"] = 0] = "Value";
24
+ ElementType[ElementType["Array"] = 1] = "Array";
25
+ ElementType[ElementType["Fields"] = 2] = "Fields";
26
+ })(ElementType = exports.ElementType || (exports.ElementType = {}));
4
27
  var RPCMethod;
5
28
  (function (RPCMethod) {
6
29
  RPCMethod["GetVersion"] = "get_version";
@@ -14,14 +37,33 @@ var RPCMethod;
14
37
  RPCMethod["HasBalance"] = "has_balance";
15
38
  RPCMethod["GetTrackedAssets"] = "get_tracked_assets";
16
39
  RPCMethod["GetAssetPrecision"] = "get_asset_precision";
40
+ RPCMethod["GetAssets"] = "get_assets";
41
+ RPCMethod["GetAsset"] = "get_asset";
17
42
  RPCMethod["GetTransaction"] = "get_transaction";
18
43
  RPCMethod["BuildTransaction"] = "build_transaction";
44
+ RPCMethod["BuildTransactionOffline"] = "build_transaction_offline";
45
+ RPCMethod["BuildUnsignedTransaction"] = "build_unsigned_transaction";
46
+ RPCMethod["SignUnsignedTransaction"] = "sign_unsigned_transaction";
47
+ RPCMethod["FinalizeUnsignedTransaction"] = "finalize_unsigned_transaction";
48
+ RPCMethod["ClearTxCache"] = "clear_tx_cache";
19
49
  RPCMethod["ListTransactions"] = "list_transactions";
20
50
  RPCMethod["IsOnline"] = "is_online";
21
51
  RPCMethod["SetOnlineMode"] = "set_online_mode";
22
52
  RPCMethod["SetOfflineMode"] = "set_offline_mode";
23
53
  RPCMethod["SignData"] = "sign_data";
24
54
  RPCMethod["EstimateFees"] = "estimate_fees";
55
+ RPCMethod["EstimateExtraDataSize"] = "estimate_extra_data_size";
56
+ RPCMethod["NetworkInfo"] = "network_info";
57
+ RPCMethod["DecryptExtraData"] = "decrypt_extra_data";
58
+ RPCMethod["DecryptCiphertext"] = "decrypt_ciphertext";
59
+ RPCMethod["GetMatchingKeys"] = "get_matching_keys";
60
+ RPCMethod["CountMatchingEntries"] = "count_matching_entries";
61
+ RPCMethod["GetValueFromKey"] = "get_value_from_key";
62
+ RPCMethod["Store"] = "store";
63
+ RPCMethod["Delete"] = "delete";
64
+ RPCMethod["DeleteTreeEntries"] = "delete_tree_entries";
65
+ RPCMethod["HasKey"] = "has_key";
66
+ RPCMethod["QueryDB"] = "query_db";
25
67
  })(RPCMethod = exports.RPCMethod || (exports.RPCMethod = {}));
26
68
  var RPCEvent;
27
69
  (function (RPCEvent) {
@@ -30,6 +72,7 @@ var RPCEvent;
30
72
  RPCEvent["NewTransaction"] = "new_transaction";
31
73
  RPCEvent["BalanceChanged"] = "balance_changed";
32
74
  RPCEvent["Rescan"] = "rescan";
75
+ RPCEvent["HistorySynced"] = "history_synced";
33
76
  RPCEvent["Online"] = "online";
34
77
  RPCEvent["Offline"] = "offline";
35
78
  })(RPCEvent = exports.RPCEvent || (exports.RPCEvent = {}));