@xelis/sdk 0.10.6 → 0.10.10
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/dist/cjs/daemon/rpc.js +6 -0
- package/dist/cjs/daemon/types.js +7 -3
- package/dist/cjs/daemon/websocket.js +14 -0
- package/dist/cjs/rpc/websocket.js +25 -28
- package/dist/cjs/wallet/rpc.js +6 -0
- package/dist/cjs/wallet/types.js +4 -8
- package/dist/cjs/wallet/websocket.js +6 -0
- package/dist/cjs/xswd/relayer/app.js +62 -0
- package/dist/cjs/xswd/relayer/index.css +37 -0
- package/dist/cjs/xswd/relayer/index.js +48 -0
- package/dist/cjs/xswd/types.js +0 -7
- package/dist/esm/daemon/rpc.js +6 -0
- package/dist/esm/daemon/types.js +7 -3
- package/dist/esm/daemon/websocket.js +14 -0
- package/dist/esm/rpc/websocket.js +25 -28
- package/dist/esm/wallet/rpc.js +6 -0
- package/dist/esm/wallet/types.js +3 -7
- package/dist/esm/wallet/websocket.js +6 -0
- package/dist/esm/xswd/relayer/app.js +56 -0
- package/dist/esm/xswd/relayer/index.css +37 -0
- package/dist/esm/xswd/relayer/index.js +46 -0
- package/dist/esm/xswd/types.js +1 -6
- package/dist/types/daemon/rpc.d.ts +2 -0
- package/dist/types/daemon/types.d.ts +43 -7
- package/dist/types/daemon/websocket.d.ts +4 -0
- package/dist/types/wallet/rpc.d.ts +2 -0
- package/dist/types/wallet/types.d.ts +8 -14
- package/dist/types/wallet/websocket.d.ts +2 -0
- package/dist/types/xswd/relayer/app.d.ts +14 -0
- package/dist/types/xswd/relayer/index.d.ts +20 -0
- package/dist/types/xswd/types.d.ts +1 -7
- package/dist/types/xswd/websocket.d.ts +1 -1
- package/package.json +13 -5
package/dist/cjs/daemon/rpc.js
CHANGED
|
@@ -212,6 +212,12 @@ var RPC = /** @class */ (function (_super) {
|
|
|
212
212
|
RPC.prototype.getContractBalanceAtTopoheight = function (params) {
|
|
213
213
|
return this.request(types_1.RPCMethod.GetContractBalanceAtTopoheight, params);
|
|
214
214
|
};
|
|
215
|
+
RPC.prototype.getContractAssets = function (params) {
|
|
216
|
+
return this.request(types_1.RPCMethod.GetContractAssets, params);
|
|
217
|
+
};
|
|
218
|
+
RPC.prototype.getP2PBlockPropagation = function (params) {
|
|
219
|
+
return this.request(types_1.RPCMethod.GetP2PBlockPropagation, params);
|
|
220
|
+
};
|
|
215
221
|
RPC.prototype.getBlockTemplate = function (address) {
|
|
216
222
|
return this.request(types_1.RPCMethod.GetBlockTemplate, { address: address });
|
|
217
223
|
};
|
package/dist/cjs/daemon/types.js
CHANGED
|
@@ -42,8 +42,8 @@ var RPCMethod;
|
|
|
42
42
|
RPCMethod["GetAsset"] = "get_asset";
|
|
43
43
|
RPCMethod["GetAssets"] = "get_assets";
|
|
44
44
|
RPCMethod["CountAssets"] = "count_assets";
|
|
45
|
-
RPCMethod["CountTransactions"] = "count_transactions";
|
|
46
45
|
RPCMethod["CountAccounts"] = "count_accounts";
|
|
46
|
+
RPCMethod["CountTransactions"] = "count_transactions";
|
|
47
47
|
RPCMethod["CountContracts"] = "count_contracts";
|
|
48
48
|
RPCMethod["SubmitTransaction"] = "submit_transaction";
|
|
49
49
|
RPCMethod["GetTransactionExecutor"] = "get_transaction_executor";
|
|
@@ -53,8 +53,8 @@ var RPCMethod;
|
|
|
53
53
|
RPCMethod["P2PStatus"] = "p2p_status";
|
|
54
54
|
RPCMethod["GetPeers"] = "get_peers";
|
|
55
55
|
RPCMethod["GetMempool"] = "get_mempool";
|
|
56
|
-
RPCMethod["GetMempoolCache"] = "get_mempool_cache";
|
|
57
56
|
RPCMethod["GetMempoolSummary"] = "get_mempool_summary";
|
|
57
|
+
RPCMethod["GetMempoolCache"] = "get_mempool_cache";
|
|
58
58
|
RPCMethod["GetEstimatedFeeRates"] = "get_estimated_fee_rates";
|
|
59
59
|
RPCMethod["GetDAGOrder"] = "get_dag_order";
|
|
60
60
|
RPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
|
|
@@ -79,6 +79,8 @@ var RPCMethod;
|
|
|
79
79
|
RPCMethod["GetContractDataAtTopoheight"] = "get_contract_data_at_topoheight";
|
|
80
80
|
RPCMethod["GetContractBalance"] = "get_contract_balance";
|
|
81
81
|
RPCMethod["GetContractBalanceAtTopoheight"] = "get_contract_balance_at_topoheight";
|
|
82
|
+
RPCMethod["GetContractAssets"] = "get_contract_assets";
|
|
83
|
+
RPCMethod["GetP2PBlockPropagation"] = "get_p2p_block_propagation";
|
|
82
84
|
RPCMethod["GetBlockTemplate"] = "get_block_template";
|
|
83
85
|
RPCMethod["GetMinerWork"] = "get_miner_work";
|
|
84
86
|
RPCMethod["SubmitBlock"] = "submit_block";
|
|
@@ -94,12 +96,14 @@ var RPCEvent;
|
|
|
94
96
|
RPCEvent["TransactionAddedInMempool"] = "transaction_added_in_mempool";
|
|
95
97
|
RPCEvent["TransactionExecuted"] = "transaction_executed";
|
|
96
98
|
RPCEvent["InvokeContract"] = "invoke_contract";
|
|
99
|
+
RPCEvent["ContractTransfer"] = "contract_transfer";
|
|
100
|
+
RPCEvent["ContractEvent"] = "contract_event";
|
|
97
101
|
RPCEvent["DeployContract"] = "deploy_contract";
|
|
98
102
|
RPCEvent["NewAsset"] = "new_asset";
|
|
99
103
|
RPCEvent["PeerConnected"] = "peer_connected";
|
|
100
104
|
RPCEvent["PeerDisconnected"] = "peer_disconnected";
|
|
101
|
-
RPCEvent["PeerStateUpdated"] = "peer_state_updated";
|
|
102
105
|
RPCEvent["PeerPeerListUpdated"] = "peer_peer_list_updated";
|
|
106
|
+
RPCEvent["PeerStateUpdated"] = "peer_state_updated";
|
|
103
107
|
RPCEvent["PeerPeerDisconnected"] = "peer_peer_disconnected";
|
|
104
108
|
RPCEvent["NewBlockTemplate"] = "new_block_template";
|
|
105
109
|
})(RPCEvent = exports.RPCEvent || (exports.RPCEvent = {}));
|
|
@@ -55,6 +55,14 @@ var DaemonMethods = /** @class */ (function () {
|
|
|
55
55
|
var _a;
|
|
56
56
|
return this.ws.listenEvent((_a = {}, _a[this.prefix + types_1.RPCEvent.InvokeContract] = { contract: contract }, _a), onData);
|
|
57
57
|
};
|
|
58
|
+
DaemonMethods.prototype.onContractTransfer = function (address, onData) {
|
|
59
|
+
var _a;
|
|
60
|
+
return this.ws.listenEvent((_a = {}, _a[this.prefix + types_1.RPCEvent.ContractTransfer] = { address: address }, _a), onData);
|
|
61
|
+
};
|
|
62
|
+
DaemonMethods.prototype.onContractEvent = function (contract, id, onData) {
|
|
63
|
+
var _a;
|
|
64
|
+
return this.ws.listenEvent((_a = {}, _a[this.prefix + types_1.RPCEvent.ContractEvent] = { contract: contract, id: id }, _a), onData);
|
|
65
|
+
};
|
|
58
66
|
DaemonMethods.prototype.onDeployContract = function (onData) {
|
|
59
67
|
return this.ws.listenEvent(this.prefix + types_1.RPCEvent.DeployContract, onData);
|
|
60
68
|
};
|
|
@@ -268,6 +276,12 @@ var DaemonMethods = /** @class */ (function () {
|
|
|
268
276
|
DaemonMethods.prototype.getContractBalanceAtTopoheight = function (params) {
|
|
269
277
|
return this.dataCall(types_1.RPCMethod.GetContractBalanceAtTopoheight, params);
|
|
270
278
|
};
|
|
279
|
+
DaemonMethods.prototype.getContractAssets = function (params) {
|
|
280
|
+
return this.dataCall(types_1.RPCMethod.GetContractAssets, params);
|
|
281
|
+
};
|
|
282
|
+
DaemonMethods.prototype.getP2PBlockPropagation = function (params) {
|
|
283
|
+
return this.dataCall(types_1.RPCMethod.GetP2PBlockPropagation, params);
|
|
284
|
+
};
|
|
271
285
|
DaemonMethods.prototype.getBlockTemplate = function (address) {
|
|
272
286
|
return this.dataCall(types_1.RPCMethod.GetBlockTemplate, { address: address });
|
|
273
287
|
};
|
|
@@ -133,7 +133,7 @@ var WSRPC = /** @class */ (function () {
|
|
|
133
133
|
};
|
|
134
134
|
WSRPC.prototype.listenEvent = function (event, onData) {
|
|
135
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
var onMessage, eventData, idRefObject, _a, err, _, closeListen;
|
|
136
|
+
var onMessage, eventData, idRefObject, _a, err, _, eventData_1, closeListen;
|
|
137
137
|
var _this = this;
|
|
138
138
|
return __generator(this, function (_b) {
|
|
139
139
|
switch (_b.label) {
|
|
@@ -167,6 +167,9 @@ var WSRPC = /** @class */ (function () {
|
|
|
167
167
|
eventData.listeners.push(onMessage);
|
|
168
168
|
return [3 /*break*/, 3];
|
|
169
169
|
case 1:
|
|
170
|
+
// important if multiple listenEvent are called without await at least we store listener before getting id
|
|
171
|
+
// avoid trying to subscribe the same event multiple times
|
|
172
|
+
this.events.set(event, { listeners: [onMessage] });
|
|
170
173
|
idRefObject = {};
|
|
171
174
|
return [4 /*yield*/, (0, await_to_js_1.to)(this.dataCall("subscribe", { notify: event }, idRefObject))];
|
|
172
175
|
case 2:
|
|
@@ -175,7 +178,9 @@ var WSRPC = /** @class */ (function () {
|
|
|
175
178
|
this.clearEvent(event);
|
|
176
179
|
return [2 /*return*/, Promise.reject(err)];
|
|
177
180
|
}
|
|
178
|
-
this.events.
|
|
181
|
+
eventData_1 = this.events.get(event);
|
|
182
|
+
if (eventData_1)
|
|
183
|
+
eventData_1.id = idRefObject.id;
|
|
179
184
|
_b.label = 3;
|
|
180
185
|
case 3:
|
|
181
186
|
this.socket && this.socket.addEventListener("message", onMessage);
|
|
@@ -191,20 +196,16 @@ var WSRPC = /** @class */ (function () {
|
|
|
191
196
|
}
|
|
192
197
|
// no more listener so we unsubscribe from daemon websocket if socket still open
|
|
193
198
|
if (listeners.length === 0) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
199
|
+
// we use a grace period to unsubscribe (mostly because of react useEffect and avoid unecessary subscribe)
|
|
200
|
+
eventData.unsubscribeTimeoutId = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
201
|
+
return __generator(this, function (_a) {
|
|
202
|
+
if (this.socket && this.socket.readyState === isomorphic_ws_1["default"].OPEN) {
|
|
198
203
|
this.dataCall("unsubscribe", { notify: event });
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
// socket is closed so we don't send unsubscribe and no grace period delete right away
|
|
206
|
-
_this.events["delete"](event);
|
|
207
|
-
}
|
|
204
|
+
}
|
|
205
|
+
this.events["delete"](event);
|
|
206
|
+
return [2 /*return*/];
|
|
207
|
+
});
|
|
208
|
+
}); }, _this.unsubscribeSuspense);
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
211
|
_this.socket && _this.socket.removeEventListener("message", onMessage);
|
|
@@ -258,25 +259,21 @@ var WSRPC = /** @class */ (function () {
|
|
|
258
259
|
var onMessage = function (msgEvent) {
|
|
259
260
|
if (typeof msgEvent.data === "string") {
|
|
260
261
|
var data = (0, parse_json_1.parseJSON)(msgEvent.data);
|
|
261
|
-
|
|
262
|
+
if (data.error && data.error.message) {
|
|
263
|
+
return reject(new Error(data.error.message));
|
|
264
|
+
}
|
|
262
265
|
if (Array.isArray(data) && data.length > 0 && data[0].id === id) {
|
|
263
266
|
//@ts-ignore
|
|
264
|
-
resolve(data);
|
|
265
|
-
valid = true;
|
|
267
|
+
return resolve(data);
|
|
266
268
|
}
|
|
267
|
-
|
|
268
|
-
resolve(data);
|
|
269
|
-
valid = true;
|
|
269
|
+
if (data.id === id) {
|
|
270
|
+
return resolve(data);
|
|
270
271
|
}
|
|
271
|
-
|
|
272
|
+
if (data.id === null && id === 0) {
|
|
272
273
|
// special case with xswd sending first call will return null id
|
|
273
|
-
resolve(data);
|
|
274
|
-
valid = true;
|
|
275
|
-
}
|
|
276
|
-
if (valid) {
|
|
277
|
-
clearTimeout(timeoutId);
|
|
278
|
-
_this.socket && _this.socket.removeEventListener("message", onMessage);
|
|
274
|
+
return resolve(data);
|
|
279
275
|
}
|
|
276
|
+
reject(new Error("invalid data"));
|
|
280
277
|
}
|
|
281
278
|
};
|
|
282
279
|
_this.socket.addEventListener("message", onMessage);
|
package/dist/cjs/wallet/rpc.js
CHANGED
|
@@ -70,6 +70,12 @@ var RPC = /** @class */ (function (_super) {
|
|
|
70
70
|
RPC.prototype.getTransaction = function (hash) {
|
|
71
71
|
return this.request(types_1.RPCMethod.GetTransaction, { hash: hash });
|
|
72
72
|
};
|
|
73
|
+
RPC.prototype.searchTransaction = function (hash) {
|
|
74
|
+
return this.request(types_1.RPCMethod.SearchTransaction, { hash: hash });
|
|
75
|
+
};
|
|
76
|
+
RPC.prototype.dumpTransaction = function (hash) {
|
|
77
|
+
return this.request(types_1.RPCMethod.DumpTransaction, { hash: hash });
|
|
78
|
+
};
|
|
73
79
|
RPC.prototype.buildTransaction = function (params) {
|
|
74
80
|
return this.request(types_1.RPCMethod.BuildTransaction, params);
|
|
75
81
|
};
|
package/dist/cjs/wallet/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.__esModule = true;
|
|
3
|
-
exports.
|
|
3
|
+
exports.RPCEvent = exports.RPCMethod = exports.ElementType = exports.ValueType = exports.TxRole = void 0;
|
|
4
4
|
var TxRole;
|
|
5
5
|
(function (TxRole) {
|
|
6
6
|
TxRole["Sender"] = "sender";
|
|
@@ -40,11 +40,13 @@ var RPCMethod;
|
|
|
40
40
|
RPCMethod["GetAssets"] = "get_assets";
|
|
41
41
|
RPCMethod["GetAsset"] = "get_asset";
|
|
42
42
|
RPCMethod["GetTransaction"] = "get_transaction";
|
|
43
|
+
RPCMethod["SearchTransaction"] = "search_transaction";
|
|
44
|
+
RPCMethod["DumpTransaction"] = "dump_transaction";
|
|
43
45
|
RPCMethod["BuildTransaction"] = "build_transaction";
|
|
44
46
|
RPCMethod["BuildTransactionOffline"] = "build_transaction_offline";
|
|
45
47
|
RPCMethod["BuildUnsignedTransaction"] = "build_unsigned_transaction";
|
|
46
|
-
RPCMethod["SignUnsignedTransaction"] = "sign_unsigned_transaction";
|
|
47
48
|
RPCMethod["FinalizeUnsignedTransaction"] = "finalize_unsigned_transaction";
|
|
49
|
+
RPCMethod["SignUnsignedTransaction"] = "sign_unsigned_transaction";
|
|
48
50
|
RPCMethod["ClearTxCache"] = "clear_tx_cache";
|
|
49
51
|
RPCMethod["ListTransactions"] = "list_transactions";
|
|
50
52
|
RPCMethod["IsOnline"] = "is_online";
|
|
@@ -76,9 +78,3 @@ var RPCEvent;
|
|
|
76
78
|
RPCEvent["Online"] = "online";
|
|
77
79
|
RPCEvent["Offline"] = "offline";
|
|
78
80
|
})(RPCEvent = exports.RPCEvent || (exports.RPCEvent = {}));
|
|
79
|
-
var Permission;
|
|
80
|
-
(function (Permission) {
|
|
81
|
-
Permission[Permission["Ask"] = 0] = "Ask";
|
|
82
|
-
Permission[Permission["AcceptAlways"] = 1] = "AcceptAlways";
|
|
83
|
-
Permission[Permission["DenyAlways"] = 2] = "DenyAlways";
|
|
84
|
-
})(Permission = exports.Permission || (exports.Permission = {}));
|
|
@@ -94,6 +94,12 @@ var WalletMethods = /** @class */ (function () {
|
|
|
94
94
|
WalletMethods.prototype.getTransaction = function (hash) {
|
|
95
95
|
return this.dataCall(types_1.RPCMethod.GetTransaction, { hash: hash });
|
|
96
96
|
};
|
|
97
|
+
WalletMethods.prototype.searchTransaction = function (hash) {
|
|
98
|
+
return this.dataCall(types_1.RPCMethod.SearchTransaction, { hash: hash });
|
|
99
|
+
};
|
|
100
|
+
WalletMethods.prototype.dumpTransaction = function (hash) {
|
|
101
|
+
return this.dataCall(types_1.RPCMethod.DumpTransaction, { hash: hash });
|
|
102
|
+
};
|
|
97
103
|
WalletMethods.prototype.buildTransaction = function (params) {
|
|
98
104
|
return this.dataCall(types_1.RPCMethod.BuildTransaction, params);
|
|
99
105
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.App = void 0;
|
|
7
|
+
var qrcode_1 = __importDefault(require("qrcode"));
|
|
8
|
+
var App = /** @class */ (function () {
|
|
9
|
+
function App(relayer) {
|
|
10
|
+
var _this = this;
|
|
11
|
+
this.relayer = relayer;
|
|
12
|
+
this.element = document.createElement("div");
|
|
13
|
+
this.element.classList.add("xelis-xswd-relayer");
|
|
14
|
+
this.contentElement = document.createElement("div");
|
|
15
|
+
this.contentElement.classList.add("xelis-xswd-relayer-content");
|
|
16
|
+
this.element.appendChild(this.contentElement);
|
|
17
|
+
this.loadingElement = document.createElement("div");
|
|
18
|
+
this.loadingElement.innerHTML = "\n <svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20.0001 12C20.0001 13.3811 19.6425 14.7386 18.9623 15.9405C18.282 17.1424 17.3022 18.1477 16.1182 18.8587C14.9341 19.5696 13.5862 19.9619 12.2056 19.9974C10.825 20.0328 9.45873 19.7103 8.23975 19.0612\" stroke=\"currentColor\" stroke-width=\"3.55556\" stroke-linecap=\"round\"/>\n </svg>\n ";
|
|
19
|
+
this.loadingElement.classList.add("xelis-xswd-relayer-loading");
|
|
20
|
+
this.errElement = document.createElement("div");
|
|
21
|
+
this.errElement.classList.add("xelis-xswd-relayer-error");
|
|
22
|
+
this.qrCodeElement = document.createElement("div");
|
|
23
|
+
this.qrCodeElement.classList.add("xelis-xswd-relayer-qrcode");
|
|
24
|
+
this.qrCodeElement.innerHTML = "\n <div>XSWD Relayer</div>\n <canvas></canvas>\n ";
|
|
25
|
+
this.element.addEventListener("click", function (e) {
|
|
26
|
+
// close the app if clicking outside
|
|
27
|
+
if (_this.element.isEqualNode(e.target)) {
|
|
28
|
+
_this.relayer.close();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.relayer.props.parent.appendChild(this.element);
|
|
32
|
+
this.setLoading();
|
|
33
|
+
}
|
|
34
|
+
App.prototype.clear = function () {
|
|
35
|
+
this.loadingElement.remove();
|
|
36
|
+
this.errElement.remove();
|
|
37
|
+
this.qrCodeElement.remove();
|
|
38
|
+
};
|
|
39
|
+
App.prototype.setError = function (msg) {
|
|
40
|
+
this.clear();
|
|
41
|
+
this.errElement.innerHTML = "error: ".concat(msg);
|
|
42
|
+
this.contentElement.appendChild(this.errElement);
|
|
43
|
+
};
|
|
44
|
+
App.prototype.setLoading = function () {
|
|
45
|
+
this.clear();
|
|
46
|
+
this.contentElement.appendChild(this.loadingElement);
|
|
47
|
+
};
|
|
48
|
+
App.prototype.setQRCode = function (channelId) {
|
|
49
|
+
this.clear();
|
|
50
|
+
var canvas = this.qrCodeElement.querySelector("canvas");
|
|
51
|
+
var qrCodeData = JSON.stringify({
|
|
52
|
+
inner: {},
|
|
53
|
+
channel_id: channelId,
|
|
54
|
+
relayer: this.relayer.props.url,
|
|
55
|
+
encryption_mode: this.relayer.props.encryption_mode
|
|
56
|
+
});
|
|
57
|
+
qrcode_1["default"].toCanvas(canvas, qrCodeData);
|
|
58
|
+
this.contentElement.appendChild(this.qrCodeElement);
|
|
59
|
+
};
|
|
60
|
+
return App;
|
|
61
|
+
}());
|
|
62
|
+
exports.App = App;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.xelis-xswd-relayer {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
bottom: 0;
|
|
6
|
+
right: 0;
|
|
7
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
8
|
+
backdrop-filter: blur(10px);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.xelis-xswd-relayer-content {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 50%;
|
|
14
|
+
left: 50%;
|
|
15
|
+
translate: -50% -50%;
|
|
16
|
+
background-color: aquamarine;
|
|
17
|
+
filter: drop-shadow(0px 0px 25px black);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.xelis-xswd-relayer-error {}
|
|
21
|
+
|
|
22
|
+
.xelis-xswd-relayer-loading {
|
|
23
|
+
width: 50px;
|
|
24
|
+
height: 50px;
|
|
25
|
+
color: black;
|
|
26
|
+
animation: xelis-xswd-relayer-loading-animation .75s infinite;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@keyframes xelis-xswd-relayer-loading-animation {
|
|
30
|
+
100% {
|
|
31
|
+
rotate: 360deg;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.xelis-xswd-relayer-qrcode {}
|
|
36
|
+
|
|
37
|
+
.xelis-xswd-relayer-qrcode canvas {}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
var app_1 = require("./app");
|
|
4
|
+
var Relayer = /** @class */ (function () {
|
|
5
|
+
function Relayer(props) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
this.onOpen = function (e) {
|
|
8
|
+
_this.message_timeout = window.setTimeout(function () {
|
|
9
|
+
_this.app.setError("timeout occured (did not receive any message)");
|
|
10
|
+
}, 3000);
|
|
11
|
+
};
|
|
12
|
+
this.onMessage = function (e) {
|
|
13
|
+
window.clearTimeout(_this.message_timeout);
|
|
14
|
+
try {
|
|
15
|
+
console.log(e);
|
|
16
|
+
var data = JSON.parse(e.data);
|
|
17
|
+
if (data.channel_id) {
|
|
18
|
+
_this.app.setQRCode(data.channel_id);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
_this.app.setError("channel id not found");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
_this.app.setError("invalid data format");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
this.onError = function (e) {
|
|
29
|
+
_this.app.setError("connection failed");
|
|
30
|
+
};
|
|
31
|
+
this.onClose = function (e) {
|
|
32
|
+
_this.app.setError("connection closed");
|
|
33
|
+
};
|
|
34
|
+
this.props = props;
|
|
35
|
+
this.app = new app_1.App(this);
|
|
36
|
+
this.ws = new WebSocket(this.props.url);
|
|
37
|
+
this.ws.addEventListener("open", this.onOpen);
|
|
38
|
+
this.ws.addEventListener("message", this.onMessage);
|
|
39
|
+
this.ws.addEventListener("error", this.onError);
|
|
40
|
+
this.ws.addEventListener("close", this.onClose);
|
|
41
|
+
}
|
|
42
|
+
Relayer.prototype.close = function () {
|
|
43
|
+
this.ws.close();
|
|
44
|
+
this.app.element.remove();
|
|
45
|
+
};
|
|
46
|
+
return Relayer;
|
|
47
|
+
}());
|
|
48
|
+
exports["default"] = Relayer;
|
package/dist/cjs/xswd/types.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
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 = {}));
|
package/dist/esm/daemon/rpc.js
CHANGED
|
@@ -209,6 +209,12 @@ var RPC = /** @class */ (function (_super) {
|
|
|
209
209
|
RPC.prototype.getContractBalanceAtTopoheight = function (params) {
|
|
210
210
|
return this.request(RPCMethod.GetContractBalanceAtTopoheight, params);
|
|
211
211
|
};
|
|
212
|
+
RPC.prototype.getContractAssets = function (params) {
|
|
213
|
+
return this.request(RPCMethod.GetContractAssets, params);
|
|
214
|
+
};
|
|
215
|
+
RPC.prototype.getP2PBlockPropagation = function (params) {
|
|
216
|
+
return this.request(RPCMethod.GetP2PBlockPropagation, params);
|
|
217
|
+
};
|
|
212
218
|
RPC.prototype.getBlockTemplate = function (address) {
|
|
213
219
|
return this.request(RPCMethod.GetBlockTemplate, { address: address });
|
|
214
220
|
};
|
package/dist/esm/daemon/types.js
CHANGED
|
@@ -39,8 +39,8 @@ export var RPCMethod;
|
|
|
39
39
|
RPCMethod["GetAsset"] = "get_asset";
|
|
40
40
|
RPCMethod["GetAssets"] = "get_assets";
|
|
41
41
|
RPCMethod["CountAssets"] = "count_assets";
|
|
42
|
-
RPCMethod["CountTransactions"] = "count_transactions";
|
|
43
42
|
RPCMethod["CountAccounts"] = "count_accounts";
|
|
43
|
+
RPCMethod["CountTransactions"] = "count_transactions";
|
|
44
44
|
RPCMethod["CountContracts"] = "count_contracts";
|
|
45
45
|
RPCMethod["SubmitTransaction"] = "submit_transaction";
|
|
46
46
|
RPCMethod["GetTransactionExecutor"] = "get_transaction_executor";
|
|
@@ -50,8 +50,8 @@ export var RPCMethod;
|
|
|
50
50
|
RPCMethod["P2PStatus"] = "p2p_status";
|
|
51
51
|
RPCMethod["GetPeers"] = "get_peers";
|
|
52
52
|
RPCMethod["GetMempool"] = "get_mempool";
|
|
53
|
-
RPCMethod["GetMempoolCache"] = "get_mempool_cache";
|
|
54
53
|
RPCMethod["GetMempoolSummary"] = "get_mempool_summary";
|
|
54
|
+
RPCMethod["GetMempoolCache"] = "get_mempool_cache";
|
|
55
55
|
RPCMethod["GetEstimatedFeeRates"] = "get_estimated_fee_rates";
|
|
56
56
|
RPCMethod["GetDAGOrder"] = "get_dag_order";
|
|
57
57
|
RPCMethod["GetBlocksRangeByTopoheight"] = "get_blocks_range_by_topoheight";
|
|
@@ -76,6 +76,8 @@ export var RPCMethod;
|
|
|
76
76
|
RPCMethod["GetContractDataAtTopoheight"] = "get_contract_data_at_topoheight";
|
|
77
77
|
RPCMethod["GetContractBalance"] = "get_contract_balance";
|
|
78
78
|
RPCMethod["GetContractBalanceAtTopoheight"] = "get_contract_balance_at_topoheight";
|
|
79
|
+
RPCMethod["GetContractAssets"] = "get_contract_assets";
|
|
80
|
+
RPCMethod["GetP2PBlockPropagation"] = "get_p2p_block_propagation";
|
|
79
81
|
RPCMethod["GetBlockTemplate"] = "get_block_template";
|
|
80
82
|
RPCMethod["GetMinerWork"] = "get_miner_work";
|
|
81
83
|
RPCMethod["SubmitBlock"] = "submit_block";
|
|
@@ -91,12 +93,14 @@ export var RPCEvent;
|
|
|
91
93
|
RPCEvent["TransactionAddedInMempool"] = "transaction_added_in_mempool";
|
|
92
94
|
RPCEvent["TransactionExecuted"] = "transaction_executed";
|
|
93
95
|
RPCEvent["InvokeContract"] = "invoke_contract";
|
|
96
|
+
RPCEvent["ContractTransfer"] = "contract_transfer";
|
|
97
|
+
RPCEvent["ContractEvent"] = "contract_event";
|
|
94
98
|
RPCEvent["DeployContract"] = "deploy_contract";
|
|
95
99
|
RPCEvent["NewAsset"] = "new_asset";
|
|
96
100
|
RPCEvent["PeerConnected"] = "peer_connected";
|
|
97
101
|
RPCEvent["PeerDisconnected"] = "peer_disconnected";
|
|
98
|
-
RPCEvent["PeerStateUpdated"] = "peer_state_updated";
|
|
99
102
|
RPCEvent["PeerPeerListUpdated"] = "peer_peer_list_updated";
|
|
103
|
+
RPCEvent["PeerStateUpdated"] = "peer_state_updated";
|
|
100
104
|
RPCEvent["PeerPeerDisconnected"] = "peer_peer_disconnected";
|
|
101
105
|
RPCEvent["NewBlockTemplate"] = "new_block_template";
|
|
102
106
|
})(RPCEvent || (RPCEvent = {}));
|
|
@@ -52,6 +52,14 @@ var DaemonMethods = /** @class */ (function () {
|
|
|
52
52
|
var _a;
|
|
53
53
|
return this.ws.listenEvent((_a = {}, _a[this.prefix + RPCEvent.InvokeContract] = { contract: contract }, _a), onData);
|
|
54
54
|
};
|
|
55
|
+
DaemonMethods.prototype.onContractTransfer = function (address, onData) {
|
|
56
|
+
var _a;
|
|
57
|
+
return this.ws.listenEvent((_a = {}, _a[this.prefix + RPCEvent.ContractTransfer] = { address: address }, _a), onData);
|
|
58
|
+
};
|
|
59
|
+
DaemonMethods.prototype.onContractEvent = function (contract, id, onData) {
|
|
60
|
+
var _a;
|
|
61
|
+
return this.ws.listenEvent((_a = {}, _a[this.prefix + RPCEvent.ContractEvent] = { contract: contract, id: id }, _a), onData);
|
|
62
|
+
};
|
|
55
63
|
DaemonMethods.prototype.onDeployContract = function (onData) {
|
|
56
64
|
return this.ws.listenEvent(this.prefix + RPCEvent.DeployContract, onData);
|
|
57
65
|
};
|
|
@@ -265,6 +273,12 @@ var DaemonMethods = /** @class */ (function () {
|
|
|
265
273
|
DaemonMethods.prototype.getContractBalanceAtTopoheight = function (params) {
|
|
266
274
|
return this.dataCall(RPCMethod.GetContractBalanceAtTopoheight, params);
|
|
267
275
|
};
|
|
276
|
+
DaemonMethods.prototype.getContractAssets = function (params) {
|
|
277
|
+
return this.dataCall(RPCMethod.GetContractAssets, params);
|
|
278
|
+
};
|
|
279
|
+
DaemonMethods.prototype.getP2PBlockPropagation = function (params) {
|
|
280
|
+
return this.dataCall(RPCMethod.GetP2PBlockPropagation, params);
|
|
281
|
+
};
|
|
268
282
|
DaemonMethods.prototype.getBlockTemplate = function (address) {
|
|
269
283
|
return this.dataCall(RPCMethod.GetBlockTemplate, { address: address });
|
|
270
284
|
};
|
|
@@ -127,7 +127,7 @@ var WSRPC = /** @class */ (function () {
|
|
|
127
127
|
};
|
|
128
128
|
WSRPC.prototype.listenEvent = function (event, onData) {
|
|
129
129
|
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
-
var onMessage, eventData, idRefObject, _a, err, _, closeListen;
|
|
130
|
+
var onMessage, eventData, idRefObject, _a, err, _, eventData_1, closeListen;
|
|
131
131
|
var _this = this;
|
|
132
132
|
return __generator(this, function (_b) {
|
|
133
133
|
switch (_b.label) {
|
|
@@ -161,6 +161,9 @@ var WSRPC = /** @class */ (function () {
|
|
|
161
161
|
eventData.listeners.push(onMessage);
|
|
162
162
|
return [3 /*break*/, 3];
|
|
163
163
|
case 1:
|
|
164
|
+
// important if multiple listenEvent are called without await at least we store listener before getting id
|
|
165
|
+
// avoid trying to subscribe the same event multiple times
|
|
166
|
+
this.events.set(event, { listeners: [onMessage] });
|
|
164
167
|
idRefObject = {};
|
|
165
168
|
return [4 /*yield*/, to(this.dataCall("subscribe", { notify: event }, idRefObject))];
|
|
166
169
|
case 2:
|
|
@@ -169,7 +172,9 @@ var WSRPC = /** @class */ (function () {
|
|
|
169
172
|
this.clearEvent(event);
|
|
170
173
|
return [2 /*return*/, Promise.reject(err)];
|
|
171
174
|
}
|
|
172
|
-
this.events.
|
|
175
|
+
eventData_1 = this.events.get(event);
|
|
176
|
+
if (eventData_1)
|
|
177
|
+
eventData_1.id = idRefObject.id;
|
|
173
178
|
_b.label = 3;
|
|
174
179
|
case 3:
|
|
175
180
|
this.socket && this.socket.addEventListener("message", onMessage);
|
|
@@ -185,20 +190,16 @@ var WSRPC = /** @class */ (function () {
|
|
|
185
190
|
}
|
|
186
191
|
// no more listener so we unsubscribe from daemon websocket if socket still open
|
|
187
192
|
if (listeners.length === 0) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
// we use a grace period to unsubscribe (mostly because of react useEffect and avoid unecessary subscribe)
|
|
194
|
+
eventData.unsubscribeTimeoutId = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
195
|
+
return __generator(this, function (_a) {
|
|
196
|
+
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
192
197
|
this.dataCall("unsubscribe", { notify: event });
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
// socket is closed so we don't send unsubscribe and no grace period delete right away
|
|
200
|
-
_this.events["delete"](event);
|
|
201
|
-
}
|
|
198
|
+
}
|
|
199
|
+
this.events["delete"](event);
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
});
|
|
202
|
+
}); }, _this.unsubscribeSuspense);
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
_this.socket && _this.socket.removeEventListener("message", onMessage);
|
|
@@ -252,25 +253,21 @@ var WSRPC = /** @class */ (function () {
|
|
|
252
253
|
var onMessage = function (msgEvent) {
|
|
253
254
|
if (typeof msgEvent.data === "string") {
|
|
254
255
|
var data = parseJSON(msgEvent.data);
|
|
255
|
-
|
|
256
|
+
if (data.error && data.error.message) {
|
|
257
|
+
return reject(new Error(data.error.message));
|
|
258
|
+
}
|
|
256
259
|
if (Array.isArray(data) && data.length > 0 && data[0].id === id) {
|
|
257
260
|
//@ts-ignore
|
|
258
|
-
resolve(data);
|
|
259
|
-
valid = true;
|
|
261
|
+
return resolve(data);
|
|
260
262
|
}
|
|
261
|
-
|
|
262
|
-
resolve(data);
|
|
263
|
-
valid = true;
|
|
263
|
+
if (data.id === id) {
|
|
264
|
+
return resolve(data);
|
|
264
265
|
}
|
|
265
|
-
|
|
266
|
+
if (data.id === null && id === 0) {
|
|
266
267
|
// special case with xswd sending first call will return null id
|
|
267
|
-
resolve(data);
|
|
268
|
-
valid = true;
|
|
269
|
-
}
|
|
270
|
-
if (valid) {
|
|
271
|
-
clearTimeout(timeoutId);
|
|
272
|
-
_this.socket && _this.socket.removeEventListener("message", onMessage);
|
|
268
|
+
return resolve(data);
|
|
273
269
|
}
|
|
270
|
+
reject(new Error("invalid data"));
|
|
274
271
|
}
|
|
275
272
|
};
|
|
276
273
|
_this.socket.addEventListener("message", onMessage);
|
package/dist/esm/wallet/rpc.js
CHANGED
|
@@ -67,6 +67,12 @@ var RPC = /** @class */ (function (_super) {
|
|
|
67
67
|
RPC.prototype.getTransaction = function (hash) {
|
|
68
68
|
return this.request(RPCMethod.GetTransaction, { hash: hash });
|
|
69
69
|
};
|
|
70
|
+
RPC.prototype.searchTransaction = function (hash) {
|
|
71
|
+
return this.request(RPCMethod.SearchTransaction, { hash: hash });
|
|
72
|
+
};
|
|
73
|
+
RPC.prototype.dumpTransaction = function (hash) {
|
|
74
|
+
return this.request(RPCMethod.DumpTransaction, { hash: hash });
|
|
75
|
+
};
|
|
70
76
|
RPC.prototype.buildTransaction = function (params) {
|
|
71
77
|
return this.request(RPCMethod.BuildTransaction, params);
|
|
72
78
|
};
|
package/dist/esm/wallet/types.js
CHANGED
|
@@ -37,11 +37,13 @@ export var RPCMethod;
|
|
|
37
37
|
RPCMethod["GetAssets"] = "get_assets";
|
|
38
38
|
RPCMethod["GetAsset"] = "get_asset";
|
|
39
39
|
RPCMethod["GetTransaction"] = "get_transaction";
|
|
40
|
+
RPCMethod["SearchTransaction"] = "search_transaction";
|
|
41
|
+
RPCMethod["DumpTransaction"] = "dump_transaction";
|
|
40
42
|
RPCMethod["BuildTransaction"] = "build_transaction";
|
|
41
43
|
RPCMethod["BuildTransactionOffline"] = "build_transaction_offline";
|
|
42
44
|
RPCMethod["BuildUnsignedTransaction"] = "build_unsigned_transaction";
|
|
43
|
-
RPCMethod["SignUnsignedTransaction"] = "sign_unsigned_transaction";
|
|
44
45
|
RPCMethod["FinalizeUnsignedTransaction"] = "finalize_unsigned_transaction";
|
|
46
|
+
RPCMethod["SignUnsignedTransaction"] = "sign_unsigned_transaction";
|
|
45
47
|
RPCMethod["ClearTxCache"] = "clear_tx_cache";
|
|
46
48
|
RPCMethod["ListTransactions"] = "list_transactions";
|
|
47
49
|
RPCMethod["IsOnline"] = "is_online";
|
|
@@ -73,9 +75,3 @@ export var RPCEvent;
|
|
|
73
75
|
RPCEvent["Online"] = "online";
|
|
74
76
|
RPCEvent["Offline"] = "offline";
|
|
75
77
|
})(RPCEvent || (RPCEvent = {}));
|
|
76
|
-
export var Permission;
|
|
77
|
-
(function (Permission) {
|
|
78
|
-
Permission[Permission["Ask"] = 0] = "Ask";
|
|
79
|
-
Permission[Permission["AcceptAlways"] = 1] = "AcceptAlways";
|
|
80
|
-
Permission[Permission["DenyAlways"] = 2] = "DenyAlways";
|
|
81
|
-
})(Permission || (Permission = {}));
|
|
@@ -91,6 +91,12 @@ var WalletMethods = /** @class */ (function () {
|
|
|
91
91
|
WalletMethods.prototype.getTransaction = function (hash) {
|
|
92
92
|
return this.dataCall(RPCMethod.GetTransaction, { hash: hash });
|
|
93
93
|
};
|
|
94
|
+
WalletMethods.prototype.searchTransaction = function (hash) {
|
|
95
|
+
return this.dataCall(RPCMethod.SearchTransaction, { hash: hash });
|
|
96
|
+
};
|
|
97
|
+
WalletMethods.prototype.dumpTransaction = function (hash) {
|
|
98
|
+
return this.dataCall(RPCMethod.DumpTransaction, { hash: hash });
|
|
99
|
+
};
|
|
94
100
|
WalletMethods.prototype.buildTransaction = function (params) {
|
|
95
101
|
return this.dataCall(RPCMethod.BuildTransaction, params);
|
|
96
102
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import QRCode from 'qrcode';
|
|
2
|
+
var App = /** @class */ (function () {
|
|
3
|
+
function App(relayer) {
|
|
4
|
+
var _this = this;
|
|
5
|
+
this.relayer = relayer;
|
|
6
|
+
this.element = document.createElement("div");
|
|
7
|
+
this.element.classList.add("xelis-xswd-relayer");
|
|
8
|
+
this.contentElement = document.createElement("div");
|
|
9
|
+
this.contentElement.classList.add("xelis-xswd-relayer-content");
|
|
10
|
+
this.element.appendChild(this.contentElement);
|
|
11
|
+
this.loadingElement = document.createElement("div");
|
|
12
|
+
this.loadingElement.innerHTML = "\n <svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20.0001 12C20.0001 13.3811 19.6425 14.7386 18.9623 15.9405C18.282 17.1424 17.3022 18.1477 16.1182 18.8587C14.9341 19.5696 13.5862 19.9619 12.2056 19.9974C10.825 20.0328 9.45873 19.7103 8.23975 19.0612\" stroke=\"currentColor\" stroke-width=\"3.55556\" stroke-linecap=\"round\"/>\n </svg>\n ";
|
|
13
|
+
this.loadingElement.classList.add("xelis-xswd-relayer-loading");
|
|
14
|
+
this.errElement = document.createElement("div");
|
|
15
|
+
this.errElement.classList.add("xelis-xswd-relayer-error");
|
|
16
|
+
this.qrCodeElement = document.createElement("div");
|
|
17
|
+
this.qrCodeElement.classList.add("xelis-xswd-relayer-qrcode");
|
|
18
|
+
this.qrCodeElement.innerHTML = "\n <div>XSWD Relayer</div>\n <canvas></canvas>\n ";
|
|
19
|
+
this.element.addEventListener("click", function (e) {
|
|
20
|
+
// close the app if clicking outside
|
|
21
|
+
if (_this.element.isEqualNode(e.target)) {
|
|
22
|
+
_this.relayer.close();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
this.relayer.props.parent.appendChild(this.element);
|
|
26
|
+
this.setLoading();
|
|
27
|
+
}
|
|
28
|
+
App.prototype.clear = function () {
|
|
29
|
+
this.loadingElement.remove();
|
|
30
|
+
this.errElement.remove();
|
|
31
|
+
this.qrCodeElement.remove();
|
|
32
|
+
};
|
|
33
|
+
App.prototype.setError = function (msg) {
|
|
34
|
+
this.clear();
|
|
35
|
+
this.errElement.innerHTML = "error: ".concat(msg);
|
|
36
|
+
this.contentElement.appendChild(this.errElement);
|
|
37
|
+
};
|
|
38
|
+
App.prototype.setLoading = function () {
|
|
39
|
+
this.clear();
|
|
40
|
+
this.contentElement.appendChild(this.loadingElement);
|
|
41
|
+
};
|
|
42
|
+
App.prototype.setQRCode = function (channelId) {
|
|
43
|
+
this.clear();
|
|
44
|
+
var canvas = this.qrCodeElement.querySelector("canvas");
|
|
45
|
+
var qrCodeData = JSON.stringify({
|
|
46
|
+
inner: {},
|
|
47
|
+
channel_id: channelId,
|
|
48
|
+
relayer: this.relayer.props.url,
|
|
49
|
+
encryption_mode: this.relayer.props.encryption_mode
|
|
50
|
+
});
|
|
51
|
+
QRCode.toCanvas(canvas, qrCodeData);
|
|
52
|
+
this.contentElement.appendChild(this.qrCodeElement);
|
|
53
|
+
};
|
|
54
|
+
return App;
|
|
55
|
+
}());
|
|
56
|
+
export { App };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.xelis-xswd-relayer {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
bottom: 0;
|
|
6
|
+
right: 0;
|
|
7
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
8
|
+
backdrop-filter: blur(10px);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.xelis-xswd-relayer-content {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 50%;
|
|
14
|
+
left: 50%;
|
|
15
|
+
translate: -50% -50%;
|
|
16
|
+
background-color: aquamarine;
|
|
17
|
+
filter: drop-shadow(0px 0px 25px black);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.xelis-xswd-relayer-error {}
|
|
21
|
+
|
|
22
|
+
.xelis-xswd-relayer-loading {
|
|
23
|
+
width: 50px;
|
|
24
|
+
height: 50px;
|
|
25
|
+
color: black;
|
|
26
|
+
animation: xelis-xswd-relayer-loading-animation .75s infinite;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@keyframes xelis-xswd-relayer-loading-animation {
|
|
30
|
+
100% {
|
|
31
|
+
rotate: 360deg;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.xelis-xswd-relayer-qrcode {}
|
|
36
|
+
|
|
37
|
+
.xelis-xswd-relayer-qrcode canvas {}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { App } from './app.js';
|
|
2
|
+
var Relayer = /** @class */ (function () {
|
|
3
|
+
function Relayer(props) {
|
|
4
|
+
var _this = this;
|
|
5
|
+
this.onOpen = function (e) {
|
|
6
|
+
_this.message_timeout = window.setTimeout(function () {
|
|
7
|
+
_this.app.setError("timeout occured (did not receive any message)");
|
|
8
|
+
}, 3000);
|
|
9
|
+
};
|
|
10
|
+
this.onMessage = function (e) {
|
|
11
|
+
window.clearTimeout(_this.message_timeout);
|
|
12
|
+
try {
|
|
13
|
+
console.log(e);
|
|
14
|
+
var data = JSON.parse(e.data);
|
|
15
|
+
if (data.channel_id) {
|
|
16
|
+
_this.app.setQRCode(data.channel_id);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
_this.app.setError("channel id not found");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
_this.app.setError("invalid data format");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this.onError = function (e) {
|
|
27
|
+
_this.app.setError("connection failed");
|
|
28
|
+
};
|
|
29
|
+
this.onClose = function (e) {
|
|
30
|
+
_this.app.setError("connection closed");
|
|
31
|
+
};
|
|
32
|
+
this.props = props;
|
|
33
|
+
this.app = new App(this);
|
|
34
|
+
this.ws = new WebSocket(this.props.url);
|
|
35
|
+
this.ws.addEventListener("open", this.onOpen);
|
|
36
|
+
this.ws.addEventListener("message", this.onMessage);
|
|
37
|
+
this.ws.addEventListener("error", this.onError);
|
|
38
|
+
this.ws.addEventListener("close", this.onClose);
|
|
39
|
+
}
|
|
40
|
+
Relayer.prototype.close = function () {
|
|
41
|
+
this.ws.close();
|
|
42
|
+
this.app.element.remove();
|
|
43
|
+
};
|
|
44
|
+
return Relayer;
|
|
45
|
+
}());
|
|
46
|
+
export default Relayer;
|
package/dist/esm/xswd/types.js
CHANGED
|
@@ -64,6 +64,8 @@ export declare class RPC extends HttpRPC {
|
|
|
64
64
|
getContractDataAtTopoheight(params: types.GetContractDataAtTopoheightParams): Promise<unknown>;
|
|
65
65
|
getContractBalance(params: types.GetContractBalanceParams): Promise<types.GetContractBalanceResult>;
|
|
66
66
|
getContractBalanceAtTopoheight(params: types.GetContractBalanceAtTopoheightParams): Promise<types.GetContractBalanceAtTopoheightResult>;
|
|
67
|
+
getContractAssets(params: types.GetContractBalanceParams): Promise<string[]>;
|
|
68
|
+
getP2PBlockPropagation(params: types.GetP2pBlockPropagationParams): Promise<types.P2pBlockPropagationResult>;
|
|
67
69
|
getBlockTemplate(address: string): Promise<types.GetBlockTemplateResult>;
|
|
68
70
|
getMinerWork(params: types.GetMinerWorkParams): Promise<types.GetMinerWorkResult>;
|
|
69
71
|
submitBlock(params: types.SubmitBlockParams): Promise<boolean>;
|
|
@@ -107,9 +107,18 @@ export interface HeightRangeParams {
|
|
|
107
107
|
export interface RPCEventResult {
|
|
108
108
|
event: string;
|
|
109
109
|
}
|
|
110
|
-
export
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
export interface TimedDirection {
|
|
111
|
+
in?: {
|
|
112
|
+
received_at: number;
|
|
113
|
+
};
|
|
114
|
+
out?: {
|
|
115
|
+
sent_at: number;
|
|
116
|
+
};
|
|
117
|
+
both?: {
|
|
118
|
+
received_at: number;
|
|
119
|
+
sent_at: number;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
113
122
|
export interface Peer {
|
|
114
123
|
id: number;
|
|
115
124
|
addr: string;
|
|
@@ -121,7 +130,9 @@ export interface Peer {
|
|
|
121
130
|
height: number;
|
|
122
131
|
last_ping: number;
|
|
123
132
|
pruned_topoheight?: number;
|
|
124
|
-
peers:
|
|
133
|
+
peers: {
|
|
134
|
+
[addr: string]: TimedDirection;
|
|
135
|
+
};
|
|
125
136
|
cumulative_difficulty: string;
|
|
126
137
|
connected_on: number;
|
|
127
138
|
}
|
|
@@ -531,6 +542,27 @@ export interface NewContract {
|
|
|
531
542
|
block_hash: string;
|
|
532
543
|
topoheight: number;
|
|
533
544
|
}
|
|
545
|
+
export interface GetP2pBlockPropagationParams {
|
|
546
|
+
hash: string;
|
|
547
|
+
outgoing: boolean;
|
|
548
|
+
incoming: boolean;
|
|
549
|
+
}
|
|
550
|
+
export interface P2pBlockPropagationResult {
|
|
551
|
+
peers: {
|
|
552
|
+
[id: number]: TimedDirection;
|
|
553
|
+
};
|
|
554
|
+
first_seen?: number;
|
|
555
|
+
processing_at?: number;
|
|
556
|
+
}
|
|
557
|
+
export interface ContractTransfer {
|
|
558
|
+
asset: string;
|
|
559
|
+
amount: number;
|
|
560
|
+
block_hash: string;
|
|
561
|
+
topoheight: number;
|
|
562
|
+
}
|
|
563
|
+
export interface ContractEvent {
|
|
564
|
+
data: any;
|
|
565
|
+
}
|
|
534
566
|
export declare enum RPCMethod {
|
|
535
567
|
GetVersion = "get_version",
|
|
536
568
|
GetHeight = "get_height",
|
|
@@ -558,8 +590,8 @@ export declare enum RPCMethod {
|
|
|
558
590
|
GetAsset = "get_asset",
|
|
559
591
|
GetAssets = "get_assets",
|
|
560
592
|
CountAssets = "count_assets",
|
|
561
|
-
CountTransactions = "count_transactions",
|
|
562
593
|
CountAccounts = "count_accounts",
|
|
594
|
+
CountTransactions = "count_transactions",
|
|
563
595
|
CountContracts = "count_contracts",
|
|
564
596
|
SubmitTransaction = "submit_transaction",
|
|
565
597
|
GetTransactionExecutor = "get_transaction_executor",
|
|
@@ -569,8 +601,8 @@ export declare enum RPCMethod {
|
|
|
569
601
|
P2PStatus = "p2p_status",
|
|
570
602
|
GetPeers = "get_peers",
|
|
571
603
|
GetMempool = "get_mempool",
|
|
572
|
-
GetMempoolCache = "get_mempool_cache",
|
|
573
604
|
GetMempoolSummary = "get_mempool_summary",
|
|
605
|
+
GetMempoolCache = "get_mempool_cache",
|
|
574
606
|
GetEstimatedFeeRates = "get_estimated_fee_rates",
|
|
575
607
|
GetDAGOrder = "get_dag_order",
|
|
576
608
|
GetBlocksRangeByTopoheight = "get_blocks_range_by_topoheight",
|
|
@@ -595,6 +627,8 @@ export declare enum RPCMethod {
|
|
|
595
627
|
GetContractDataAtTopoheight = "get_contract_data_at_topoheight",
|
|
596
628
|
GetContractBalance = "get_contract_balance",
|
|
597
629
|
GetContractBalanceAtTopoheight = "get_contract_balance_at_topoheight",
|
|
630
|
+
GetContractAssets = "get_contract_assets",
|
|
631
|
+
GetP2PBlockPropagation = "get_p2p_block_propagation",
|
|
598
632
|
GetBlockTemplate = "get_block_template",
|
|
599
633
|
GetMinerWork = "get_miner_work",
|
|
600
634
|
SubmitBlock = "submit_block"
|
|
@@ -609,12 +643,14 @@ export declare enum RPCEvent {
|
|
|
609
643
|
TransactionAddedInMempool = "transaction_added_in_mempool",
|
|
610
644
|
TransactionExecuted = "transaction_executed",
|
|
611
645
|
InvokeContract = "invoke_contract",
|
|
646
|
+
ContractTransfer = "contract_transfer",
|
|
647
|
+
ContractEvent = "contract_event",
|
|
612
648
|
DeployContract = "deploy_contract",
|
|
613
649
|
NewAsset = "new_asset",
|
|
614
650
|
PeerConnected = "peer_connected",
|
|
615
651
|
PeerDisconnected = "peer_disconnected",
|
|
616
|
-
PeerStateUpdated = "peer_state_updated",
|
|
617
652
|
PeerPeerListUpdated = "peer_peer_list_updated",
|
|
653
|
+
PeerStateUpdated = "peer_state_updated",
|
|
618
654
|
PeerPeerDisconnected = "peer_peer_disconnected",
|
|
619
655
|
NewBlockTemplate = "new_block_template"
|
|
620
656
|
}
|
|
@@ -15,6 +15,8 @@ export declare class DaemonMethods {
|
|
|
15
15
|
onTransactionAddedInMempool(onData: (msgEvent: MessageEvent, data?: types.MempoolTransactionSummary & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
16
16
|
onTransactionExecuted(onData: (msgEvent: MessageEvent, data?: types.TransactionExecuted & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
17
17
|
onInvokeContract(contract: string, onData: (msgEvent: MessageEvent, data?: types.InvokeContract & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
18
|
+
onContractTransfer(address: string, onData: (msgEvent: MessageEvent, data?: types.ContractTransfer & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
19
|
+
onContractEvent(contract: string, id: number, onData: (msgEvent: MessageEvent, data?: types.ContractEvent & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
18
20
|
onDeployContract(onData: (msgEvent: MessageEvent, data?: types.NewContract & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
19
21
|
onNewAsset(onData: (msgEvent: MessageEvent, data?: types.AssetWithData & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
20
22
|
onPeerConnected(onData: (msgEvent: MessageEvent, data?: types.Peer & types.RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
|
|
@@ -86,6 +88,8 @@ export declare class DaemonMethods {
|
|
|
86
88
|
getContractDataAtTopoheight(params: types.GetContractDataAtTopoheightParams): Promise<unknown>;
|
|
87
89
|
getContractBalance(params: types.GetContractBalanceParams): Promise<types.GetContractBalanceResult>;
|
|
88
90
|
getContractBalanceAtTopoheight(params: types.GetContractBalanceAtTopoheightParams): Promise<types.GetContractBalanceAtTopoheightResult>;
|
|
91
|
+
getContractAssets(params: types.GetContractBalanceParams): Promise<string[]>;
|
|
92
|
+
getP2PBlockPropagation(params: types.GetP2pBlockPropagationParams): Promise<types.P2pBlockPropagationResult>;
|
|
89
93
|
getBlockTemplate(address: string): Promise<string>;
|
|
90
94
|
getMinerWork(params: types.GetMinerWorkParams): Promise<types.GetMinerWorkResult>;
|
|
91
95
|
submitBlock(params: types.SubmitBlockParams): Promise<boolean>;
|
|
@@ -20,6 +20,8 @@ export declare class RPC extends HttpRPC {
|
|
|
20
20
|
}>;
|
|
21
21
|
getAsset(params: daemonTypes.GetAssetParams): Promise<types.Asset>;
|
|
22
22
|
getTransaction(hash: string): Promise<types.TransactionEntry>;
|
|
23
|
+
searchTransaction(hash: string): Promise<types.SearchTransactionResult>;
|
|
24
|
+
dumpTransaction(hash: string): Promise<string>;
|
|
23
25
|
buildTransaction(params: types.BuildTransactionParams): Promise<types.TransactionResponse>;
|
|
24
26
|
buildTransactionOffline(params: types.BuildTransactionOfflineParams): Promise<types.TransactionResponse>;
|
|
25
27
|
buildUnsignedTransaction(params: types.BuildTransactionParams): Promise<types.UnsignedTransactionResponse>;
|
|
@@ -286,6 +286,11 @@ export interface Query extends QueryValue, QueryElement {
|
|
|
286
286
|
and?: Query[];
|
|
287
287
|
or?: Query[];
|
|
288
288
|
}
|
|
289
|
+
export interface SearchTransactionResult {
|
|
290
|
+
transaction: TransactionEntry;
|
|
291
|
+
index?: number;
|
|
292
|
+
is_raw_search: boolean;
|
|
293
|
+
}
|
|
289
294
|
export declare enum RPCMethod {
|
|
290
295
|
GetVersion = "get_version",
|
|
291
296
|
GetNetwork = "get_network",
|
|
@@ -301,11 +306,13 @@ export declare enum RPCMethod {
|
|
|
301
306
|
GetAssets = "get_assets",
|
|
302
307
|
GetAsset = "get_asset",
|
|
303
308
|
GetTransaction = "get_transaction",
|
|
309
|
+
SearchTransaction = "search_transaction",
|
|
310
|
+
DumpTransaction = "dump_transaction",
|
|
304
311
|
BuildTransaction = "build_transaction",
|
|
305
312
|
BuildTransactionOffline = "build_transaction_offline",
|
|
306
313
|
BuildUnsignedTransaction = "build_unsigned_transaction",
|
|
307
|
-
SignUnsignedTransaction = "sign_unsigned_transaction",
|
|
308
314
|
FinalizeUnsignedTransaction = "finalize_unsigned_transaction",
|
|
315
|
+
SignUnsignedTransaction = "sign_unsigned_transaction",
|
|
309
316
|
ClearTxCache = "clear_tx_cache",
|
|
310
317
|
ListTransactions = "list_transactions",
|
|
311
318
|
IsOnline = "is_online",
|
|
@@ -336,16 +343,3 @@ export declare enum RPCEvent {
|
|
|
336
343
|
Online = "online",
|
|
337
344
|
Offline = "offline"
|
|
338
345
|
}
|
|
339
|
-
export declare enum Permission {
|
|
340
|
-
Ask = 0,
|
|
341
|
-
AcceptAlways = 1,
|
|
342
|
-
DenyAlways = 2
|
|
343
|
-
}
|
|
344
|
-
export interface ApplicationData {
|
|
345
|
-
id: string;
|
|
346
|
-
name: string;
|
|
347
|
-
description: string;
|
|
348
|
-
url?: string;
|
|
349
|
-
permissions: Map<string, Permission>;
|
|
350
|
-
signature?: string;
|
|
351
|
-
}
|
|
@@ -33,6 +33,8 @@ export declare class WalletMethods {
|
|
|
33
33
|
}>;
|
|
34
34
|
getAsset(params: daemonTypes.GetAssetParams): Promise<types.Asset>;
|
|
35
35
|
getTransaction(hash: string): Promise<types.TransactionEntry>;
|
|
36
|
+
searchTransaction(hash: string): Promise<types.SearchTransactionResult>;
|
|
37
|
+
dumpTransaction(hash: string): Promise<string>;
|
|
36
38
|
buildTransaction(params: types.BuildTransactionParams): Promise<types.TransactionResponse>;
|
|
37
39
|
buildTransactionOffline(params: types.BuildTransactionOfflineParams): Promise<types.TransactionResponse>;
|
|
38
40
|
buildUnsignedTransaction(params: types.BuildTransactionParams): Promise<types.UnsignedTransactionResponse>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Relayer from './index';
|
|
2
|
+
export declare class App {
|
|
3
|
+
relayer: Relayer;
|
|
4
|
+
element: HTMLDivElement;
|
|
5
|
+
contentElement: HTMLDivElement;
|
|
6
|
+
qrCodeElement: HTMLDivElement;
|
|
7
|
+
loadingElement: HTMLDivElement;
|
|
8
|
+
errElement: HTMLDivElement;
|
|
9
|
+
constructor(relayer: Relayer);
|
|
10
|
+
clear(): void;
|
|
11
|
+
setError(msg: string): void;
|
|
12
|
+
setLoading(): void;
|
|
13
|
+
setQRCode(channelId: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { App } from './app';
|
|
2
|
+
export type RelayerEncryptionMode = null | "aes" | "chacha20poly1305";
|
|
3
|
+
export interface RelayerProps {
|
|
4
|
+
url: string;
|
|
5
|
+
encryption_mode: RelayerEncryptionMode;
|
|
6
|
+
parent: HTMLElement;
|
|
7
|
+
}
|
|
8
|
+
declare class Relayer {
|
|
9
|
+
ws: WebSocket;
|
|
10
|
+
app: App;
|
|
11
|
+
props: RelayerProps;
|
|
12
|
+
message_timeout?: number;
|
|
13
|
+
constructor(props: RelayerProps);
|
|
14
|
+
close(): void;
|
|
15
|
+
onOpen: (e: Event) => void;
|
|
16
|
+
onMessage: (e: MessageEvent) => void;
|
|
17
|
+
onError: (e: Event) => void;
|
|
18
|
+
onClose: (e: CloseEvent) => void;
|
|
19
|
+
}
|
|
20
|
+
export default Relayer;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
export declare enum Permission {
|
|
2
|
-
Ask = 0,
|
|
3
|
-
AcceptAlways = 1,
|
|
4
|
-
DenyAlways = 2
|
|
5
|
-
}
|
|
6
1
|
export interface ApplicationData {
|
|
7
2
|
id: string;
|
|
8
3
|
name: string;
|
|
9
4
|
description: string;
|
|
10
5
|
url?: string;
|
|
11
|
-
permissions:
|
|
12
|
-
signature?: string;
|
|
6
|
+
permissions: string[];
|
|
13
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WSRPC } from '../rpc/websocket';
|
|
2
|
-
import { ApplicationData } from '../wallet/types';
|
|
3
2
|
import { DaemonMethods } from '../daemon/websocket';
|
|
4
3
|
import { WalletMethods } from '../wallet/websocket';
|
|
4
|
+
import { ApplicationData } from './types';
|
|
5
5
|
export declare class WS extends WSRPC {
|
|
6
6
|
daemon: DaemonMethods;
|
|
7
7
|
wallet: WalletMethods;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.10.
|
|
2
|
+
"version": "0.10.10",
|
|
3
3
|
"name": "@xelis/sdk",
|
|
4
4
|
"description": "Xelis software development kit for JS",
|
|
5
5
|
"exports": {
|
|
@@ -23,24 +23,32 @@
|
|
|
23
23
|
"test": "jest",
|
|
24
24
|
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
|
|
25
25
|
"fix-esm": "fix-esm-import-path ./dist/esm",
|
|
26
|
-
"clean": "
|
|
27
|
-
"
|
|
28
|
-
"
|
|
26
|
+
"clean": "rimraf ./dist",
|
|
27
|
+
"copy-css": "copyfiles -u 1 ./src/**/*.css ./dist/cjs && copyfiles -u 1 ./src/**/*.css ./dist/esm",
|
|
28
|
+
"build": "npm run clean && npm run compile && node create_esm_pkg.js && npm run fix-esm && npm run copy-css",
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"publish-dev": "npm publish --tag beta",
|
|
31
|
+
"dev-relayer": "vite ./src/xswd/relayer/test"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@types/jest": "^29.4.0",
|
|
32
35
|
"@types/json-bigint": "^1.0.4",
|
|
36
|
+
"@types/qrcode": "^1.5.5",
|
|
33
37
|
"@types/react": "^18.2.23",
|
|
34
38
|
"@types/ws": "^8.5.4",
|
|
39
|
+
"copyfiles": "^2.4.1",
|
|
35
40
|
"fix-esm-import-path": "^1.10.1",
|
|
41
|
+
"rimraf": "^6.0.1",
|
|
36
42
|
"ts-jest": "^29.0.5",
|
|
37
|
-
"typescript": "^4.9.5"
|
|
43
|
+
"typescript": "^4.9.5",
|
|
44
|
+
"vite": "^7.0.5"
|
|
38
45
|
},
|
|
39
46
|
"dependencies": {
|
|
40
47
|
"await-to-js": "^3.0.0",
|
|
41
48
|
"isomorphic-ws": "^5.0.0",
|
|
42
49
|
"js-base64": "^3.7.6",
|
|
43
50
|
"json-bigint": "^1.0.0",
|
|
51
|
+
"qrcode": "^1.5.4",
|
|
44
52
|
"react": "^18.2.0",
|
|
45
53
|
"ws": "^8.12.1"
|
|
46
54
|
}
|