@xelis/sdk 0.6.1 → 0.8.0
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/create_esm_pkg.js +13 -0
- package/dist/cjs/config.js +38 -0
- package/dist/cjs/daemon/rpc.js +143 -0
- package/dist/cjs/daemon/types.js +74 -0
- package/dist/cjs/daemon/websocket.js +236 -0
- package/dist/cjs/lib/rpc.js +89 -0
- package/dist/cjs/lib/types.js +2 -0
- package/dist/cjs/lib/websocket.js +283 -0
- package/dist/cjs/react/daemon.js +176 -0
- package/dist/cjs/wallet/rpc.js +131 -0
- package/dist/cjs/wallet/types.js +29 -0
- package/dist/cjs/wallet/websocket.js +92 -0
- package/dist/cjs/xswd/types.js +9 -0
- package/dist/cjs/xswd/websocket.js +38 -0
- package/dist/esm/config.js +35 -0
- package/dist/esm/daemon/rpc.js +140 -0
- package/{daemon → dist/esm/daemon}/types.js +13 -3
- package/dist/esm/daemon/websocket.js +233 -0
- package/dist/esm/lib/rpc.js +86 -0
- package/dist/esm/lib/websocket.js +277 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/react/daemon.js +144 -0
- package/dist/esm/wallet/rpc.js +128 -0
- package/{wallet → dist/esm/wallet}/types.js +1 -0
- package/dist/esm/wallet/websocket.js +89 -0
- package/dist/esm/xswd/websocket.js +35 -0
- package/{daemon → dist/types/daemon}/rpc.d.ts +17 -15
- package/{daemon → dist/types/daemon}/types.d.ts +127 -47
- package/{daemon → dist/types/daemon}/websocket.d.ts +20 -16
- package/{wallet → dist/types/wallet}/rpc.d.ts +9 -5
- package/{wallet → dist/types/wallet}/types.d.ts +26 -0
- package/{wallet → dist/types/wallet}/websocket.d.ts +7 -5
- package/jest.config.js +6 -0
- package/package.json +12 -3
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +17 -0
- package/tsconfig.types.json +8 -0
- package/config.js +0 -25
- package/daemon/rpc.js +0 -113
- package/daemon/websocket.js +0 -159
- package/lib/rpc.js +0 -38
- package/lib/websocket.js +0 -202
- package/react/daemon.js +0 -82
- package/wallet/rpc.js +0 -55
- package/wallet/websocket.js +0 -60
- package/xswd/websocket.js +0 -16
- /package/{lib → dist/esm/lib}/types.js +0 -0
- /package/{xswd → dist/esm/xswd}/types.js +0 -0
- /package/{config.d.ts → dist/types/config.d.ts} +0 -0
- /package/{lib → dist/types/lib}/rpc.d.ts +0 -0
- /package/{lib → dist/types/lib}/types.d.ts +0 -0
- /package/{lib → dist/types/lib}/websocket.d.ts +0 -0
- /package/{react → dist/types/react}/daemon.d.ts +0 -0
- /package/{xswd → dist/types/xswd}/types.d.ts +0 -0
- /package/{xswd → dist/types/xswd}/websocket.d.ts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
// We need to create a package.json for explicitly setting the ESM folder has modern EcmaScript modules.
|
|
4
|
+
|
|
5
|
+
const main = () => {
|
|
6
|
+
const data = JSON.stringify({
|
|
7
|
+
"type": "module"
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
fs.writeFileSync('./dist/esm/package.json', data)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.LOCAL_XSWD_WS = exports.LOCAL_XSWD_URL = exports.LOCAL_WALLET_WS = exports.LOCAL_WALLET_RPC = exports.LOCAL_WALLET_URL = exports.LOCAL_NODE_WS = exports.TESTNET_NODE_WS = exports.MAINNET_NODE_WS = exports.LOCAL_NODE_RPC = exports.TESTNET_NODE_RPC = exports.MAINNET_NODE_RPC = exports.LOCAL_NODE_URL = exports.TESTNET_NODE_URL = exports.MAINNET_NODE_URL = exports.XSWD_PORT = exports.WALLET_RPC_PORT = exports.DAEMON_RPC_PORT = void 0;
|
|
4
|
+
exports.DAEMON_RPC_PORT = "8080";
|
|
5
|
+
exports.WALLET_RPC_PORT = "8081";
|
|
6
|
+
exports.XSWD_PORT = "44325";
|
|
7
|
+
exports.MAINNET_NODE_URL = "node.xelis.io";
|
|
8
|
+
exports.TESTNET_NODE_URL = "testnet-node.xelis.io";
|
|
9
|
+
exports.LOCAL_NODE_URL = "127.0.0.1:".concat(exports.DAEMON_RPC_PORT);
|
|
10
|
+
exports.MAINNET_NODE_RPC = "https://".concat(exports.MAINNET_NODE_URL, "/json_rpc");
|
|
11
|
+
exports.TESTNET_NODE_RPC = "https://".concat(exports.TESTNET_NODE_URL, "/json_rpc");
|
|
12
|
+
exports.LOCAL_NODE_RPC = "http://".concat(exports.LOCAL_NODE_URL, "/json_rpc");
|
|
13
|
+
exports.MAINNET_NODE_WS = "wss://".concat(exports.MAINNET_NODE_URL, "/json_rpc");
|
|
14
|
+
exports.TESTNET_NODE_WS = "wss://".concat(exports.TESTNET_NODE_URL, "/json_rpc");
|
|
15
|
+
exports.LOCAL_NODE_WS = "ws://".concat(exports.LOCAL_NODE_URL, "/json_rpc");
|
|
16
|
+
exports.LOCAL_WALLET_URL = "127.0.0.1:".concat(exports.WALLET_RPC_PORT);
|
|
17
|
+
exports.LOCAL_WALLET_RPC = "http://".concat(exports.LOCAL_WALLET_URL, "/json_rpc");
|
|
18
|
+
exports.LOCAL_WALLET_WS = "ws://".concat(exports.LOCAL_WALLET_URL, "/json_rpc");
|
|
19
|
+
exports.LOCAL_XSWD_URL = "127.0.0.1:".concat(exports.XSWD_PORT);
|
|
20
|
+
exports.LOCAL_XSWD_WS = "ws://".concat(exports.LOCAL_XSWD_URL, "/xswd");
|
|
21
|
+
exports["default"] = {
|
|
22
|
+
MAINNET_NODE_URL: exports.MAINNET_NODE_URL,
|
|
23
|
+
TESTNET_NODE_URL: exports.TESTNET_NODE_URL,
|
|
24
|
+
MAINNET_NODE_RPC: exports.MAINNET_NODE_RPC,
|
|
25
|
+
TESTNET_NODE_RPC: exports.TESTNET_NODE_RPC,
|
|
26
|
+
LOCAL_NODE_RPC: exports.LOCAL_NODE_RPC,
|
|
27
|
+
MAINNET_NODE_WS: exports.MAINNET_NODE_WS,
|
|
28
|
+
TESTNET_NODE_WS: exports.TESTNET_NODE_WS,
|
|
29
|
+
LOCAL_NODE_WS: exports.LOCAL_NODE_WS,
|
|
30
|
+
DAEMON_RPC_PORT: exports.DAEMON_RPC_PORT,
|
|
31
|
+
WALLET_RPC_PORT: exports.WALLET_RPC_PORT,
|
|
32
|
+
XSWD_PORT: exports.XSWD_PORT,
|
|
33
|
+
LOCAL_WALLET_URL: exports.LOCAL_WALLET_URL,
|
|
34
|
+
LOCAL_WALLET_RPC: exports.LOCAL_WALLET_RPC,
|
|
35
|
+
LOCAL_WALLET_WS: exports.LOCAL_WALLET_WS,
|
|
36
|
+
LOCAL_XSWD_URL: exports.LOCAL_XSWD_URL,
|
|
37
|
+
LOCAL_XSWD_WS: exports.LOCAL_XSWD_WS
|
|
38
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
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.RPC = void 0;
|
|
19
|
+
var types_1 = require("./types");
|
|
20
|
+
var rpc_1 = require("../lib/rpc");
|
|
21
|
+
var RPC = /** @class */ (function (_super) {
|
|
22
|
+
__extends(RPC, _super);
|
|
23
|
+
function RPC() {
|
|
24
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
25
|
+
}
|
|
26
|
+
RPC.prototype.getVersion = function () {
|
|
27
|
+
return this.post(types_1.RPCMethod.GetVersion);
|
|
28
|
+
};
|
|
29
|
+
RPC.prototype.getHeight = function () {
|
|
30
|
+
return this.post(types_1.RPCMethod.GetHeight);
|
|
31
|
+
};
|
|
32
|
+
RPC.prototype.getTopoHeight = function () {
|
|
33
|
+
return this.post(types_1.RPCMethod.GetTopoHeight);
|
|
34
|
+
};
|
|
35
|
+
RPC.prototype.getStableHeight = function () {
|
|
36
|
+
return this.post(types_1.RPCMethod.GetStableHeight);
|
|
37
|
+
};
|
|
38
|
+
RPC.prototype.getBlockTemplate = function (address) {
|
|
39
|
+
return this.post(types_1.RPCMethod.GetBlockTemplate, { address: address });
|
|
40
|
+
};
|
|
41
|
+
RPC.prototype.getBlockAtTopoHeight = function (params) {
|
|
42
|
+
return this.post(types_1.RPCMethod.GetBlockAtTopoHeight, params);
|
|
43
|
+
};
|
|
44
|
+
RPC.prototype.getBlocksAtHeight = function (params) {
|
|
45
|
+
return this.post(types_1.RPCMethod.GetBlocksAtHeight, params);
|
|
46
|
+
};
|
|
47
|
+
RPC.prototype.getBlockByHash = function (params) {
|
|
48
|
+
return this.post(types_1.RPCMethod.GetBlockByHash, params);
|
|
49
|
+
};
|
|
50
|
+
RPC.prototype.getTopBlock = function (params) {
|
|
51
|
+
return this.post(types_1.RPCMethod.GetTopBlock, params);
|
|
52
|
+
};
|
|
53
|
+
RPC.prototype.submitBlock = function (blockTemplate) {
|
|
54
|
+
return this.post(types_1.RPCMethod.SubmitBlock, { block_template: blockTemplate });
|
|
55
|
+
};
|
|
56
|
+
RPC.prototype.getBalance = function (params) {
|
|
57
|
+
return this.post(types_1.RPCMethod.GetBalance, params);
|
|
58
|
+
};
|
|
59
|
+
RPC.prototype.hasBalance = function (params) {
|
|
60
|
+
return this.post(types_1.RPCMethod.HasBalance, params);
|
|
61
|
+
};
|
|
62
|
+
RPC.prototype.getBalanceAtTopoHeight = function (params) {
|
|
63
|
+
return this.post(types_1.RPCMethod.GetBalanceAtTopoHeight, params);
|
|
64
|
+
};
|
|
65
|
+
RPC.prototype.getInfo = function () {
|
|
66
|
+
return this.post(types_1.RPCMethod.GetInfo);
|
|
67
|
+
};
|
|
68
|
+
RPC.prototype.getNonce = function (params) {
|
|
69
|
+
return this.post(types_1.RPCMethod.GetNonce, params);
|
|
70
|
+
};
|
|
71
|
+
RPC.prototype.hasNonce = function (params) {
|
|
72
|
+
return this.post(types_1.RPCMethod.HasNonce, params);
|
|
73
|
+
};
|
|
74
|
+
RPC.prototype.getNonceAtTopoheight = function (params) {
|
|
75
|
+
return this.post(types_1.RPCMethod.GetNonceAtTopoheight, params);
|
|
76
|
+
};
|
|
77
|
+
RPC.prototype.getAsset = function (params) {
|
|
78
|
+
return this.post(types_1.RPCMethod.GetAsset, params);
|
|
79
|
+
};
|
|
80
|
+
RPC.prototype.getAssets = function () {
|
|
81
|
+
return this.post(types_1.RPCMethod.GetAssets);
|
|
82
|
+
};
|
|
83
|
+
RPC.prototype.countAssets = function () {
|
|
84
|
+
return this.post(types_1.RPCMethod.CountAssets);
|
|
85
|
+
};
|
|
86
|
+
RPC.prototype.countAccounts = function () {
|
|
87
|
+
return this.post(types_1.RPCMethod.CountAccounts);
|
|
88
|
+
};
|
|
89
|
+
RPC.prototype.countTransactions = function () {
|
|
90
|
+
return this.post(types_1.RPCMethod.CountTransactions);
|
|
91
|
+
};
|
|
92
|
+
RPC.prototype.submitTransaction = function (hexData) {
|
|
93
|
+
return this.post(types_1.RPCMethod.SubmitTransaction, { data: hexData });
|
|
94
|
+
};
|
|
95
|
+
RPC.prototype.getTransaction = function (hash) {
|
|
96
|
+
return this.post(types_1.RPCMethod.GetTransaction, { hash: hash });
|
|
97
|
+
};
|
|
98
|
+
RPC.prototype.p2pStatus = function () {
|
|
99
|
+
return this.post(types_1.RPCMethod.P2PStatus);
|
|
100
|
+
};
|
|
101
|
+
RPC.prototype.getPeers = function () {
|
|
102
|
+
return this.post(types_1.RPCMethod.GetPeers);
|
|
103
|
+
};
|
|
104
|
+
RPC.prototype.getMemPool = function () {
|
|
105
|
+
return this.post(types_1.RPCMethod.GetMempool);
|
|
106
|
+
};
|
|
107
|
+
RPC.prototype.getTips = function () {
|
|
108
|
+
return this.post(types_1.RPCMethod.GetTips);
|
|
109
|
+
};
|
|
110
|
+
RPC.prototype.getDAGOrder = function (params) {
|
|
111
|
+
return this.post(types_1.RPCMethod.GetDAGOrder, params);
|
|
112
|
+
};
|
|
113
|
+
RPC.prototype.getBlocksRangeByTopoheight = function (params) {
|
|
114
|
+
return this.post(types_1.RPCMethod.GetBlocksRangeByTopoheight, params);
|
|
115
|
+
};
|
|
116
|
+
RPC.prototype.getBlocksRangeByHeight = function (params) {
|
|
117
|
+
return this.post(types_1.RPCMethod.GetBlocksRangeByHeight, params);
|
|
118
|
+
};
|
|
119
|
+
RPC.prototype.getTransactions = function (txHashes) {
|
|
120
|
+
return this.post(types_1.RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
121
|
+
};
|
|
122
|
+
RPC.prototype.getAccountHistory = function (params) {
|
|
123
|
+
return this.post(types_1.RPCMethod.GetAccountHistory, params);
|
|
124
|
+
};
|
|
125
|
+
RPC.prototype.getAccountAssets = function (address) {
|
|
126
|
+
return this.post(types_1.RPCMethod.GetAccountAssets, { address: address });
|
|
127
|
+
};
|
|
128
|
+
RPC.prototype.getAccounts = function (params) {
|
|
129
|
+
return this.post(types_1.RPCMethod.GetAccounts, params);
|
|
130
|
+
};
|
|
131
|
+
RPC.prototype.isTxExecutedInBlock = function (params) {
|
|
132
|
+
return this.post(types_1.RPCMethod.IsTxExecutedInBlock, params);
|
|
133
|
+
};
|
|
134
|
+
RPC.prototype.getDevFeeThresholds = function () {
|
|
135
|
+
return this.post(types_1.RPCMethod.GetDevFeeThresholds);
|
|
136
|
+
};
|
|
137
|
+
RPC.prototype.getSizeOnDisk = function () {
|
|
138
|
+
return this.post(types_1.RPCMethod.GetSizeOnDisk);
|
|
139
|
+
};
|
|
140
|
+
return RPC;
|
|
141
|
+
}(rpc_1.RPC));
|
|
142
|
+
exports.RPC = RPC;
|
|
143
|
+
exports["default"] = RPC;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.RPCEvent = exports.RPCMethod = exports.BlockType = exports.BalanceType = void 0;
|
|
4
|
+
var BalanceType;
|
|
5
|
+
(function (BalanceType) {
|
|
6
|
+
BalanceType["Input"] = "input";
|
|
7
|
+
BalanceType["Output"] = "output";
|
|
8
|
+
BalanceType["Both"] = "both";
|
|
9
|
+
})(BalanceType = exports.BalanceType || (exports.BalanceType = {}));
|
|
10
|
+
var BlockType;
|
|
11
|
+
(function (BlockType) {
|
|
12
|
+
BlockType["Sync"] = "Sync";
|
|
13
|
+
BlockType["Normal"] = "Normal";
|
|
14
|
+
BlockType["Side"] = "Side";
|
|
15
|
+
BlockType["Orphaned"] = "Orphaned";
|
|
16
|
+
})(BlockType = exports.BlockType || (exports.BlockType = {}));
|
|
17
|
+
var RPCMethod;
|
|
18
|
+
(function (RPCMethod) {
|
|
19
|
+
RPCMethod["GetVersion"] = "get_version";
|
|
20
|
+
RPCMethod["GetInfo"] = "get_info";
|
|
21
|
+
RPCMethod["GetHeight"] = "get_height";
|
|
22
|
+
RPCMethod["GetTopoHeight"] = "get_topoheight";
|
|
23
|
+
RPCMethod["GetStableHeight"] = "get_stableheight";
|
|
24
|
+
RPCMethod["GetBlockTemplate"] = "get_block_template";
|
|
25
|
+
RPCMethod["GetBlockAtTopoHeight"] = "get_block_at_topoheight";
|
|
26
|
+
RPCMethod["GetBlocksAtHeight"] = "get_blocks_at_height";
|
|
27
|
+
RPCMethod["GetBlockByHash"] = "get_block_by_hash";
|
|
28
|
+
RPCMethod["GetTopBlock"] = "get_top_block";
|
|
29
|
+
RPCMethod["GetNonce"] = "get_nonce";
|
|
30
|
+
RPCMethod["GetNonceAtTopoheight"] = "get_nonce_at_topoheight";
|
|
31
|
+
RPCMethod["HasNonce"] = "has_nonce";
|
|
32
|
+
RPCMethod["GetBalance"] = "get_balance";
|
|
33
|
+
RPCMethod["HasBalance"] = "has_balance";
|
|
34
|
+
RPCMethod["GetBalanceAtTopoHeight"] = "get_balance_at_topoheight";
|
|
35
|
+
RPCMethod["GetAsset"] = "get_asset";
|
|
36
|
+
RPCMethod["GetAssets"] = "get_assets";
|
|
37
|
+
RPCMethod["CountAssets"] = "count_assets";
|
|
38
|
+
RPCMethod["CountTransactions"] = "count_transactions";
|
|
39
|
+
RPCMethod["GetTips"] = "get_tips";
|
|
40
|
+
RPCMethod["P2PStatus"] = "p2p_status";
|
|
41
|
+
RPCMethod["GetDAGOrder"] = "get_dag_order";
|
|
42
|
+
RPCMethod["GetMempool"] = "get_mempool";
|
|
43
|
+
RPCMethod["GetTransaction"] = "get_transaction";
|
|
44
|
+
RPCMethod["GetTransactions"] = "get_transactions";
|
|
45
|
+
RPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
|
|
46
|
+
RPCMethod["GetBlocksRangeByHeight"] = "get_blocks_range_by_height";
|
|
47
|
+
RPCMethod["GetAccounts"] = "get_accounts";
|
|
48
|
+
RPCMethod["SubmitBlock"] = "submit_block";
|
|
49
|
+
RPCMethod["SubmitTransaction"] = "submit_transaction";
|
|
50
|
+
RPCMethod["CountAccounts"] = "count_accounts";
|
|
51
|
+
RPCMethod["GetAccountHistory"] = "get_account_history";
|
|
52
|
+
RPCMethod["GetAccountAssets"] = "get_account_assets";
|
|
53
|
+
RPCMethod["GetPeers"] = "get_peers";
|
|
54
|
+
RPCMethod["GetDevFeeThresholds"] = "get_dev_fee_thresholds";
|
|
55
|
+
RPCMethod["GetSizeOnDisk"] = "get_size_on_disk";
|
|
56
|
+
RPCMethod["IsTxExecutedInBlock"] = "is_tx_executed_in_block";
|
|
57
|
+
})(RPCMethod = exports.RPCMethod || (exports.RPCMethod = {}));
|
|
58
|
+
var RPCEvent;
|
|
59
|
+
(function (RPCEvent) {
|
|
60
|
+
RPCEvent["NewBlock"] = "new_block";
|
|
61
|
+
RPCEvent["BlockOrdered"] = "block_ordered";
|
|
62
|
+
RPCEvent["BlockOrphaned"] = "block_orphaned";
|
|
63
|
+
RPCEvent["StableHeightChanged"] = "stable_height_changed";
|
|
64
|
+
RPCEvent["TransactionOrphaned"] = "transaction_orphaned";
|
|
65
|
+
RPCEvent["TransactionAddedInMempool"] = "transaction_added_in_mempool";
|
|
66
|
+
RPCEvent["TransactionExecuted"] = "transaction_executed";
|
|
67
|
+
RPCEvent["TransactionSCResult"] = "transaction_sc_result";
|
|
68
|
+
RPCEvent["NewAsset"] = "new_asset";
|
|
69
|
+
RPCEvent["PeerConnected"] = "peer_connected";
|
|
70
|
+
RPCEvent["PeerDisconnected"] = "peer_disconnected";
|
|
71
|
+
RPCEvent["PeerPeerListUpdated"] = "peer_peer_list_updated";
|
|
72
|
+
RPCEvent["PeerStateUpdated"] = "peer_state_updated";
|
|
73
|
+
RPCEvent["PeerPeerDisconnected"] = "peer_peer_disconnected";
|
|
74
|
+
})(RPCEvent = exports.RPCEvent || (exports.RPCEvent = {}));
|
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
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
|
+
exports.__esModule = true;
|
|
54
|
+
exports.WS = exports.DaemonMethods = void 0;
|
|
55
|
+
var types_1 = require("./types");
|
|
56
|
+
var websocket_1 = require("../lib/websocket");
|
|
57
|
+
var DaemonMethods = /** @class */ (function () {
|
|
58
|
+
function DaemonMethods(ws, prefix) {
|
|
59
|
+
if (prefix === void 0) { prefix = ""; }
|
|
60
|
+
this.ws = ws;
|
|
61
|
+
this.prefix = prefix;
|
|
62
|
+
}
|
|
63
|
+
DaemonMethods.prototype.listenEvent = function (event, onData) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
return [2 /*return*/, this.ws.listenEvent(this.prefix + event, onData)];
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
DaemonMethods.prototype.dataCall = function (method, params) {
|
|
71
|
+
return this.ws.dataCall(this.prefix + method, params);
|
|
72
|
+
};
|
|
73
|
+
DaemonMethods.prototype.onNewBlock = function (onData) {
|
|
74
|
+
return this.listenEvent(types_1.RPCEvent.NewBlock, onData);
|
|
75
|
+
};
|
|
76
|
+
DaemonMethods.prototype.onTransactionAddedInMempool = function (onData) {
|
|
77
|
+
return this.listenEvent(types_1.RPCEvent.TransactionAddedInMempool, onData);
|
|
78
|
+
};
|
|
79
|
+
DaemonMethods.prototype.onTransactionExecuted = function (onData) {
|
|
80
|
+
return this.listenEvent(types_1.RPCEvent.TransactionExecuted, onData);
|
|
81
|
+
};
|
|
82
|
+
DaemonMethods.prototype.onBlockOrdered = function (onData) {
|
|
83
|
+
return this.listenEvent(types_1.RPCEvent.BlockOrdered, onData);
|
|
84
|
+
};
|
|
85
|
+
DaemonMethods.prototype.onPeerConnected = function (onData) {
|
|
86
|
+
return this.listenEvent(types_1.RPCEvent.PeerConnected, onData);
|
|
87
|
+
};
|
|
88
|
+
DaemonMethods.prototype.onPeerDisconnected = function (onData) {
|
|
89
|
+
return this.listenEvent(types_1.RPCEvent.PeerDisconnected, onData);
|
|
90
|
+
};
|
|
91
|
+
DaemonMethods.prototype.onPeerPeerListUpdated = function (onData) {
|
|
92
|
+
return this.listenEvent(types_1.RPCEvent.PeerPeerListUpdated, onData);
|
|
93
|
+
};
|
|
94
|
+
DaemonMethods.prototype.onPeerPeerDisconnected = function (onData) {
|
|
95
|
+
return this.listenEvent(types_1.RPCEvent.PeerPeerDisconnected, onData);
|
|
96
|
+
};
|
|
97
|
+
DaemonMethods.prototype.onPeerStateUpdated = function (onData) {
|
|
98
|
+
return this.listenEvent(types_1.RPCEvent.PeerStateUpdated, onData);
|
|
99
|
+
};
|
|
100
|
+
DaemonMethods.prototype.onNewAsset = function (onData) {
|
|
101
|
+
return this.listenEvent(types_1.RPCEvent.NewAsset, onData);
|
|
102
|
+
};
|
|
103
|
+
DaemonMethods.prototype.onBlockOrphaned = function (onData) {
|
|
104
|
+
return this.listenEvent(types_1.RPCEvent.BlockOrphaned, onData);
|
|
105
|
+
};
|
|
106
|
+
DaemonMethods.prototype.onTransactionOrphaned = function (onData) {
|
|
107
|
+
return this.listenEvent(types_1.RPCEvent.TransactionOrphaned, onData);
|
|
108
|
+
};
|
|
109
|
+
DaemonMethods.prototype.onStableHeightChanged = function (onData) {
|
|
110
|
+
return this.listenEvent(types_1.RPCEvent.StableHeightChanged, onData);
|
|
111
|
+
};
|
|
112
|
+
DaemonMethods.prototype.getVersion = function () {
|
|
113
|
+
return this.dataCall(types_1.RPCMethod.GetVersion);
|
|
114
|
+
};
|
|
115
|
+
DaemonMethods.prototype.getHeight = function () {
|
|
116
|
+
return this.dataCall(types_1.RPCMethod.GetHeight);
|
|
117
|
+
};
|
|
118
|
+
DaemonMethods.prototype.getTopoHeight = function () {
|
|
119
|
+
return this.dataCall(types_1.RPCMethod.GetTopoHeight);
|
|
120
|
+
};
|
|
121
|
+
DaemonMethods.prototype.getStableHeight = function () {
|
|
122
|
+
return this.dataCall(types_1.RPCMethod.GetStableHeight);
|
|
123
|
+
};
|
|
124
|
+
DaemonMethods.prototype.getBlockTemplate = function (address) {
|
|
125
|
+
return this.dataCall(types_1.RPCMethod.GetBlockTemplate, { address: address });
|
|
126
|
+
};
|
|
127
|
+
DaemonMethods.prototype.getBlockAtTopoHeight = function (params) {
|
|
128
|
+
return this.dataCall(types_1.RPCMethod.GetBlockAtTopoHeight, params);
|
|
129
|
+
};
|
|
130
|
+
DaemonMethods.prototype.getBlocksAtHeight = function (params) {
|
|
131
|
+
return this.dataCall(types_1.RPCMethod.GetBlocksAtHeight, params);
|
|
132
|
+
};
|
|
133
|
+
DaemonMethods.prototype.getBlockByHash = function (params) {
|
|
134
|
+
return this.dataCall(types_1.RPCMethod.GetBlockByHash, params);
|
|
135
|
+
};
|
|
136
|
+
DaemonMethods.prototype.getTopBlock = function (params) {
|
|
137
|
+
return this.dataCall(types_1.RPCMethod.GetTopBlock, params);
|
|
138
|
+
};
|
|
139
|
+
DaemonMethods.prototype.submitBlock = function (blockTemplate) {
|
|
140
|
+
return this.dataCall(types_1.RPCMethod.SubmitBlock, { block_template: blockTemplate });
|
|
141
|
+
};
|
|
142
|
+
DaemonMethods.prototype.getBalance = function (params) {
|
|
143
|
+
return this.dataCall(types_1.RPCMethod.GetBalance, params);
|
|
144
|
+
};
|
|
145
|
+
DaemonMethods.prototype.hasBalance = function (params) {
|
|
146
|
+
return this.dataCall(types_1.RPCMethod.HasBalance, params);
|
|
147
|
+
};
|
|
148
|
+
DaemonMethods.prototype.getBalanceAtTopoHeight = function (params) {
|
|
149
|
+
return this.dataCall(types_1.RPCMethod.GetBalanceAtTopoHeight, params);
|
|
150
|
+
};
|
|
151
|
+
DaemonMethods.prototype.getInfo = function () {
|
|
152
|
+
return this.dataCall(types_1.RPCMethod.GetInfo);
|
|
153
|
+
};
|
|
154
|
+
DaemonMethods.prototype.getNonce = function (params) {
|
|
155
|
+
return this.dataCall(types_1.RPCMethod.GetNonce, params);
|
|
156
|
+
};
|
|
157
|
+
DaemonMethods.prototype.hasNonce = function (params) {
|
|
158
|
+
return this.dataCall(types_1.RPCMethod.HasNonce, params);
|
|
159
|
+
};
|
|
160
|
+
DaemonMethods.prototype.getAsset = function (params) {
|
|
161
|
+
return this.dataCall(types_1.RPCMethod.GetAsset, params);
|
|
162
|
+
};
|
|
163
|
+
DaemonMethods.prototype.getAssets = function () {
|
|
164
|
+
return this.dataCall(types_1.RPCMethod.GetAssets);
|
|
165
|
+
};
|
|
166
|
+
DaemonMethods.prototype.countAssets = function () {
|
|
167
|
+
return this.dataCall(types_1.RPCMethod.CountAssets);
|
|
168
|
+
};
|
|
169
|
+
DaemonMethods.prototype.countAccounts = function () {
|
|
170
|
+
return this.dataCall(types_1.RPCMethod.CountAccounts);
|
|
171
|
+
};
|
|
172
|
+
DaemonMethods.prototype.countTransactions = function () {
|
|
173
|
+
return this.dataCall(types_1.RPCMethod.CountTransactions);
|
|
174
|
+
};
|
|
175
|
+
DaemonMethods.prototype.submitTransaction = function (hexData) {
|
|
176
|
+
return this.dataCall(types_1.RPCMethod.SubmitTransaction, { data: hexData });
|
|
177
|
+
};
|
|
178
|
+
DaemonMethods.prototype.getTransaction = function (hash) {
|
|
179
|
+
return this.dataCall(types_1.RPCMethod.GetTransaction, { hash: hash });
|
|
180
|
+
};
|
|
181
|
+
DaemonMethods.prototype.p2pStatus = function () {
|
|
182
|
+
return this.dataCall(types_1.RPCMethod.P2PStatus);
|
|
183
|
+
};
|
|
184
|
+
DaemonMethods.prototype.getPeers = function () {
|
|
185
|
+
return this.dataCall(types_1.RPCMethod.GetPeers);
|
|
186
|
+
};
|
|
187
|
+
DaemonMethods.prototype.getMemPool = function () {
|
|
188
|
+
return this.dataCall(types_1.RPCMethod.GetMempool);
|
|
189
|
+
};
|
|
190
|
+
DaemonMethods.prototype.getTips = function () {
|
|
191
|
+
return this.dataCall(types_1.RPCMethod.GetTips);
|
|
192
|
+
};
|
|
193
|
+
DaemonMethods.prototype.getDAGOrder = function (params) {
|
|
194
|
+
return this.dataCall(types_1.RPCMethod.GetDAGOrder, params);
|
|
195
|
+
};
|
|
196
|
+
DaemonMethods.prototype.getBlocksRangeByTopoheight = function (params) {
|
|
197
|
+
return this.dataCall(types_1.RPCMethod.GetBlocksRangeByTopoheight, params);
|
|
198
|
+
};
|
|
199
|
+
DaemonMethods.prototype.getBlocksRangeByHeight = function (params) {
|
|
200
|
+
return this.dataCall(types_1.RPCMethod.GetBlocksRangeByHeight, params);
|
|
201
|
+
};
|
|
202
|
+
DaemonMethods.prototype.getTransactions = function (txHashes) {
|
|
203
|
+
return this.dataCall(types_1.RPCMethod.GetTransactions, { tx_hashes: txHashes });
|
|
204
|
+
};
|
|
205
|
+
DaemonMethods.prototype.getAccountHistory = function (params) {
|
|
206
|
+
return this.dataCall(types_1.RPCMethod.GetAccountHistory, params);
|
|
207
|
+
};
|
|
208
|
+
DaemonMethods.prototype.getAccountAssets = function (address) {
|
|
209
|
+
return this.dataCall(types_1.RPCMethod.GetAccountAssets, { address: address });
|
|
210
|
+
};
|
|
211
|
+
DaemonMethods.prototype.getAccounts = function (params) {
|
|
212
|
+
return this.dataCall(types_1.RPCMethod.GetAccounts, params);
|
|
213
|
+
};
|
|
214
|
+
DaemonMethods.prototype.isTxExecutedInBlock = function (params) {
|
|
215
|
+
return this.dataCall(types_1.RPCMethod.IsTxExecutedInBlock, params);
|
|
216
|
+
};
|
|
217
|
+
DaemonMethods.prototype.getDevFeeThresholds = function () {
|
|
218
|
+
return this.dataCall(types_1.RPCMethod.GetDevFeeThresholds);
|
|
219
|
+
};
|
|
220
|
+
DaemonMethods.prototype.getSizeOnDisk = function () {
|
|
221
|
+
return this.dataCall(types_1.RPCMethod.GetSizeOnDisk);
|
|
222
|
+
};
|
|
223
|
+
return DaemonMethods;
|
|
224
|
+
}());
|
|
225
|
+
exports.DaemonMethods = DaemonMethods;
|
|
226
|
+
var WS = /** @class */ (function (_super) {
|
|
227
|
+
__extends(WS, _super);
|
|
228
|
+
function WS() {
|
|
229
|
+
var _this = _super.call(this) || this;
|
|
230
|
+
_this.methods = new DaemonMethods(_this);
|
|
231
|
+
return _this;
|
|
232
|
+
}
|
|
233
|
+
return WS;
|
|
234
|
+
}(websocket_1.WS));
|
|
235
|
+
exports.WS = WS;
|
|
236
|
+
exports["default"] = WS;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.RPC = void 0;
|
|
40
|
+
var RPC = /** @class */ (function () {
|
|
41
|
+
function RPC(endpoint) {
|
|
42
|
+
this.endpoint = endpoint;
|
|
43
|
+
this.timeout = 3000;
|
|
44
|
+
}
|
|
45
|
+
RPC.prototype.post = function (method, params, headers) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var controller_1, body, timeoutId, res, data, err_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
_a.trys.push([0, 5, , 6]);
|
|
52
|
+
controller_1 = new AbortController();
|
|
53
|
+
body = JSON.stringify({ id: 1, jsonrpc: '2.0', method: method, params: params });
|
|
54
|
+
timeoutId = setTimeout(function () {
|
|
55
|
+
controller_1.abort();
|
|
56
|
+
}, this.timeout);
|
|
57
|
+
headers = headers || new Headers();
|
|
58
|
+
headers.set("Content-Type", "application/json");
|
|
59
|
+
return [4 /*yield*/, fetch(this.endpoint, {
|
|
60
|
+
headers: headers,
|
|
61
|
+
method: "POST",
|
|
62
|
+
body: body,
|
|
63
|
+
signal: controller_1.signal
|
|
64
|
+
})];
|
|
65
|
+
case 1:
|
|
66
|
+
res = _a.sent();
|
|
67
|
+
clearTimeout(timeoutId);
|
|
68
|
+
if (!res.ok) return [3 /*break*/, 3];
|
|
69
|
+
return [4 /*yield*/, res.json()];
|
|
70
|
+
case 2:
|
|
71
|
+
data = _a.sent();
|
|
72
|
+
if (data.error) {
|
|
73
|
+
return [2 /*return*/, Promise.reject(new Error(data.error.message))];
|
|
74
|
+
}
|
|
75
|
+
return [2 /*return*/, Promise.resolve(data)];
|
|
76
|
+
case 3: return [2 /*return*/, Promise.reject(new Error("".concat(res.status, " - ").concat(res.statusText)))];
|
|
77
|
+
case 4: return [3 /*break*/, 6];
|
|
78
|
+
case 5:
|
|
79
|
+
err_1 = _a.sent();
|
|
80
|
+
console.log(err_1);
|
|
81
|
+
return [2 /*return*/, Promise.reject(err_1)];
|
|
82
|
+
case 6: return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return RPC;
|
|
88
|
+
}());
|
|
89
|
+
exports.RPC = RPC;
|