chia-agent 16.1.2 → 16.1.4

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [16.1.4]
4
+ ### Fixed
5
+ - Fixed `TGetCoinRecordsByPuzzleHashesRequest` type definition
6
+ - Made `start_height`, `end_height`, and `include_spent_coins` optional parameters
7
+
8
+ ## [16.1.3]
9
+ ### Fixed
10
+ - RPC failures now reject with a typed `RpcError` instead of a raw response object
11
+
3
12
  ## [16.1.2]
4
13
  ### Fixed
5
14
  - Fixed `TGetCoinRecordsByPuzzleHashRequest` type definition
@@ -211,9 +211,9 @@ export declare const get_coin_records_by_puzzle_hashes_command = "get_coin_recor
211
211
  export type get_coin_records_by_puzzle_hashes_command = typeof get_coin_records_by_puzzle_hashes_command;
212
212
  export type TGetCoinRecordsByPuzzleHashesRequest = {
213
213
  puzzle_hashes: str[];
214
- start_height: uint32;
215
- end_height: uint32;
216
- include_spent_coins: bool;
214
+ start_height?: uint32;
215
+ end_height?: uint32;
216
+ include_spent_coins?: bool;
217
217
  };
218
218
  export type TGetCoinRecordsByPuzzleHashesResponse = {
219
219
  coin_records: CoinRecordBackwardCompatible[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chia-agent",
3
- "version": "16.1.2",
3
+ "version": "16.1.4",
4
4
  "author": "ChiaMineJP <admin@chiamine.jp>",
5
5
  "description": "chia rpc/websocket client library",
6
6
  "license": "MIT",
package/rpc/index.d.ts CHANGED
@@ -2,6 +2,10 @@ import { Agent as HttpsAgent } from "https";
2
2
  import { Agent as HttpAgent } from "http";
3
3
  import { TConfig } from "../config/index";
4
4
  import { APIAgent } from "../agent/index";
5
+ export declare class RpcError extends Error {
6
+ response: unknown;
7
+ constructor(message: string, response: unknown);
8
+ }
5
9
  type TDestination = "farmer" | "harvester" | "full_node" | "wallet" | "data_layer" | "daemon" | "pool";
6
10
  export declare function getConnectionInfoFromConfig(destination: TDestination, config: TConfig): {
7
11
  hostname: string;
package/rpc/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RPCAgent = void 0;
3
+ exports.RPCAgent = exports.RpcError = void 0;
4
4
  exports.getConnectionInfoFromConfig = getConnectionInfoFromConfig;
5
5
  exports.getConf = getConf;
6
6
  exports.loadCertFilesFromConfig = loadCertFilesFromConfig;
@@ -14,6 +14,14 @@ const JSONbig = JSONbigBuilder({
14
14
  useNativeBigInt: true,
15
15
  alwaysParseAsBig: false,
16
16
  });
17
+ class RpcError extends Error {
18
+ constructor(message, response) {
19
+ super(message);
20
+ this.name = "RpcError";
21
+ this.response = response;
22
+ }
23
+ }
24
+ exports.RpcError = RpcError;
17
25
  function getConnectionInfoFromConfig(destination, config) {
18
26
  let hostname = "localhost";
19
27
  let port = -1;
@@ -313,8 +321,13 @@ class RPCAgent {
313
321
  return reject(new Error(`Response has no 'success' property: ${serializedData}`));
314
322
  }
315
323
  if (!d.success) {
316
- (0, logger_1.getLogger)().info(`API failure: ${d.error}`);
317
- return reject(d);
324
+ const errorMessage = typeof d.error === "string"
325
+ ? d.error
326
+ : typeof d.error_message === "string"
327
+ ? d.error_message
328
+ : `RPC request failed: ${(0, logger_1.stringify)(d)}`;
329
+ (0, logger_1.getLogger)().info(`API failure: ${errorMessage}`);
330
+ return reject(new RpcError(errorMessage, d));
318
331
  }
319
332
  (0, logger_1.getLogger)().debug(() => `RPC response received from ${this._protocol}//${this._host}:${this._port}${options.path}`);
320
333
  (0, logger_1.getLogger)().trace(() => `RPC response data: ${(0, logger_1.stringify)(d)}`);