chia-agent 14.3.0 → 14.3.2
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/CHANGELOG.md +13 -0
- package/daemon/connection.d.ts +1 -0
- package/daemon/connection.js +14 -6
- package/daemon/index.d.ts +2 -0
- package/daemon/index.js +35 -6
- package/package.json +1 -1
- package/rpc/index.js +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [14.3.2]
|
|
4
|
+
### Changed
|
|
5
|
+
- Error logs are generated when
|
|
6
|
+
- an error occurs during sending a message.
|
|
7
|
+
- it receives a websocket message with unexpected format.
|
|
8
|
+
- Debug logs are generated when ping/pong events are triggered.
|
|
9
|
+
|
|
10
|
+
## [14.3.1]
|
|
11
|
+
### Changed
|
|
12
|
+
- Added a `Host` header when sending https request to a remote host.
|
|
13
|
+
|
|
3
14
|
## [14.3.0]
|
|
4
15
|
### Changed
|
|
5
16
|
- Removed `RpcWalletMessageOnWs` since it's costly to maintain while there are a few use cases.
|
|
@@ -1704,6 +1715,8 @@ daemon.sendMessage(destination, get_block_record_by_height_command, data);
|
|
|
1704
1715
|
Initial release.
|
|
1705
1716
|
|
|
1706
1717
|
<!-- [Unreleased]: https://github.com/Chia-Mine/chia-agent/compare/v0.0.1...v0.0.2 -->
|
|
1718
|
+
[14.3.2]: https://github.com/Chia-Mine/chia-agent/compare/v14.3.1...v14.3.2
|
|
1719
|
+
[14.3.1]: https://github.com/Chia-Mine/chia-agent/compare/v14.3.0...v14.3.1
|
|
1707
1720
|
[14.3.0]: https://github.com/Chia-Mine/chia-agent/compare/v14.2.2...v14.3.0
|
|
1708
1721
|
[14.2.2]: https://github.com/Chia-Mine/chia-agent/compare/v14.2.1...v14.2.2
|
|
1709
1722
|
[14.2.1]: https://github.com/Chia-Mine/chia-agent/compare/v14.2.0...v14.2.1
|
package/daemon/connection.d.ts
CHANGED
package/daemon/connection.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.open = void 0;
|
|
3
|
+
exports.open = exports.defaultTimeoutInMs = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const config_1 = require("../config");
|
|
6
6
|
const WS = require("ws");
|
|
@@ -25,25 +25,33 @@ function create(url) {
|
|
|
25
25
|
};
|
|
26
26
|
return new WS(url, options);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
exports.defaultTimeoutInMs = 50000;
|
|
29
29
|
function open(url, timeoutMs) {
|
|
30
30
|
return new Promise((resolve, reject) => {
|
|
31
31
|
const ws = create(url);
|
|
32
32
|
let timer = null;
|
|
33
|
-
timeoutMs = typeof timeoutMs === "number" ? timeoutMs : defaultTimeoutInMs;
|
|
33
|
+
timeoutMs = typeof timeoutMs === "number" ? timeoutMs : exports.defaultTimeoutInMs;
|
|
34
|
+
let opened = false;
|
|
34
35
|
timer = setTimeout(() => {
|
|
35
36
|
timer = null;
|
|
36
37
|
(0, logger_1.getLogger)().error("Request to open connection timed out");
|
|
37
38
|
reject("Timeout");
|
|
38
39
|
}, timeoutMs);
|
|
39
|
-
|
|
40
|
+
const onOpenError = (err) => {
|
|
41
|
+
if (!opened) {
|
|
42
|
+
reject(err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
ws.addEventListener("open", (openEvent) => {
|
|
46
|
+
opened = true;
|
|
47
|
+
ws.removeEventListener("error", onOpenError);
|
|
40
48
|
if (timer !== null) {
|
|
41
49
|
clearTimeout(timer);
|
|
42
50
|
timer = null;
|
|
43
51
|
resolve({ ws, openEvent });
|
|
44
52
|
}
|
|
45
|
-
};
|
|
46
|
-
ws.
|
|
53
|
+
});
|
|
54
|
+
ws.addEventListener("error", onOpenError);
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
57
|
exports.open = open;
|
package/daemon/index.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ declare class Daemon {
|
|
|
57
57
|
protected onError(error: ErrorEvent): void;
|
|
58
58
|
protected onMessage(event: MessageEvent): void;
|
|
59
59
|
protected onClose(event: CloseEvent): void;
|
|
60
|
+
protected onPing(): void;
|
|
61
|
+
protected onPong(): void;
|
|
60
62
|
}
|
|
61
63
|
export type TDaemon = InstanceType<typeof Daemon>;
|
|
62
64
|
export {};
|
package/daemon/index.js
CHANGED
|
@@ -68,6 +68,8 @@ class Daemon {
|
|
|
68
68
|
this.onError = this.onError.bind(this);
|
|
69
69
|
this.onMessage = this.onMessage.bind(this);
|
|
70
70
|
this.onClose = this.onClose.bind(this);
|
|
71
|
+
this.onPing = this.onPing.bind(this);
|
|
72
|
+
this.onPong = this.onPong.bind(this);
|
|
71
73
|
}
|
|
72
74
|
/**
|
|
73
75
|
* Connect to local daemon via websocket.
|
|
@@ -92,9 +94,11 @@ class Daemon {
|
|
|
92
94
|
(0, logger_1.getLogger)().debug(`Opening websocket connection to ${daemonServerURL}`);
|
|
93
95
|
const result = yield (0, connection_1.open)(daemonServerURL, timeoutMs);
|
|
94
96
|
this._socket = result.ws;
|
|
95
|
-
this._socket.
|
|
96
|
-
this._socket.
|
|
97
|
-
this._socket.
|
|
97
|
+
this._socket.addEventListener("error", this.onError);
|
|
98
|
+
this._socket.addEventListener("message", this.onMessage);
|
|
99
|
+
this._socket.addEventListener("close", this.onClose);
|
|
100
|
+
this._socket.addListener("ping", this.onPing);
|
|
101
|
+
this._socket.addListener("pong", this.onPong);
|
|
98
102
|
yield this.onOpen(result.openEvent, daemonServerURL);
|
|
99
103
|
return true;
|
|
100
104
|
});
|
|
@@ -124,7 +128,13 @@ class Daemon {
|
|
|
124
128
|
const reqId = message.request_id;
|
|
125
129
|
this._responseQueue[reqId] = resolve;
|
|
126
130
|
(0, logger_1.getLogger)().debug(`Sending message. dest=${destination} command=${command} reqId=${reqId}`);
|
|
127
|
-
|
|
131
|
+
const messageStr = JSON.stringify(message);
|
|
132
|
+
this._socket.send(messageStr, (err) => {
|
|
133
|
+
if (err) {
|
|
134
|
+
(0, logger_1.getLogger)().error(`Error while sending message: ${messageStr}`);
|
|
135
|
+
(0, logger_1.getLogger)().error(JSON.stringify(err));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
128
138
|
});
|
|
129
139
|
});
|
|
130
140
|
}
|
|
@@ -252,8 +262,19 @@ class Daemon {
|
|
|
252
262
|
this._errorEventListeners.forEach(l => l(error));
|
|
253
263
|
}
|
|
254
264
|
onMessage(event) {
|
|
255
|
-
|
|
256
|
-
|
|
265
|
+
let payload;
|
|
266
|
+
let request_id;
|
|
267
|
+
let origin;
|
|
268
|
+
let command;
|
|
269
|
+
try {
|
|
270
|
+
payload = JSON.parse(event.data);
|
|
271
|
+
({ request_id, origin, command } = payload);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
(0, logger_1.getLogger)().error(`Failed to parse message data: ${JSON.stringify(err)}`);
|
|
275
|
+
(0, logger_1.getLogger)().error(`payload: ${event.data}`);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
257
278
|
(0, logger_1.getLogger)().debug(`Arrived message. origin=${origin} command=${command} reqId=${request_id}`);
|
|
258
279
|
const resolver = this._responseQueue[request_id];
|
|
259
280
|
if (resolver) {
|
|
@@ -276,6 +297,8 @@ class Daemon {
|
|
|
276
297
|
this._socket.removeEventListener("error", this.onError);
|
|
277
298
|
this._socket.removeEventListener("message", this.onMessage);
|
|
278
299
|
this._socket.removeEventListener("close", this.onClose);
|
|
300
|
+
this._socket.removeListener("ping", this.onPing);
|
|
301
|
+
this._socket.removeListener("pong", this.onPong);
|
|
279
302
|
this._socket = null;
|
|
280
303
|
}
|
|
281
304
|
this._closing = false;
|
|
@@ -289,4 +312,10 @@ class Daemon {
|
|
|
289
312
|
this._onClosePromise = undefined;
|
|
290
313
|
}
|
|
291
314
|
}
|
|
315
|
+
onPing() {
|
|
316
|
+
(0, logger_1.getLogger)().debug("Received ping");
|
|
317
|
+
}
|
|
318
|
+
onPong() {
|
|
319
|
+
(0, logger_1.getLogger)().debug("Received pong");
|
|
320
|
+
}
|
|
292
321
|
}
|
package/package.json
CHANGED
package/rpc/index.js
CHANGED
|
@@ -202,14 +202,19 @@ class RPCAgent {
|
|
|
202
202
|
const body = data ? JSONbig.stringify(data) : "{}";
|
|
203
203
|
const pathname = `/${path.replace(/^\/+/, "")}`;
|
|
204
204
|
const METHOD = method.toUpperCase();
|
|
205
|
+
const headers = {
|
|
206
|
+
Accept: "application/json, text/plain, */*",
|
|
207
|
+
"User-Agent": userAgent,
|
|
208
|
+
};
|
|
209
|
+
if ("options" in this._agent && typeof this._agent.options.host === "string") {
|
|
210
|
+
// Assuming `this._agent instanceof HttpsAgent` is true.
|
|
211
|
+
headers.Host = this._agent.options.host;
|
|
212
|
+
}
|
|
205
213
|
const options = {
|
|
206
214
|
path: pathname,
|
|
207
215
|
method: METHOD,
|
|
208
216
|
agent: this._agent,
|
|
209
|
-
headers
|
|
210
|
-
Accept: "application/json, text/plain, */*",
|
|
211
|
-
"User-Agent": userAgent,
|
|
212
|
-
},
|
|
217
|
+
headers,
|
|
213
218
|
};
|
|
214
219
|
if (this._skip_hostname_verification) {
|
|
215
220
|
options.checkServerIdentity = () => {
|