chia-agent 14.3.3 → 14.5.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/daemon/index.d.ts CHANGED
@@ -26,6 +26,7 @@ declare class Daemon {
26
26
  get connected(): boolean;
27
27
  get closing(): boolean;
28
28
  constructor(serviceName?: string);
29
+ protected onRejection(e: unknown): null;
29
30
  /**
30
31
  * Connect to local daemon via websocket.
31
32
  * @param daemonServerURL
package/daemon/index.js CHANGED
@@ -71,10 +71,31 @@ class Daemon {
71
71
  this.onClose = this.onClose.bind(this);
72
72
  this.onPing = this.onPing.bind(this);
73
73
  this.onPong = this.onPong.bind(this);
74
+ this.onRejection = this.onRejection.bind(this);
74
75
  if (serviceName) {
75
76
  this._serviceName = serviceName;
76
77
  }
77
78
  }
79
+ onRejection(e) {
80
+ if (typeof e === "string") {
81
+ (0, logger_1.getLogger)().error(`Error: ${e}`);
82
+ }
83
+ else if (e instanceof Error) {
84
+ (0, logger_1.getLogger)().error(`Error ${e.name}: ${e.message}`);
85
+ if (e.stack) {
86
+ (0, logger_1.getLogger)().error(e.stack);
87
+ }
88
+ }
89
+ else {
90
+ try {
91
+ (0, logger_1.getLogger)().error(`Error: ${JSON.stringify(e)}`);
92
+ }
93
+ catch (_) {
94
+ (0, logger_1.getLogger)().error("Unknown error");
95
+ }
96
+ }
97
+ return null;
98
+ }
78
99
  /**
79
100
  * Connect to local daemon via websocket.
80
101
  * @param daemonServerURL
@@ -96,14 +117,18 @@ class Daemon {
96
117
  return false;
97
118
  }
98
119
  (0, logger_1.getLogger)().debug(`Opening websocket connection to ${daemonServerURL}`);
99
- const result = yield (0, connection_1.open)(daemonServerURL, timeoutMs);
120
+ const result = yield (0, connection_1.open)(daemonServerURL, timeoutMs)
121
+ .catch(this.onRejection);
122
+ if (!result) {
123
+ return false;
124
+ }
100
125
  this._socket = result.ws;
101
126
  this._socket.on("error", this.onError);
102
127
  this._socket.addEventListener("message", this.onMessage);
103
128
  this._socket.on("close", this.onClose);
104
129
  this._socket.on("ping", this.onPing);
105
130
  this._socket.on("pong", this.onPong);
106
- yield this.onOpen(result.openEvent, daemonServerURL);
131
+ yield this.onOpen(result.openEvent, daemonServerURL).catch(this.onRejection);
107
132
  return true;
108
133
  });
109
134
  }
@@ -116,6 +141,7 @@ class Daemon {
116
141
  (0, logger_1.getLogger)().debug("Closing web socket connection");
117
142
  this._socket.close();
118
143
  this._closing = true;
144
+ this._connectedUrl = "";
119
145
  this._onClosePromise = resolve; // Resolved in onClose function.
120
146
  }));
121
147
  });
@@ -175,6 +201,7 @@ class Daemon {
175
201
  });
176
202
  if (error || !result) {
177
203
  (0, logger_1.getLogger)().error("Failed to register agent service to daemon");
204
+ (0, logger_1.getLogger)().error(error instanceof Error ? `${error.name}: ${error.message}` : JSON.stringify(error));
178
205
  throw new Error("Subscribe failed");
179
206
  }
180
207
  this._subscriptions.push(service);
@@ -310,7 +337,7 @@ class Daemon {
310
337
  this._subscriptions = [];
311
338
  this._closeEventListeners.forEach(l => l(event));
312
339
  this.clearAllEventListeners();
313
- (0, logger_1.getLogger)().info("Closed ws connection");
340
+ (0, logger_1.getLogger)().info(`Closed ws connection. code:${event.code} wasClean:${event.wasClean} reason:${event.reason}`);
314
341
  if (this._onClosePromise) {
315
342
  this._onClosePromise();
316
343
  this._onClosePromise = undefined;
package/index.d.ts CHANGED
@@ -2,3 +2,6 @@ export * from "./logger";
2
2
  export * from "./daemon/index";
3
3
  export * from "./rpc/index";
4
4
  export * from "./config/index";
5
+ export { VCMint } from "./api/chia/rpc/wallet_request_types";
6
+ export { VcSpend } from "./api/chia/rpc/wallet_request_types";
7
+ export { VcRevoke } from "./api/chia/rpc/wallet_request_types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chia-agent",
3
- "version": "14.3.3",
3
+ "version": "14.5.0",
4
4
  "author": "ChiaMineJP <admin@chiamine.jp>",
5
5
  "description": "chia rpc/websocket client library",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@chiamine/json-bigint": "^1.0.3",
30
- "ws": "^8.17.0",
30
+ "ws": "^8.18.1",
31
31
  "yaml": "^2.4.2"
32
32
  }
33
33
  }