@xelis/sdk 0.7.0 → 0.8.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 (58) hide show
  1. package/create_esm_pkg.js +13 -0
  2. package/dist/cjs/config.js +38 -0
  3. package/dist/cjs/daemon/rpc.js +143 -0
  4. package/dist/cjs/daemon/types.js +74 -0
  5. package/dist/cjs/daemon/websocket.js +236 -0
  6. package/dist/cjs/lib/rpc.js +89 -0
  7. package/dist/cjs/lib/types.js +2 -0
  8. package/dist/cjs/lib/websocket.js +283 -0
  9. package/dist/cjs/react/daemon.js +176 -0
  10. package/dist/cjs/wallet/rpc.js +131 -0
  11. package/dist/cjs/wallet/types.js +29 -0
  12. package/dist/cjs/wallet/websocket.js +92 -0
  13. package/dist/cjs/xswd/types.js +9 -0
  14. package/dist/cjs/xswd/websocket.js +38 -0
  15. package/dist/esm/config.js +35 -0
  16. package/dist/esm/daemon/rpc.js +140 -0
  17. package/dist/esm/daemon/websocket.js +233 -0
  18. package/dist/esm/lib/rpc.js +86 -0
  19. package/dist/esm/lib/websocket.js +277 -0
  20. package/dist/esm/package.json +1 -0
  21. package/dist/esm/react/daemon.js +144 -0
  22. package/dist/esm/wallet/rpc.js +128 -0
  23. package/dist/esm/wallet/websocket.js +89 -0
  24. package/dist/esm/xswd/websocket.js +35 -0
  25. package/dist/types/daemon/rpc.d.ts +43 -0
  26. package/{daemon → dist/types/daemon}/websocket.d.ts +2 -2
  27. package/{lib → dist/types/lib}/rpc.d.ts +1 -1
  28. package/{lib → dist/types/lib}/websocket.d.ts +1 -1
  29. package/{react → dist/types/react}/daemon.d.ts +2 -2
  30. package/{wallet → dist/types/wallet}/rpc.d.ts +4 -4
  31. package/{wallet → dist/types/wallet}/types.d.ts +1 -1
  32. package/{wallet → dist/types/wallet}/websocket.d.ts +3 -3
  33. package/dist/types/xswd/websocket.d.ts +11 -0
  34. package/jest.config.js +6 -0
  35. package/package.json +12 -3
  36. package/tsconfig.cjs.json +7 -0
  37. package/tsconfig.esm.json +7 -0
  38. package/tsconfig.json +17 -0
  39. package/tsconfig.types.json +8 -0
  40. package/config.js +0 -25
  41. package/daemon/rpc.d.ts +0 -43
  42. package/daemon/rpc.js +0 -119
  43. package/daemon/websocket.js +0 -171
  44. package/lib/rpc.js +0 -38
  45. package/lib/websocket.js +0 -202
  46. package/react/daemon.js +0 -82
  47. package/wallet/rpc.js +0 -67
  48. package/wallet/websocket.js +0 -66
  49. package/xswd/websocket.d.ts +0 -11
  50. package/xswd/websocket.js +0 -16
  51. /package/{daemon → dist/esm/daemon}/types.js +0 -0
  52. /package/{lib → dist/esm/lib}/types.js +0 -0
  53. /package/{wallet → dist/esm/wallet}/types.js +0 -0
  54. /package/{xswd → dist/esm/xswd}/types.js +0 -0
  55. /package/{config.d.ts → dist/types/config.d.ts} +0 -0
  56. /package/{daemon → dist/types/daemon}/types.d.ts +0 -0
  57. /package/{lib → dist/types/lib}/types.d.ts +0 -0
  58. /package/{xswd → dist/types/xswd}/types.d.ts +0 -0
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ exports.__esModule = true;
18
+ exports.WS = exports.WalletMethods = void 0;
19
+ var websocket_js_1 = require("../lib/websocket.js");
20
+ var types_js_1 = require("./types.js");
21
+ var WalletMethods = /** @class */ (function () {
22
+ function WalletMethods(ws, prefix) {
23
+ if (prefix === void 0) { prefix = ""; }
24
+ this.ws = ws;
25
+ this.prefix = prefix;
26
+ }
27
+ WalletMethods.prototype.dataCall = function (method, params) {
28
+ return this.ws.dataCall(this.prefix + method, params);
29
+ };
30
+ WalletMethods.prototype.getVersion = function () {
31
+ return this.dataCall(types_js_1.RPCMethod.GetVersion);
32
+ };
33
+ WalletMethods.prototype.getNetwork = function () {
34
+ return this.dataCall(types_js_1.RPCMethod.GetNetwork);
35
+ };
36
+ WalletMethods.prototype.getNonce = function () {
37
+ return this.dataCall(types_js_1.RPCMethod.GetNonce);
38
+ };
39
+ WalletMethods.prototype.getTopoheight = function () {
40
+ return this.dataCall(types_js_1.RPCMethod.GetTopoheight);
41
+ };
42
+ WalletMethods.prototype.getAddress = function (params) {
43
+ if (params === void 0) { params = {}; }
44
+ return this.dataCall(types_js_1.RPCMethod.GetAddress, params);
45
+ };
46
+ WalletMethods.prototype.splitAddress = function (params) {
47
+ return this.dataCall(types_js_1.RPCMethod.SplitAddress, params);
48
+ };
49
+ WalletMethods.prototype.rescan = function () {
50
+ return this.dataCall(types_js_1.RPCMethod.Rescan);
51
+ };
52
+ WalletMethods.prototype.getBalance = function (asset) {
53
+ return this.dataCall(types_js_1.RPCMethod.GetBalance, { asset: asset });
54
+ };
55
+ WalletMethods.prototype.getTrackedAssets = function () {
56
+ return this.dataCall(types_js_1.RPCMethod.GetTrackedAssets);
57
+ };
58
+ WalletMethods.prototype.getAssetPrecision = function (params) {
59
+ return this.dataCall(types_js_1.RPCMethod.GetAssetPrecision, params);
60
+ };
61
+ WalletMethods.prototype.getTransaction = function (hash) {
62
+ return this.dataCall(types_js_1.RPCMethod.GetTransaction, { hash: hash });
63
+ };
64
+ WalletMethods.prototype.buildTransaction = function (params) {
65
+ return this.dataCall(types_js_1.RPCMethod.BuildTransaction, params);
66
+ };
67
+ WalletMethods.prototype.listTransactions = function (params) {
68
+ return this.dataCall(types_js_1.RPCMethod.GetTransaction, params);
69
+ };
70
+ WalletMethods.prototype.isOnline = function () {
71
+ return this.dataCall(types_js_1.RPCMethod.IsOnline);
72
+ };
73
+ WalletMethods.prototype.signData = function (data) {
74
+ return this.dataCall(types_js_1.RPCMethod.SignData, data);
75
+ };
76
+ WalletMethods.prototype.estimateFees = function (txData) {
77
+ return this.dataCall(types_js_1.RPCMethod.EstimateFees, { tx_type: txData });
78
+ };
79
+ return WalletMethods;
80
+ }());
81
+ exports.WalletMethods = WalletMethods;
82
+ var WS = /** @class */ (function (_super) {
83
+ __extends(WS, _super);
84
+ function WS(username, password) {
85
+ var _this = _super.call(this, { auth: "".concat(username, ":").concat(password) }) || this;
86
+ _this.methods = new WalletMethods(_this);
87
+ return _this;
88
+ }
89
+ return WS;
90
+ }(websocket_js_1.WS));
91
+ exports.WS = WS;
92
+ exports["default"] = WS;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.Permission = void 0;
4
+ var Permission;
5
+ (function (Permission) {
6
+ Permission[Permission["Ask"] = 0] = "Ask";
7
+ Permission[Permission["AcceptAlways"] = 1] = "AcceptAlways";
8
+ Permission[Permission["DenyAlways"] = 2] = "DenyAlways";
9
+ })(Permission = exports.Permission || (exports.Permission = {}));
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ exports.__esModule = true;
18
+ exports.WS = void 0;
19
+ var websocket_js_1 = require("../lib/websocket.js");
20
+ var websocket_js_2 = require("../daemon/websocket.js");
21
+ var websocket_js_3 = require("../wallet/websocket.js");
22
+ var WS = /** @class */ (function (_super) {
23
+ __extends(WS, _super);
24
+ function WS() {
25
+ var _this = _super.call(this) || this;
26
+ _this.timeout = 0;
27
+ _this.daemon = new websocket_js_2.DaemonMethods(_this, "node.");
28
+ _this.wallet = new websocket_js_3.WalletMethods(_this, "wallet.");
29
+ return _this;
30
+ }
31
+ WS.prototype.authorize = function (app) {
32
+ var data = JSON.stringify(app);
33
+ return this.call("", {}, data);
34
+ };
35
+ return WS;
36
+ }(websocket_js_1.WS));
37
+ exports.WS = WS;
38
+ exports["default"] = WS;
@@ -0,0 +1,35 @@
1
+ export var DAEMON_RPC_PORT = "8080";
2
+ export var WALLET_RPC_PORT = "8081";
3
+ export var XSWD_PORT = "44325";
4
+ export var MAINNET_NODE_URL = "node.xelis.io";
5
+ export var TESTNET_NODE_URL = "testnet-node.xelis.io";
6
+ export var LOCAL_NODE_URL = "127.0.0.1:".concat(DAEMON_RPC_PORT);
7
+ export var MAINNET_NODE_RPC = "https://".concat(MAINNET_NODE_URL, "/json_rpc");
8
+ export var TESTNET_NODE_RPC = "https://".concat(TESTNET_NODE_URL, "/json_rpc");
9
+ export var LOCAL_NODE_RPC = "http://".concat(LOCAL_NODE_URL, "/json_rpc");
10
+ export var MAINNET_NODE_WS = "wss://".concat(MAINNET_NODE_URL, "/json_rpc");
11
+ export var TESTNET_NODE_WS = "wss://".concat(TESTNET_NODE_URL, "/json_rpc");
12
+ export var LOCAL_NODE_WS = "ws://".concat(LOCAL_NODE_URL, "/json_rpc");
13
+ export var LOCAL_WALLET_URL = "127.0.0.1:".concat(WALLET_RPC_PORT);
14
+ export var LOCAL_WALLET_RPC = "http://".concat(LOCAL_WALLET_URL, "/json_rpc");
15
+ export var LOCAL_WALLET_WS = "ws://".concat(LOCAL_WALLET_URL, "/json_rpc");
16
+ export var LOCAL_XSWD_URL = "127.0.0.1:".concat(XSWD_PORT);
17
+ export var LOCAL_XSWD_WS = "ws://".concat(LOCAL_XSWD_URL, "/xswd");
18
+ export default {
19
+ MAINNET_NODE_URL: MAINNET_NODE_URL,
20
+ TESTNET_NODE_URL: TESTNET_NODE_URL,
21
+ MAINNET_NODE_RPC: MAINNET_NODE_RPC,
22
+ TESTNET_NODE_RPC: TESTNET_NODE_RPC,
23
+ LOCAL_NODE_RPC: LOCAL_NODE_RPC,
24
+ MAINNET_NODE_WS: MAINNET_NODE_WS,
25
+ TESTNET_NODE_WS: TESTNET_NODE_WS,
26
+ LOCAL_NODE_WS: LOCAL_NODE_WS,
27
+ DAEMON_RPC_PORT: DAEMON_RPC_PORT,
28
+ WALLET_RPC_PORT: WALLET_RPC_PORT,
29
+ XSWD_PORT: XSWD_PORT,
30
+ LOCAL_WALLET_URL: LOCAL_WALLET_URL,
31
+ LOCAL_WALLET_RPC: LOCAL_WALLET_RPC,
32
+ LOCAL_WALLET_WS: LOCAL_WALLET_WS,
33
+ LOCAL_XSWD_URL: LOCAL_XSWD_URL,
34
+ LOCAL_XSWD_WS: LOCAL_XSWD_WS
35
+ };
@@ -0,0 +1,140 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { RPCMethod } from './types.js';
17
+ import { RPC as BaseRPC } from '../lib/rpc.js';
18
+ var RPC = /** @class */ (function (_super) {
19
+ __extends(RPC, _super);
20
+ function RPC() {
21
+ return _super !== null && _super.apply(this, arguments) || this;
22
+ }
23
+ RPC.prototype.getVersion = function () {
24
+ return this.post(RPCMethod.GetVersion);
25
+ };
26
+ RPC.prototype.getHeight = function () {
27
+ return this.post(RPCMethod.GetHeight);
28
+ };
29
+ RPC.prototype.getTopoHeight = function () {
30
+ return this.post(RPCMethod.GetTopoHeight);
31
+ };
32
+ RPC.prototype.getStableHeight = function () {
33
+ return this.post(RPCMethod.GetStableHeight);
34
+ };
35
+ RPC.prototype.getBlockTemplate = function (address) {
36
+ return this.post(RPCMethod.GetBlockTemplate, { address: address });
37
+ };
38
+ RPC.prototype.getBlockAtTopoHeight = function (params) {
39
+ return this.post(RPCMethod.GetBlockAtTopoHeight, params);
40
+ };
41
+ RPC.prototype.getBlocksAtHeight = function (params) {
42
+ return this.post(RPCMethod.GetBlocksAtHeight, params);
43
+ };
44
+ RPC.prototype.getBlockByHash = function (params) {
45
+ return this.post(RPCMethod.GetBlockByHash, params);
46
+ };
47
+ RPC.prototype.getTopBlock = function (params) {
48
+ return this.post(RPCMethod.GetTopBlock, params);
49
+ };
50
+ RPC.prototype.submitBlock = function (blockTemplate) {
51
+ return this.post(RPCMethod.SubmitBlock, { block_template: blockTemplate });
52
+ };
53
+ RPC.prototype.getBalance = function (params) {
54
+ return this.post(RPCMethod.GetBalance, params);
55
+ };
56
+ RPC.prototype.hasBalance = function (params) {
57
+ return this.post(RPCMethod.HasBalance, params);
58
+ };
59
+ RPC.prototype.getBalanceAtTopoHeight = function (params) {
60
+ return this.post(RPCMethod.GetBalanceAtTopoHeight, params);
61
+ };
62
+ RPC.prototype.getInfo = function () {
63
+ return this.post(RPCMethod.GetInfo);
64
+ };
65
+ RPC.prototype.getNonce = function (params) {
66
+ return this.post(RPCMethod.GetNonce, params);
67
+ };
68
+ RPC.prototype.hasNonce = function (params) {
69
+ return this.post(RPCMethod.HasNonce, params);
70
+ };
71
+ RPC.prototype.getNonceAtTopoheight = function (params) {
72
+ return this.post(RPCMethod.GetNonceAtTopoheight, params);
73
+ };
74
+ RPC.prototype.getAsset = function (params) {
75
+ return this.post(RPCMethod.GetAsset, params);
76
+ };
77
+ RPC.prototype.getAssets = function () {
78
+ return this.post(RPCMethod.GetAssets);
79
+ };
80
+ RPC.prototype.countAssets = function () {
81
+ return this.post(RPCMethod.CountAssets);
82
+ };
83
+ RPC.prototype.countAccounts = function () {
84
+ return this.post(RPCMethod.CountAccounts);
85
+ };
86
+ RPC.prototype.countTransactions = function () {
87
+ return this.post(RPCMethod.CountTransactions);
88
+ };
89
+ RPC.prototype.submitTransaction = function (hexData) {
90
+ return this.post(RPCMethod.SubmitTransaction, { data: hexData });
91
+ };
92
+ RPC.prototype.getTransaction = function (hash) {
93
+ return this.post(RPCMethod.GetTransaction, { hash: hash });
94
+ };
95
+ RPC.prototype.p2pStatus = function () {
96
+ return this.post(RPCMethod.P2PStatus);
97
+ };
98
+ RPC.prototype.getPeers = function () {
99
+ return this.post(RPCMethod.GetPeers);
100
+ };
101
+ RPC.prototype.getMemPool = function () {
102
+ return this.post(RPCMethod.GetMempool);
103
+ };
104
+ RPC.prototype.getTips = function () {
105
+ return this.post(RPCMethod.GetTips);
106
+ };
107
+ RPC.prototype.getDAGOrder = function (params) {
108
+ return this.post(RPCMethod.GetDAGOrder, params);
109
+ };
110
+ RPC.prototype.getBlocksRangeByTopoheight = function (params) {
111
+ return this.post(RPCMethod.GetBlocksRangeByTopoheight, params);
112
+ };
113
+ RPC.prototype.getBlocksRangeByHeight = function (params) {
114
+ return this.post(RPCMethod.GetBlocksRangeByHeight, params);
115
+ };
116
+ RPC.prototype.getTransactions = function (txHashes) {
117
+ return this.post(RPCMethod.GetTransactions, { tx_hashes: txHashes });
118
+ };
119
+ RPC.prototype.getAccountHistory = function (params) {
120
+ return this.post(RPCMethod.GetAccountHistory, params);
121
+ };
122
+ RPC.prototype.getAccountAssets = function (address) {
123
+ return this.post(RPCMethod.GetAccountAssets, { address: address });
124
+ };
125
+ RPC.prototype.getAccounts = function (params) {
126
+ return this.post(RPCMethod.GetAccounts, params);
127
+ };
128
+ RPC.prototype.isTxExecutedInBlock = function (params) {
129
+ return this.post(RPCMethod.IsTxExecutedInBlock, params);
130
+ };
131
+ RPC.prototype.getDevFeeThresholds = function () {
132
+ return this.post(RPCMethod.GetDevFeeThresholds);
133
+ };
134
+ RPC.prototype.getSizeOnDisk = function () {
135
+ return this.post(RPCMethod.GetSizeOnDisk);
136
+ };
137
+ return RPC;
138
+ }(BaseRPC));
139
+ export { RPC };
140
+ export default RPC;
@@ -0,0 +1,233 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ 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;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import { RPCEvent, RPCMethod } from './types.js';
53
+ import { WS as BaseWS } from '../lib/websocket.js';
54
+ var DaemonMethods = /** @class */ (function () {
55
+ function DaemonMethods(ws, prefix) {
56
+ if (prefix === void 0) { prefix = ""; }
57
+ this.ws = ws;
58
+ this.prefix = prefix;
59
+ }
60
+ DaemonMethods.prototype.listenEvent = function (event, onData) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ return __generator(this, function (_a) {
63
+ return [2 /*return*/, this.ws.listenEvent(this.prefix + event, onData)];
64
+ });
65
+ });
66
+ };
67
+ DaemonMethods.prototype.dataCall = function (method, params) {
68
+ return this.ws.dataCall(this.prefix + method, params);
69
+ };
70
+ DaemonMethods.prototype.onNewBlock = function (onData) {
71
+ return this.listenEvent(RPCEvent.NewBlock, onData);
72
+ };
73
+ DaemonMethods.prototype.onTransactionAddedInMempool = function (onData) {
74
+ return this.listenEvent(RPCEvent.TransactionAddedInMempool, onData);
75
+ };
76
+ DaemonMethods.prototype.onTransactionExecuted = function (onData) {
77
+ return this.listenEvent(RPCEvent.TransactionExecuted, onData);
78
+ };
79
+ DaemonMethods.prototype.onBlockOrdered = function (onData) {
80
+ return this.listenEvent(RPCEvent.BlockOrdered, onData);
81
+ };
82
+ DaemonMethods.prototype.onPeerConnected = function (onData) {
83
+ return this.listenEvent(RPCEvent.PeerConnected, onData);
84
+ };
85
+ DaemonMethods.prototype.onPeerDisconnected = function (onData) {
86
+ return this.listenEvent(RPCEvent.PeerDisconnected, onData);
87
+ };
88
+ DaemonMethods.prototype.onPeerPeerListUpdated = function (onData) {
89
+ return this.listenEvent(RPCEvent.PeerPeerListUpdated, onData);
90
+ };
91
+ DaemonMethods.prototype.onPeerPeerDisconnected = function (onData) {
92
+ return this.listenEvent(RPCEvent.PeerPeerDisconnected, onData);
93
+ };
94
+ DaemonMethods.prototype.onPeerStateUpdated = function (onData) {
95
+ return this.listenEvent(RPCEvent.PeerStateUpdated, onData);
96
+ };
97
+ DaemonMethods.prototype.onNewAsset = function (onData) {
98
+ return this.listenEvent(RPCEvent.NewAsset, onData);
99
+ };
100
+ DaemonMethods.prototype.onBlockOrphaned = function (onData) {
101
+ return this.listenEvent(RPCEvent.BlockOrphaned, onData);
102
+ };
103
+ DaemonMethods.prototype.onTransactionOrphaned = function (onData) {
104
+ return this.listenEvent(RPCEvent.TransactionOrphaned, onData);
105
+ };
106
+ DaemonMethods.prototype.onStableHeightChanged = function (onData) {
107
+ return this.listenEvent(RPCEvent.StableHeightChanged, onData);
108
+ };
109
+ DaemonMethods.prototype.getVersion = function () {
110
+ return this.dataCall(RPCMethod.GetVersion);
111
+ };
112
+ DaemonMethods.prototype.getHeight = function () {
113
+ return this.dataCall(RPCMethod.GetHeight);
114
+ };
115
+ DaemonMethods.prototype.getTopoHeight = function () {
116
+ return this.dataCall(RPCMethod.GetTopoHeight);
117
+ };
118
+ DaemonMethods.prototype.getStableHeight = function () {
119
+ return this.dataCall(RPCMethod.GetStableHeight);
120
+ };
121
+ DaemonMethods.prototype.getBlockTemplate = function (address) {
122
+ return this.dataCall(RPCMethod.GetBlockTemplate, { address: address });
123
+ };
124
+ DaemonMethods.prototype.getBlockAtTopoHeight = function (params) {
125
+ return this.dataCall(RPCMethod.GetBlockAtTopoHeight, params);
126
+ };
127
+ DaemonMethods.prototype.getBlocksAtHeight = function (params) {
128
+ return this.dataCall(RPCMethod.GetBlocksAtHeight, params);
129
+ };
130
+ DaemonMethods.prototype.getBlockByHash = function (params) {
131
+ return this.dataCall(RPCMethod.GetBlockByHash, params);
132
+ };
133
+ DaemonMethods.prototype.getTopBlock = function (params) {
134
+ return this.dataCall(RPCMethod.GetTopBlock, params);
135
+ };
136
+ DaemonMethods.prototype.submitBlock = function (blockTemplate) {
137
+ return this.dataCall(RPCMethod.SubmitBlock, { block_template: blockTemplate });
138
+ };
139
+ DaemonMethods.prototype.getBalance = function (params) {
140
+ return this.dataCall(RPCMethod.GetBalance, params);
141
+ };
142
+ DaemonMethods.prototype.hasBalance = function (params) {
143
+ return this.dataCall(RPCMethod.HasBalance, params);
144
+ };
145
+ DaemonMethods.prototype.getBalanceAtTopoHeight = function (params) {
146
+ return this.dataCall(RPCMethod.GetBalanceAtTopoHeight, params);
147
+ };
148
+ DaemonMethods.prototype.getInfo = function () {
149
+ return this.dataCall(RPCMethod.GetInfo);
150
+ };
151
+ DaemonMethods.prototype.getNonce = function (params) {
152
+ return this.dataCall(RPCMethod.GetNonce, params);
153
+ };
154
+ DaemonMethods.prototype.hasNonce = function (params) {
155
+ return this.dataCall(RPCMethod.HasNonce, params);
156
+ };
157
+ DaemonMethods.prototype.getAsset = function (params) {
158
+ return this.dataCall(RPCMethod.GetAsset, params);
159
+ };
160
+ DaemonMethods.prototype.getAssets = function () {
161
+ return this.dataCall(RPCMethod.GetAssets);
162
+ };
163
+ DaemonMethods.prototype.countAssets = function () {
164
+ return this.dataCall(RPCMethod.CountAssets);
165
+ };
166
+ DaemonMethods.prototype.countAccounts = function () {
167
+ return this.dataCall(RPCMethod.CountAccounts);
168
+ };
169
+ DaemonMethods.prototype.countTransactions = function () {
170
+ return this.dataCall(RPCMethod.CountTransactions);
171
+ };
172
+ DaemonMethods.prototype.submitTransaction = function (hexData) {
173
+ return this.dataCall(RPCMethod.SubmitTransaction, { data: hexData });
174
+ };
175
+ DaemonMethods.prototype.getTransaction = function (hash) {
176
+ return this.dataCall(RPCMethod.GetTransaction, { hash: hash });
177
+ };
178
+ DaemonMethods.prototype.p2pStatus = function () {
179
+ return this.dataCall(RPCMethod.P2PStatus);
180
+ };
181
+ DaemonMethods.prototype.getPeers = function () {
182
+ return this.dataCall(RPCMethod.GetPeers);
183
+ };
184
+ DaemonMethods.prototype.getMemPool = function () {
185
+ return this.dataCall(RPCMethod.GetMempool);
186
+ };
187
+ DaemonMethods.prototype.getTips = function () {
188
+ return this.dataCall(RPCMethod.GetTips);
189
+ };
190
+ DaemonMethods.prototype.getDAGOrder = function (params) {
191
+ return this.dataCall(RPCMethod.GetDAGOrder, params);
192
+ };
193
+ DaemonMethods.prototype.getBlocksRangeByTopoheight = function (params) {
194
+ return this.dataCall(RPCMethod.GetBlocksRangeByTopoheight, params);
195
+ };
196
+ DaemonMethods.prototype.getBlocksRangeByHeight = function (params) {
197
+ return this.dataCall(RPCMethod.GetBlocksRangeByHeight, params);
198
+ };
199
+ DaemonMethods.prototype.getTransactions = function (txHashes) {
200
+ return this.dataCall(RPCMethod.GetTransactions, { tx_hashes: txHashes });
201
+ };
202
+ DaemonMethods.prototype.getAccountHistory = function (params) {
203
+ return this.dataCall(RPCMethod.GetAccountHistory, params);
204
+ };
205
+ DaemonMethods.prototype.getAccountAssets = function (address) {
206
+ return this.dataCall(RPCMethod.GetAccountAssets, { address: address });
207
+ };
208
+ DaemonMethods.prototype.getAccounts = function (params) {
209
+ return this.dataCall(RPCMethod.GetAccounts, params);
210
+ };
211
+ DaemonMethods.prototype.isTxExecutedInBlock = function (params) {
212
+ return this.dataCall(RPCMethod.IsTxExecutedInBlock, params);
213
+ };
214
+ DaemonMethods.prototype.getDevFeeThresholds = function () {
215
+ return this.dataCall(RPCMethod.GetDevFeeThresholds);
216
+ };
217
+ DaemonMethods.prototype.getSizeOnDisk = function () {
218
+ return this.dataCall(RPCMethod.GetSizeOnDisk);
219
+ };
220
+ return DaemonMethods;
221
+ }());
222
+ export { DaemonMethods };
223
+ var WS = /** @class */ (function (_super) {
224
+ __extends(WS, _super);
225
+ function WS() {
226
+ var _this = _super.call(this) || this;
227
+ _this.methods = new DaemonMethods(_this);
228
+ return _this;
229
+ }
230
+ return WS;
231
+ }(BaseWS));
232
+ export { WS };
233
+ export default WS;
@@ -0,0 +1,86 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var RPC = /** @class */ (function () {
38
+ function RPC(endpoint) {
39
+ this.endpoint = endpoint;
40
+ this.timeout = 3000;
41
+ }
42
+ RPC.prototype.post = function (method, params, headers) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var controller_1, body, timeoutId, res, data, err_1;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0:
48
+ _a.trys.push([0, 5, , 6]);
49
+ controller_1 = new AbortController();
50
+ body = JSON.stringify({ id: 1, jsonrpc: '2.0', method: method, params: params });
51
+ timeoutId = setTimeout(function () {
52
+ controller_1.abort();
53
+ }, this.timeout);
54
+ headers = headers || new Headers();
55
+ headers.set("Content-Type", "application/json");
56
+ return [4 /*yield*/, fetch(this.endpoint, {
57
+ headers: headers,
58
+ method: "POST",
59
+ body: body,
60
+ signal: controller_1.signal
61
+ })];
62
+ case 1:
63
+ res = _a.sent();
64
+ clearTimeout(timeoutId);
65
+ if (!res.ok) return [3 /*break*/, 3];
66
+ return [4 /*yield*/, res.json()];
67
+ case 2:
68
+ data = _a.sent();
69
+ if (data.error) {
70
+ return [2 /*return*/, Promise.reject(new Error(data.error.message))];
71
+ }
72
+ return [2 /*return*/, Promise.resolve(data)];
73
+ case 3: return [2 /*return*/, Promise.reject(new Error("".concat(res.status, " - ").concat(res.statusText)))];
74
+ case 4: return [3 /*break*/, 6];
75
+ case 5:
76
+ err_1 = _a.sent();
77
+ console.log(err_1);
78
+ return [2 /*return*/, Promise.reject(err_1)];
79
+ case 6: return [2 /*return*/];
80
+ }
81
+ });
82
+ });
83
+ };
84
+ return RPC;
85
+ }());
86
+ export { RPC };