chia-agent 14.3.2 → 14.3.3
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 +6 -0
- package/daemon/connection.js +3 -3
- package/daemon/index.d.ts +3 -2
- package/daemon/index.js +19 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [14.3.3]
|
|
4
|
+
### Changed
|
|
5
|
+
- The default service name which [`Daemon`](./src/daemon/index.ts) client tries to register is now `wallet_ui`.
|
|
6
|
+
Previously `chia_agent` service and optionally `wallet_ui` service were registered to `chia-blockchain`'s `Daemon`.
|
|
7
|
+
|
|
3
8
|
## [14.3.2]
|
|
4
9
|
### Changed
|
|
5
10
|
- Error logs are generated when
|
|
@@ -1715,6 +1720,7 @@ daemon.sendMessage(destination, get_block_record_by_height_command, data);
|
|
|
1715
1720
|
Initial release.
|
|
1716
1721
|
|
|
1717
1722
|
<!-- [Unreleased]: https://github.com/Chia-Mine/chia-agent/compare/v0.0.1...v0.0.2 -->
|
|
1723
|
+
[14.3.3]: https://github.com/Chia-Mine/chia-agent/compare/v14.3.2...v14.3.3
|
|
1718
1724
|
[14.3.2]: https://github.com/Chia-Mine/chia-agent/compare/v14.3.1...v14.3.2
|
|
1719
1725
|
[14.3.1]: https://github.com/Chia-Mine/chia-agent/compare/v14.3.0...v14.3.1
|
|
1720
1726
|
[14.3.0]: https://github.com/Chia-Mine/chia-agent/compare/v14.2.2...v14.3.0
|
package/daemon/connection.js
CHANGED
|
@@ -42,16 +42,16 @@ function open(url, timeoutMs) {
|
|
|
42
42
|
reject(err);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
ws.
|
|
45
|
+
ws.on("open", (openEvent) => {
|
|
46
46
|
opened = true;
|
|
47
|
-
ws.
|
|
47
|
+
ws.off("error", onOpenError);
|
|
48
48
|
if (timer !== null) {
|
|
49
49
|
clearTimeout(timer);
|
|
50
50
|
timer = null;
|
|
51
51
|
resolve({ ws, openEvent });
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
ws.
|
|
54
|
+
ws.on("error", onOpenError);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
exports.open = open;
|
package/daemon/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type WsEvent = Event | MessageEvent | ErrorEvent | CloseEvent;
|
|
|
7
7
|
export type EventListener<T = WsEvent> = (ev: T) => unknown;
|
|
8
8
|
type EventListenerOf<T> = T extends "open" ? EventListener<Event> : T extends "message" ? EventListener<MessageEvent> : T extends "error" ? EventListener<ErrorEvent> : T extends "close" ? EventListener<CloseEvent> : never;
|
|
9
9
|
export type MessageListener<D extends WsMessage> = (msg: D) => unknown;
|
|
10
|
-
export declare function getDaemon(): Daemon;
|
|
10
|
+
export declare function getDaemon(serviceName?: string): Daemon;
|
|
11
11
|
declare class Daemon {
|
|
12
12
|
protected _socket: WS | null;
|
|
13
13
|
protected _connectedUrl: string;
|
|
@@ -22,9 +22,10 @@ declare class Daemon {
|
|
|
22
22
|
protected _closing: boolean;
|
|
23
23
|
protected _onClosePromise: (() => unknown) | undefined;
|
|
24
24
|
protected _subscriptions: string[];
|
|
25
|
+
protected _serviceName: string;
|
|
25
26
|
get connected(): boolean;
|
|
26
27
|
get closing(): boolean;
|
|
27
|
-
constructor();
|
|
28
|
+
constructor(serviceName?: string);
|
|
28
29
|
/**
|
|
29
30
|
* Connect to local daemon via websocket.
|
|
30
31
|
* @param daemonServerURL
|
package/daemon/index.js
CHANGED
|
@@ -14,13 +14,13 @@ const crypto_1 = require("crypto");
|
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
15
|
const connection_1 = require("./connection");
|
|
16
16
|
const index_1 = require("../config/index");
|
|
17
|
-
const
|
|
17
|
+
const DEFAULT_SERVICE_NAME = "wallet_ui";
|
|
18
18
|
let daemon = null;
|
|
19
|
-
function getDaemon() {
|
|
19
|
+
function getDaemon(serviceName) {
|
|
20
20
|
if (daemon) {
|
|
21
21
|
return daemon;
|
|
22
22
|
}
|
|
23
|
-
return daemon = new Daemon();
|
|
23
|
+
return daemon = new Daemon(serviceName);
|
|
24
24
|
}
|
|
25
25
|
exports.getDaemon = getDaemon;
|
|
26
26
|
// Gracefully disconnect from remote daemon server on Ctrl+C.
|
|
@@ -53,7 +53,7 @@ class Daemon {
|
|
|
53
53
|
get closing() {
|
|
54
54
|
return this._closing;
|
|
55
55
|
}
|
|
56
|
-
constructor() {
|
|
56
|
+
constructor(serviceName) {
|
|
57
57
|
this._socket = null;
|
|
58
58
|
this._connectedUrl = "";
|
|
59
59
|
this._responseQueue = {};
|
|
@@ -64,12 +64,16 @@ class Daemon {
|
|
|
64
64
|
this._messageListeners = {};
|
|
65
65
|
this._closing = false;
|
|
66
66
|
this._subscriptions = [];
|
|
67
|
+
this._serviceName = DEFAULT_SERVICE_NAME;
|
|
67
68
|
this.onOpen = this.onOpen.bind(this);
|
|
68
69
|
this.onError = this.onError.bind(this);
|
|
69
70
|
this.onMessage = this.onMessage.bind(this);
|
|
70
71
|
this.onClose = this.onClose.bind(this);
|
|
71
72
|
this.onPing = this.onPing.bind(this);
|
|
72
73
|
this.onPong = this.onPong.bind(this);
|
|
74
|
+
if (serviceName) {
|
|
75
|
+
this._serviceName = serviceName;
|
|
76
|
+
}
|
|
73
77
|
}
|
|
74
78
|
/**
|
|
75
79
|
* Connect to local daemon via websocket.
|
|
@@ -94,11 +98,11 @@ class Daemon {
|
|
|
94
98
|
(0, logger_1.getLogger)().debug(`Opening websocket connection to ${daemonServerURL}`);
|
|
95
99
|
const result = yield (0, connection_1.open)(daemonServerURL, timeoutMs);
|
|
96
100
|
this._socket = result.ws;
|
|
97
|
-
this._socket.
|
|
101
|
+
this._socket.on("error", this.onError);
|
|
98
102
|
this._socket.addEventListener("message", this.onMessage);
|
|
99
|
-
this._socket.
|
|
100
|
-
this._socket.
|
|
101
|
-
this._socket.
|
|
103
|
+
this._socket.on("close", this.onClose);
|
|
104
|
+
this._socket.on("ping", this.onPing);
|
|
105
|
+
this._socket.on("pong", this.onPong);
|
|
102
106
|
yield this.onOpen(result.openEvent, daemonServerURL);
|
|
103
107
|
return true;
|
|
104
108
|
});
|
|
@@ -143,7 +147,7 @@ class Daemon {
|
|
|
143
147
|
command,
|
|
144
148
|
data,
|
|
145
149
|
ack: false,
|
|
146
|
-
origin:
|
|
150
|
+
origin: this._serviceName,
|
|
147
151
|
destination,
|
|
148
152
|
request_id: (0, crypto_1.randomBytes)(32).toString("hex"),
|
|
149
153
|
};
|
|
@@ -160,7 +164,7 @@ class Daemon {
|
|
|
160
164
|
data: { success: true },
|
|
161
165
|
ack: true,
|
|
162
166
|
origin: "daemon",
|
|
163
|
-
destination:
|
|
167
|
+
destination: service,
|
|
164
168
|
request_id: "",
|
|
165
169
|
};
|
|
166
170
|
}
|
|
@@ -254,7 +258,7 @@ class Daemon {
|
|
|
254
258
|
(0, logger_1.getLogger)().info("ws connection opened");
|
|
255
259
|
this._connectedUrl = url;
|
|
256
260
|
this._openEventListeners.forEach(l => l(event));
|
|
257
|
-
return this.subscribe(
|
|
261
|
+
return this.subscribe(this._serviceName);
|
|
258
262
|
});
|
|
259
263
|
}
|
|
260
264
|
onError(error) {
|
|
@@ -294,11 +298,11 @@ class Daemon {
|
|
|
294
298
|
}
|
|
295
299
|
onClose(event) {
|
|
296
300
|
if (this._socket) {
|
|
297
|
-
this._socket.
|
|
301
|
+
this._socket.off("error", this.onError);
|
|
298
302
|
this._socket.removeEventListener("message", this.onMessage);
|
|
299
|
-
this._socket.
|
|
300
|
-
this._socket.
|
|
301
|
-
this._socket.
|
|
303
|
+
this._socket.off("close", this.onClose);
|
|
304
|
+
this._socket.off("ping", this.onPing);
|
|
305
|
+
this._socket.off("pong", this.onPong);
|
|
302
306
|
this._socket = null;
|
|
303
307
|
}
|
|
304
308
|
this._closing = false;
|