chia-agent 14.0.0-beta.1 → 14.0.0-beta.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 +38 -1
- package/agent/index.d.ts +3 -0
- package/agent/index.js +2 -0
- package/api/rpc/full_node/index.d.ts +9 -2
- package/api/rpc/full_node/index.js +9 -2
- package/api/rpc/index.d.ts +1 -1
- package/api/rpc/index.js +6 -5
- package/api/rpc/pool/index.d.ts +7 -7
- package/api/rpc/pool/index.js +3 -3
- package/api/types.d.ts +1 -1
- package/package.json +1 -1
- package/rpc/index.d.ts +15 -17
- package/rpc/index.js +99 -96
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
## [14.0.0]
|
|
4
4
|
### Breaking change
|
|
5
5
|
- When RPC API responds with `success: false`, its `Promise` now does `reject`. (Previously it does `resolve`)
|
|
6
|
+
### Changed
|
|
7
|
+
- Loosened a type of `agent` to call RPC APIs. RPC APIs can be invoked with `agent` which just implements
|
|
8
|
+
`sendMessage` method depicted as below.
|
|
9
|
+
```typescript
|
|
10
|
+
export interface APIAgent {
|
|
11
|
+
sendMessage<M extends unknown>(
|
|
12
|
+
destination: string,
|
|
13
|
+
command: string,
|
|
14
|
+
data?: Record<string, unknown>,
|
|
15
|
+
): Promise<M>;
|
|
16
|
+
}
|
|
17
|
+
```
|
|
6
18
|
### Added
|
|
7
19
|
- Added connectivity options for `RPCAgent`.
|
|
8
20
|
- `keepAlive` (default: `true`)
|
|
@@ -11,7 +23,7 @@
|
|
|
11
23
|
- `timeout` (default: `undefined`)
|
|
12
24
|
```typescript
|
|
13
25
|
// Usage
|
|
14
|
-
const {RPCAgent
|
|
26
|
+
const {RPCAgent} = require("chia-agent");
|
|
15
27
|
const {get_plots} = require("chia-agent/api/rpc");
|
|
16
28
|
|
|
17
29
|
const agent = new RPCAgent({
|
|
@@ -21,7 +33,32 @@ const agent = new RPCAgent({
|
|
|
21
33
|
maxSockets: 1, // Avoid to set `1` if your requests may be sent in parallel.
|
|
22
34
|
timeout: 5000,
|
|
23
35
|
});
|
|
36
|
+
const res = await get_plots(agent);
|
|
24
37
|
```
|
|
38
|
+
- Added `httpsAgent`, `httpAgent` option for `RPCAgent`.
|
|
39
|
+
You can now configure and inject your own `require('https').Agent` into `RPCAgent`.
|
|
40
|
+
```typescript
|
|
41
|
+
// Usage
|
|
42
|
+
const {Agent: HttpsAgent} = require("https"); // or const {Agent: HttpAgent} = require('http');
|
|
43
|
+
const {RPCAgent} = require("chia-agent");
|
|
44
|
+
const {get_plots} = require("chia-agent/api/rpc");
|
|
45
|
+
|
|
46
|
+
const httpsAgent = new HttpsAgent({
|
|
47
|
+
host: "localhost",
|
|
48
|
+
port: 8560,
|
|
49
|
+
ca: ...,
|
|
50
|
+
cert: ...,
|
|
51
|
+
key: ...,
|
|
52
|
+
rejectUnauthorized: false,
|
|
53
|
+
});
|
|
54
|
+
const agent = new RPCAgent({httpsAgent: httpsAgent}); // `new RPCAgent({httpAgent: httpAgent});` is also allowed.
|
|
55
|
+
const res = await get_plots(agent);
|
|
56
|
+
```
|
|
57
|
+
- [FullNode RPC API](./src/api/rpc/full_node)
|
|
58
|
+
- [`get_aggsig_additional_data`](./src/api/rpc/full_node/README.md#get_aggsig_additional_dataagent)
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
- Fixed an issue where some of the RPC Pool APIs did not handle request parameters correctly.
|
|
25
62
|
|
|
26
63
|
## [13.2.0]
|
|
27
64
|
### Added
|
package/agent/index.d.ts
ADDED
package/agent/index.js
ADDED
|
@@ -162,6 +162,13 @@ export declare type TGetAdditionsAndRemovalsResponse = {
|
|
|
162
162
|
};
|
|
163
163
|
export declare type WsGetAdditionsAndRemovalsMessage = GetMessageType<chia_full_node_service, get_additions_and_removals_command, TGetAdditionsAndRemovalsResponse>;
|
|
164
164
|
export declare function get_additions_and_removals<T extends TRPCAgent | TDaemon>(agent: T, data: TGetAdditionsAndRemovalsRequest): Promise<ResType<T, TGetAdditionsAndRemovalsResponse, WsGetAdditionsAndRemovalsMessage>>;
|
|
165
|
+
export declare const get_aggsig_additional_data_command = "get_aggsig_additional_data";
|
|
166
|
+
export declare type get_aggsig_additional_data_command = typeof get_aggsig_additional_data_command;
|
|
167
|
+
export declare type TGetAggsigAdditionalDataResponse = {
|
|
168
|
+
additional_data: str;
|
|
169
|
+
};
|
|
170
|
+
export declare type WsGetAggsigAdditionalDataMessage = GetMessageType<chia_full_node_service, get_aggsig_additional_data_command, TGetAggsigAdditionalDataResponse>;
|
|
171
|
+
export declare function get_aggsig_additional_data<T extends TRPCAgent | TDaemon>(agent: T): Promise<ResType<T, TGetAggsigAdditionalDataResponse, WsGetAggsigAdditionalDataMessage>>;
|
|
165
172
|
export declare const get_initial_freeze_period_command_of_full_node = "get_initial_freeze_period";
|
|
166
173
|
export declare type get_initial_freeze_period_command_of_full_node = typeof get_initial_freeze_period_command_of_full_node;
|
|
167
174
|
export declare type TGetInitialFreezePeriodRequestOfFullNode = {};
|
|
@@ -451,5 +458,5 @@ export declare type TReorgBlocksResponse = {
|
|
|
451
458
|
};
|
|
452
459
|
export declare type WsReorgBlocksMessage = GetMessageType<chia_full_node_service, reorg_blocks_command, TReorgBlocksResponse>;
|
|
453
460
|
export declare function reorg_blocks<T extends TRPCAgent | TDaemon>(agent: T, data: TReorgBlocksRequest): Promise<ResType<T, TReorgBlocksResponse, WsReorgBlocksMessage>>;
|
|
454
|
-
export declare type RpcFullNodeMessage = TGetAdditionsAndRemovalsResponse | TGetAllMempoolItemsResponse | TGetAllMempoolTxIdsResponse | TGetBlockResponse | TGetBlockRecordByHeightResponse | TGetBlockRecordResponse | TGetBlockRecordsResponse | TGetBlockSpendsResponse | TGetBlockSpendsWithConditionsResponse | TGetBlockchainStateResponse | TGetBlocksResponse | TGetBlockCountMetricsResponse | TGetRecentSignagePointOrEOSCommandResponse | TGetCoinRecordByNameResponse | TGetCoinRecordsByNamesResponse | TGetCoinRecordsByPuzzleHashResponse | TGetCoinRecordsByPuzzleHashesResponse | TGetCoinRecordsByParentIdsResponse | TGetCoinRecordsByHintResponse | TGetInitialFreezePeriodResponseOfFullNode | TGetMempoolItemByTxIdResponse | TGetMempoolItemsByCoinNameResponse | TGetNetworkInfoResponseOfFullNode | TGetNetworkSpaceResponse | TGetUnfinishedBlockHeadersResponse | TPushTxResponse | TGetPuzzleAndSolutionResponse | TGetFeeEstimateResponse | TGetAllBlocksResponse | TFarmBlockResponse | TSetAutoFarmingResponse | TGetAutoFarmingResponse | TGetFarmingPhResponse | TGetAllCoinsResponse | TGetAllPuzzleHashesResponse | TRevertBlocksResponse | TReorgBlocksResponse;
|
|
455
|
-
export declare type RpcFullNodeMessageOnWs = WsGetAdditionsAndRemovalsMessage | WsGetAllMempoolItemsMessage | WsGetAllMempoolTxIdsMessage | WsGetBlockMessage | WsGetBlockRecordByHeightMessage | WsGetBlockRecordMessage | WsGetBlockRecordsMessage | WsGetBlockSpendsMessage | WsGetBlockSpendsWithConditionsMessage | WsGetBlockchainStateMessage | WsGetBlocksMessage | WsGetBlockCountMetricsMessage | WsGetRecentSignagePointOrEOSCommandMessage | WsGetCoinRecordByNameMessage | WsGetCoinRecordsByNamesMessage | WsGetCoinRecordsByPuzzleHashMessage | WsGetCoinRecordsByPuzzleHashesMessage | WsGetCoinRecordsByParentIdsMessage | WsGetCoinRecordsByHintMessage | WsGetInitialFreezePeriodMessageOfFullNode | WsGetMempoolItemByTxIdMessage | WsGetMempoolItemsByCoinNameMessage | WsGetNetworkInfoMessageOfFullNode | WsGetNetworkSpaceMessage | WsGetUnfinishedBlockHeadersMessage | WsPushTxMessage | WsGetPuzzleAndSolutionMessage | WsGetFeeEstimateMessage | WsGetAllBlocksMessage | WsFarmBlockMessage | WsSetAutoFarmingMessage | WsGetAutoFarmingMessage | WsGetFarmingPhMessage | WsGetAllCoinsMessage | WsGetAllPuzzleHashesMessage | WsRevertBlocksMessage | WsReorgBlocksMessage;
|
|
461
|
+
export declare type RpcFullNodeMessage = TGetAdditionsAndRemovalsResponse | TGetAggsigAdditionalDataResponse | TGetAllMempoolItemsResponse | TGetAllMempoolTxIdsResponse | TGetBlockResponse | TGetBlockRecordByHeightResponse | TGetBlockRecordResponse | TGetBlockRecordsResponse | TGetBlockSpendsResponse | TGetBlockSpendsWithConditionsResponse | TGetBlockchainStateResponse | TGetBlocksResponse | TGetBlockCountMetricsResponse | TGetRecentSignagePointOrEOSCommandResponse | TGetCoinRecordByNameResponse | TGetCoinRecordsByNamesResponse | TGetCoinRecordsByPuzzleHashResponse | TGetCoinRecordsByPuzzleHashesResponse | TGetCoinRecordsByParentIdsResponse | TGetCoinRecordsByHintResponse | TGetInitialFreezePeriodResponseOfFullNode | TGetMempoolItemByTxIdResponse | TGetMempoolItemsByCoinNameResponse | TGetNetworkInfoResponseOfFullNode | TGetNetworkSpaceResponse | TGetUnfinishedBlockHeadersResponse | TPushTxResponse | TGetPuzzleAndSolutionResponse | TGetFeeEstimateResponse | TGetAllBlocksResponse | TFarmBlockResponse | TSetAutoFarmingResponse | TGetAutoFarmingResponse | TGetFarmingPhResponse | TGetAllCoinsResponse | TGetAllPuzzleHashesResponse | TRevertBlocksResponse | TReorgBlocksResponse;
|
|
462
|
+
export declare type RpcFullNodeMessageOnWs = WsGetAdditionsAndRemovalsMessage | WsGetAggsigAdditionalDataMessage | WsGetAllMempoolItemsMessage | WsGetAllMempoolTxIdsMessage | WsGetBlockMessage | WsGetBlockRecordByHeightMessage | WsGetBlockRecordMessage | WsGetBlockRecordsMessage | WsGetBlockSpendsMessage | WsGetBlockSpendsWithConditionsMessage | WsGetBlockchainStateMessage | WsGetBlocksMessage | WsGetBlockCountMetricsMessage | WsGetRecentSignagePointOrEOSCommandMessage | WsGetCoinRecordByNameMessage | WsGetCoinRecordsByNamesMessage | WsGetCoinRecordsByPuzzleHashMessage | WsGetCoinRecordsByPuzzleHashesMessage | WsGetCoinRecordsByParentIdsMessage | WsGetCoinRecordsByHintMessage | WsGetInitialFreezePeriodMessageOfFullNode | WsGetMempoolItemByTxIdMessage | WsGetMempoolItemsByCoinNameMessage | WsGetNetworkInfoMessageOfFullNode | WsGetNetworkSpaceMessage | WsGetUnfinishedBlockHeadersMessage | WsPushTxMessage | WsGetPuzzleAndSolutionMessage | WsGetFeeEstimateMessage | WsGetAllBlocksMessage | WsFarmBlockMessage | WsSetAutoFarmingMessage | WsGetAutoFarmingMessage | WsGetFarmingPhMessage | WsGetAllCoinsMessage | WsGetAllPuzzleHashesMessage | WsRevertBlocksMessage | WsReorgBlocksMessage;
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
exports.reorg_blocks = exports.reorg_blocks_command = exports.revert_blocks = exports.revert_blocks_command = exports.get_all_puzzle_hashes = exports.get_all_puzzle_hashes_command = exports.get_all_coins = exports.get_all_coins_command = exports.get_farming_ph = exports.get_farming_ph_command = exports.get_auto_farming = exports.get_auto_farming_command = exports.set_auto_farming = exports.set_auto_farming_command = exports.farm_block = exports.farm_block_command = exports.get_all_blocks = exports.get_all_blocks_command = exports.get_fee_estimate = exports.get_fee_estimate_command = exports.get_mempool_items_by_coin_name = exports.get_mempool_items_by_coin_name_command = exports.get_mempool_item_by_tx_id = exports.get_mempool_item_by_tx_id_command = exports.get_all_mempool_items = void 0;
|
|
12
|
+
exports.get_all_mempool_tx_ids_command = exports.get_puzzle_and_solution = exports.get_puzzle_and_solution_command = exports.push_tx = exports.push_tx_command = exports.get_coin_records_by_hint = exports.get_coin_records_by_hint_command = exports.get_coin_records_by_parent_ids = exports.get_coin_records_by_parent_ids_command = exports.get_coin_records_by_names = exports.get_coin_records_by_names_command = exports.get_coin_record_by_name = exports.get_coin_record_by_name_command = exports.get_coin_records_by_puzzle_hashes = exports.get_coin_records_by_puzzle_hashes_command = exports.get_coin_records_by_puzzle_hash = exports.get_coin_records_by_puzzle_hash_command = exports.get_recent_signage_point_or_eos = exports.get_recent_signage_point_or_eos_command = exports.get_network_info_of_full_node = exports.get_network_info_command_of_full_node = exports.get_initial_freeze_period_of_full_node = exports.get_initial_freeze_period_command_of_full_node = exports.get_aggsig_additional_data = exports.get_aggsig_additional_data_command = exports.get_additions_and_removals = exports.get_additions_and_removals_command = exports.get_network_space = exports.get_network_space_command = exports.get_unfinished_block_headers = exports.get_unfinished_block_headers_command = exports.get_block_spends_with_conditions = exports.get_block_spends_with_conditions_command = exports.get_block_spends = exports.get_block_spends_command = exports.get_block_records = exports.get_block_records_command = exports.get_block_record = exports.get_block_record_command = exports.get_block_record_by_height = exports.get_block_record_by_height_command = exports.get_block_count_metrics = exports.get_block_count_metrics_command = exports.get_blocks = exports.get_blocks_command = exports.get_block = exports.get_block_command = exports.get_blockchain_state = exports.get_blockchain_state_command = exports.chia_full_node_service = void 0;
|
|
13
|
+
exports.reorg_blocks = exports.reorg_blocks_command = exports.revert_blocks = exports.revert_blocks_command = exports.get_all_puzzle_hashes = exports.get_all_puzzle_hashes_command = exports.get_all_coins = exports.get_all_coins_command = exports.get_farming_ph = exports.get_farming_ph_command = exports.get_auto_farming = exports.get_auto_farming_command = exports.set_auto_farming = exports.set_auto_farming_command = exports.farm_block = exports.farm_block_command = exports.get_all_blocks = exports.get_all_blocks_command = exports.get_fee_estimate = exports.get_fee_estimate_command = exports.get_mempool_items_by_coin_name = exports.get_mempool_items_by_coin_name_command = exports.get_mempool_item_by_tx_id = exports.get_mempool_item_by_tx_id_command = exports.get_all_mempool_items = exports.get_all_mempool_items_command = exports.get_all_mempool_tx_ids = void 0;
|
|
14
14
|
exports.chia_full_node_service = "chia_full_node";
|
|
15
15
|
exports.get_blockchain_state_command = "get_blockchain_state";
|
|
16
16
|
function get_blockchain_state(agent) {
|
|
@@ -96,6 +96,13 @@ function get_additions_and_removals(agent, data) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
exports.get_additions_and_removals = get_additions_and_removals;
|
|
99
|
+
exports.get_aggsig_additional_data_command = "get_aggsig_additional_data";
|
|
100
|
+
function get_aggsig_additional_data(agent) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return agent.sendMessage(exports.chia_full_node_service, exports.get_aggsig_additional_data_command);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
exports.get_aggsig_additional_data = get_aggsig_additional_data;
|
|
99
106
|
exports.get_initial_freeze_period_command_of_full_node = "get_initial_freeze_period";
|
|
100
107
|
function get_initial_freeze_period_of_full_node(agent) {
|
|
101
108
|
return __awaiter(this, void 0, void 0, function* () {
|
package/api/rpc/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RpcFarmerMessage } from "./farmer/index";
|
|
2
2
|
export { chia_farmer_service, RpcFarmerMessage, TGetRewardTargetRequest, TGetRewardTargetResponse, get_reward_targets, TGetSignagePointRequest, TGetSignagePointResponse, get_signage_point, TGetSignagePointsRequest, TGetSignagePointsResponse, get_signage_points, TSetRewardTargetRequest, TSetRewardTargetResponse, set_reward_targets, TGetHarvestersRequest, TGetHarvestersResponse, get_harvesters, TGetHarvestersSummaryResponse, get_harvesters_summary, TGetHarvesterPlotsValidRequest, TGetHarvesterPlotsValidResponse, get_harvester_plots_valid, TGetHarvesterPlotsInvalidRequest, TGetHarvesterPlotsInvalidResponse, get_harvester_plots_invalid, TGetHarvesterPlotsKeysMissingRequest, TGetHarvesterPlotsKeysMissingResponse, get_harvester_plots_keys_missing, TGetHarvesterPlotsDuplicatesRequest, TGetHarvesterPlotsDuplicatesResponse, get_harvester_plots_duplicates, TSetPayoutInstructionsRequest, TSetPayoutInstructionsResponse, set_pool_payout_instructions, TGetPoolStateRequest, TGetPoolStateResponse, get_pool_state, TGetPoolLinkRequest, TGetPoolLinkResponse, get_pool_login_link, } from "./farmer/index";
|
|
3
3
|
import type { RpcFullNodeMessage } from "./full_node/index";
|
|
4
|
-
export { chia_full_node_service, TGetAdditionsAndRemovalsRequest, TGetAdditionsAndRemovalsResponse, get_additions_and_removals, TGetAllMempoolItemsRequest, TGetAllMempoolItemsResponse, get_all_mempool_items, TGetAllMempoolTxIdsRequest, TGetAllMempoolTxIdsResponse, get_all_mempool_tx_ids, TGetMempoolItemsByCoinNameRequest, TGetMempoolItemsByCoinNameResponse, get_mempool_items_by_coin_name, TGetBlockRecordByHeightRequest, TGetBlockRecordByHeightResponse, get_block_record_by_height, TGetBlockRecordRequest, TGetBlockRecordResponse, get_block_record, TGetBlockRecordsRequest, TGetBlockRecordsResponse, get_block_records, TGetBlockSpendsRequest, TGetBlockSpendsResponse, get_block_spends, TGetBlockSpendsWithConditionsRequest, TGetBlockSpendsWithConditionsResponse, get_block_spends_with_conditions, TGetBlockRequest, TGetBlockResponse, get_block, TGetBlockchainStateRequest, TGetBlockchainStateResponse, get_blockchain_state, TGetBlocksRequest, TGetBlocksResponse, get_blocks, TGetBlockCountMetricsResponse, get_block_count_metrics, TGetRecentSignagePointOrEOSCommandRequest, TGetRecentSignagePointOrEOSCommandResponse, get_recent_signage_point_or_eos, TGetCoinRecordsByNamesRequest, TGetCoinRecordsByNamesResponse, get_coin_records_by_names, TGetCoinRecordByNameRequest, TGetCoinRecordByNameResponse, get_coin_record_by_name, TGetCoinRecordsByPuzzleHashRequest, TGetCoinRecordsByPuzzleHashResponse, get_coin_records_by_puzzle_hash, TGetCoinRecordsByPuzzleHashesRequest, TGetCoinRecordsByPuzzleHashesResponse, get_coin_records_by_puzzle_hashes, TGetCoinRecordsByParentIdsRequest, TGetCoinRecordsByParentIdsResponse, get_coin_records_by_parent_ids, TGetCoinRecordsByHintRequest, TGetCoinRecordsByHintResponse, get_coin_records_by_hint, TGetInitialFreezePeriodRequestOfFullNode, TGetInitialFreezePeriodResponseOfFullNode, get_initial_freeze_period_of_full_node, TGetMempoolItemByTxIdRequest, TGetMempoolItemByTxIdResponse, get_mempool_item_by_tx_id, TGetNetworkInfoRequestOfFullNode, TGetNetworkInfoResponseOfFullNode, get_network_info_of_full_node, TGetNetworkSpaceRequest, TGetNetworkSpaceResponse, get_network_space, TGetUnfinishedBlockHeadersRequest, TGetUnfinishedBlockHeadersResponse, get_unfinished_block_headers, TPushTxRequest, TPushTxResponse, push_tx, TGetPuzzleAndSolutionRequest, TGetPuzzleAndSolutionResponse, get_puzzle_and_solution, TGetFeeEstimateRequest, TGetFeeEstimateResponse, get_fee_estimate, TGetAllBlocksResponse, get_all_blocks, TFarmBlockRequest as TFarmBlockFullNodeRequest, TFarmBlockResponse as TFarmBlockFullNodeResponse, farm_block as farm_block_fullnode, TSetAutoFarmingRequest, TSetAutoFarmingResponse, set_auto_farming, TGetAutoFarmingResponse, get_auto_farming, TGetFarmingPhResponse, get_farming_ph, TGetAllCoinsRequest, TGetAllCoinsResponse, get_all_coins, TGetAllPuzzleHashesResponse, get_all_puzzle_hashes, TRevertBlocksRequest, TRevertBlocksResponse, revert_blocks, TReorgBlocksRequest, TReorgBlocksResponse, reorg_blocks } from "./full_node/index";
|
|
4
|
+
export { chia_full_node_service, TGetAdditionsAndRemovalsRequest, TGetAdditionsAndRemovalsResponse, get_additions_and_removals, TGetAggsigAdditionalDataResponse, get_aggsig_additional_data, TGetAllMempoolItemsRequest, TGetAllMempoolItemsResponse, get_all_mempool_items, TGetAllMempoolTxIdsRequest, TGetAllMempoolTxIdsResponse, get_all_mempool_tx_ids, TGetMempoolItemsByCoinNameRequest, TGetMempoolItemsByCoinNameResponse, get_mempool_items_by_coin_name, TGetBlockRecordByHeightRequest, TGetBlockRecordByHeightResponse, get_block_record_by_height, TGetBlockRecordRequest, TGetBlockRecordResponse, get_block_record, TGetBlockRecordsRequest, TGetBlockRecordsResponse, get_block_records, TGetBlockSpendsRequest, TGetBlockSpendsResponse, get_block_spends, TGetBlockSpendsWithConditionsRequest, TGetBlockSpendsWithConditionsResponse, get_block_spends_with_conditions, TGetBlockRequest, TGetBlockResponse, get_block, TGetBlockchainStateRequest, TGetBlockchainStateResponse, get_blockchain_state, TGetBlocksRequest, TGetBlocksResponse, get_blocks, TGetBlockCountMetricsResponse, get_block_count_metrics, TGetRecentSignagePointOrEOSCommandRequest, TGetRecentSignagePointOrEOSCommandResponse, get_recent_signage_point_or_eos, TGetCoinRecordsByNamesRequest, TGetCoinRecordsByNamesResponse, get_coin_records_by_names, TGetCoinRecordByNameRequest, TGetCoinRecordByNameResponse, get_coin_record_by_name, TGetCoinRecordsByPuzzleHashRequest, TGetCoinRecordsByPuzzleHashResponse, get_coin_records_by_puzzle_hash, TGetCoinRecordsByPuzzleHashesRequest, TGetCoinRecordsByPuzzleHashesResponse, get_coin_records_by_puzzle_hashes, TGetCoinRecordsByParentIdsRequest, TGetCoinRecordsByParentIdsResponse, get_coin_records_by_parent_ids, TGetCoinRecordsByHintRequest, TGetCoinRecordsByHintResponse, get_coin_records_by_hint, TGetInitialFreezePeriodRequestOfFullNode, TGetInitialFreezePeriodResponseOfFullNode, get_initial_freeze_period_of_full_node, TGetMempoolItemByTxIdRequest, TGetMempoolItemByTxIdResponse, get_mempool_item_by_tx_id, TGetNetworkInfoRequestOfFullNode, TGetNetworkInfoResponseOfFullNode, get_network_info_of_full_node, TGetNetworkSpaceRequest, TGetNetworkSpaceResponse, get_network_space, TGetUnfinishedBlockHeadersRequest, TGetUnfinishedBlockHeadersResponse, get_unfinished_block_headers, TPushTxRequest, TPushTxResponse, push_tx, TGetPuzzleAndSolutionRequest, TGetPuzzleAndSolutionResponse, get_puzzle_and_solution, TGetFeeEstimateRequest, TGetFeeEstimateResponse, get_fee_estimate, TGetAllBlocksResponse, get_all_blocks, TFarmBlockRequest as TFarmBlockFullNodeRequest, TFarmBlockResponse as TFarmBlockFullNodeResponse, farm_block as farm_block_fullnode, TSetAutoFarmingRequest, TSetAutoFarmingResponse, set_auto_farming, TGetAutoFarmingResponse, get_auto_farming, TGetFarmingPhResponse, get_farming_ph, TGetAllCoinsRequest, TGetAllCoinsResponse, get_all_coins, TGetAllPuzzleHashesResponse, get_all_puzzle_hashes, TRevertBlocksRequest, TRevertBlocksResponse, revert_blocks, TReorgBlocksRequest, TReorgBlocksResponse, reorg_blocks } from "./full_node/index";
|
|
5
5
|
import type { RpcHarvesterMessage } from "./harvester/index";
|
|
6
6
|
export { chia_harvester_service, TAddPlotDirectoryRequest, TAddPlotDirectoryResponse, add_plot_directory, TDeletePlotRequest, TDeletePlotResponse, delete_plot, TGetPlotDirectoriesRequest, TGetPlotDirectoriesResponse, get_plot_directories, TGetPlotsRequest, TGetPlotsResponse, get_plots, TRefreshPlotsRequest, TRefreshPlotsResponse, refresh_plots, TRemovePlotDirectoryRequest, TRemovePlotDirectoryResponse, remove_plot_directory, TGetHarvesterConfigResponse, get_harvester_config, TUpdateHarvesterConfigRequest, TUpdateHarvesterConfigResponse, update_harvester_config, } from "./harvester/index";
|
|
7
7
|
import type { RpcWalletMessage } from "./wallet/index";
|
package/api/rpc/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.healthz = exports.get_routes = exports.stop_node = exports.close_connection = exports.open_connection = exports.get_connections = exports.chia_common_service = exports.get_peer_counts = exports.get_ips_after_timestamp = exports.chia_crawler_service = exports.clear_pending_roots = exports.check_plugins = exports.get_sync_status_dl = exports.cancel_offer_dl = exports.verify_offer = exports.take_offer_dl = exports.make_offer = exports.add_missing_files = exports.get_root_history = exports.get_kv_diff = exports.subscriptions = exports.remove_subscriptions = exports.get_mirrors = exports.delete_mirror = exports.add_mirror = exports.unsubscribe = exports.subscribe = exports.insert = exports.delete_key_dl = exports.get_roots = exports.get_local_root = exports.get_root = exports.get_ancestors = exports.get_keys_values = void 0;
|
|
3
|
+
exports.get_all_coins = exports.get_farming_ph = exports.get_auto_farming = exports.set_auto_farming = exports.farm_block_fullnode = exports.get_all_blocks = exports.get_fee_estimate = exports.get_puzzle_and_solution = exports.push_tx = exports.get_unfinished_block_headers = exports.get_network_space = exports.get_network_info_of_full_node = exports.get_mempool_item_by_tx_id = exports.get_initial_freeze_period_of_full_node = exports.get_coin_records_by_hint = exports.get_coin_records_by_parent_ids = exports.get_coin_records_by_puzzle_hashes = exports.get_coin_records_by_puzzle_hash = exports.get_coin_record_by_name = exports.get_coin_records_by_names = exports.get_recent_signage_point_or_eos = exports.get_block_count_metrics = exports.get_blocks = exports.get_blockchain_state = exports.get_block = exports.get_block_spends_with_conditions = exports.get_block_spends = exports.get_block_records = exports.get_block_record = exports.get_block_record_by_height = exports.get_mempool_items_by_coin_name = exports.get_all_mempool_tx_ids = exports.get_all_mempool_items = exports.get_aggsig_additional_data = exports.get_additions_and_removals = exports.chia_full_node_service = exports.get_pool_login_link = exports.get_pool_state = exports.set_pool_payout_instructions = exports.get_harvester_plots_duplicates = exports.get_harvester_plots_keys_missing = exports.get_harvester_plots_invalid = exports.get_harvester_plots_valid = exports.get_harvesters_summary = exports.get_harvesters = exports.set_reward_targets = exports.get_signage_points = exports.get_signage_point = exports.get_reward_targets = exports.chia_farmer_service = void 0;
|
|
4
|
+
exports.did_transfer_did = exports.did_create_backup_file = exports.did_create_attest = exports.did_get_wallet_name = exports.did_set_wallet_name = exports.delete_key = exports.set_wallet_resync_on_startup = exports.delete_all_keys = exports.nft_transfer_bulk = exports.nft_set_did_bulk = exports.nft_mint_bulk = exports.nft_calculate_royalties = exports.get_transaction_memo = exports.verify_signature = exports.sign_message_by_id = exports.sign_message_by_address = exports.send_notification = exports.delete_notifications = exports.get_notifications = exports.extend_derivation_index = exports.get_current_derivation_index = exports.select_coins = exports.delete_unconfirmed_transactions = exports.create_signed_transaction = exports.create_offer_for_ids = exports.create_new_wallet = exports.check_offer_validity = exports.cat_spend = exports.cat_set_name = exports.cat_asset_id_to_name = exports.get_stray_cats = exports.cat_get_name = exports.cat_get_asset_id = exports.cancel_offers = exports.cancel_offer = exports.add_rate_limited_funds = exports.add_key = exports.chia_wallet_service = exports.update_harvester_config = exports.get_harvester_config = exports.remove_plot_directory = exports.refresh_plots = exports.get_plots = exports.get_plot_directories = exports.delete_plot = exports.add_plot_directory = exports.chia_harvester_service = exports.reorg_blocks = exports.revert_blocks = exports.get_all_puzzle_hashes = void 0;
|
|
5
|
+
exports.get_network_info_of_wallet = exports.get_offer_summary = exports.get_offers_count = exports.get_offer = exports.get_logged_in_fingerprint = exports.get_initial_freeze_period_of_wallet = exports.get_height_info = exports.get_farmed_amount = exports.get_cat_list = exports.get_all_offers = exports.generate_mnemonic = exports.get_auto_claim = exports.set_auto_claim = exports.get_timestamp_for_height = exports.farm_block = exports.nft_add_uri = exports.nft_get_info = exports.nft_transfer_nft = exports.nft_set_nft_status = exports.nft_get_wallets_with_dids = exports.nft_get_wallet_did = exports.nft_get_by_did = exports.nft_set_nft_did = exports.nft_get_nfts = exports.nft_count_nfts = exports.nft_mint_nft = exports.dao_free_coins_from_finished_proposals = exports.dao_close_proposal = exports.dao_parse_proposal = exports.dao_vote_on_proposal = exports.dao_create_proposal = exports.dao_exit_lockup = exports.dao_get_proposal_state = exports.dao_get_proposals = exports.dao_send_to_lockup = exports.dao_get_rules = exports.dao_get_treasury_id = exports.dao_get_treasury_balance = exports.dao_add_funds_to_treasury = exports.dao_adjust_filter_level = exports.did_update_metadata = exports.did_update_recovery_ids = exports.did_spend = exports.did_recovery_spend = exports.did_get_metadata = exports.did_get_recovery_list = exports.did_get_pubkey = exports.did_get_current_coin_info = exports.did_get_information_needed_for_recovery = exports.did_get_did = void 0;
|
|
6
|
+
exports.get_value = exports.batch_update = exports.get_owned_stores = exports.create_data_store = exports.wallet_log_in = exports.chia_data_layer_service = exports.crcat_approve_pending = exports.vc_revoke = exports.vc_get_proofs_for_root = exports.vc_add_proofs = exports.vc_spend = exports.vc_get_list = exports.vc_get = exports.vc_mint = exports.dl_delete_mirror = exports.dl_new_mirror = exports.dl_get_mirrors = exports.dl_owned_singletons = exports.dl_history = exports.dl_update_multiple = exports.dl_update_root = exports.dl_singletons_by_root = exports.dl_latest_singleton = exports.dl_stop_tracking = exports.dl_track_new = exports.create_new_dl = exports.take_offer = exports.get_coin_records = exports.spend_clawback_coins = exports.send_transaction_multi = exports.send_transaction = exports.send_clawback_transaction = exports.rl_set_user_info = exports.pw_status = exports.pw_absorb_rewards = exports.pw_self_pool = exports.pw_join_pool = exports.push_transactions = exports.push_tx_wallet = exports.log_in = exports.get_wallets = exports.get_wallet_balances = exports.get_wallet_balance = exports.get_transactions = exports.get_transaction = exports.get_transaction_count = exports.get_sync_status = exports.get_public_keys = exports.get_private_key = exports.get_next_address = void 0;
|
|
7
|
+
exports.healthz = exports.get_routes = exports.stop_node = exports.close_connection = exports.open_connection = exports.get_connections = exports.chia_common_service = exports.get_peer_counts = exports.get_ips_after_timestamp = exports.chia_crawler_service = exports.clear_pending_roots = exports.check_plugins = exports.get_sync_status_dl = exports.cancel_offer_dl = exports.verify_offer = exports.take_offer_dl = exports.make_offer = exports.add_missing_files = exports.get_root_history = exports.get_kv_diff = exports.subscriptions = exports.remove_subscriptions = exports.get_mirrors = exports.delete_mirror = exports.add_mirror = exports.unsubscribe = exports.subscribe = exports.insert = exports.delete_key_dl = exports.get_roots = exports.get_local_root = exports.get_root = exports.get_ancestors = exports.get_keys_values = exports.get_keys = void 0;
|
|
8
8
|
var index_1 = require("./farmer/index");
|
|
9
9
|
Object.defineProperty(exports, "chia_farmer_service", { enumerable: true, get: function () { return index_1.chia_farmer_service; } });
|
|
10
10
|
Object.defineProperty(exports, "get_reward_targets", { enumerable: true, get: function () { return index_1.get_reward_targets; } });
|
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "get_pool_login_link", { enumerable: true, get: f
|
|
|
23
23
|
var index_2 = require("./full_node/index");
|
|
24
24
|
Object.defineProperty(exports, "chia_full_node_service", { enumerable: true, get: function () { return index_2.chia_full_node_service; } });
|
|
25
25
|
Object.defineProperty(exports, "get_additions_and_removals", { enumerable: true, get: function () { return index_2.get_additions_and_removals; } });
|
|
26
|
+
Object.defineProperty(exports, "get_aggsig_additional_data", { enumerable: true, get: function () { return index_2.get_aggsig_additional_data; } });
|
|
26
27
|
Object.defineProperty(exports, "get_all_mempool_items", { enumerable: true, get: function () { return index_2.get_all_mempool_items; } });
|
|
27
28
|
Object.defineProperty(exports, "get_all_mempool_tx_ids", { enumerable: true, get: function () { return index_2.get_all_mempool_tx_ids; } });
|
|
28
29
|
Object.defineProperty(exports, "get_mempool_items_by_coin_name", { enumerable: true, get: function () { return index_2.get_mempool_items_by_coin_name; } });
|
package/api/rpc/pool/index.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { str, uint64 } from "../../chia/types/_python_types_";
|
|
2
|
-
import {
|
|
2
|
+
import type { RPCAgent } from "../../../rpc";
|
|
3
3
|
import { ErrorResponse, GetFarmerResponse, GetPoolInfoResponse, PostFarmerRequest, PostFarmerResponse, PostPartialRequest, PostPartialResponse, PutFarmerRequest, PutFarmerResponse } from "../../chia/protocols/pool_protocol";
|
|
4
4
|
import { FarmerRecord } from "../../chia/pool/store";
|
|
5
5
|
export declare type TPoolInfoResponse = GetPoolInfoResponse;
|
|
6
|
-
export declare function pool_info(agent:
|
|
6
|
+
export declare function pool_info(agent: RPCAgent): Promise<GetPoolInfoResponse>;
|
|
7
7
|
export declare type TGetFarmerRequest = {
|
|
8
8
|
launcher_id: str;
|
|
9
9
|
authentication_token: str;
|
|
10
10
|
signature: str;
|
|
11
11
|
};
|
|
12
12
|
export declare type TGetFarmerResponse = GetFarmerResponse;
|
|
13
|
-
export declare function get_farmer(agent:
|
|
13
|
+
export declare function get_farmer(agent: RPCAgent, data: TGetFarmerRequest): Promise<GetFarmerResponse>;
|
|
14
14
|
export declare type TPostFarmerRequest = PostFarmerRequest;
|
|
15
15
|
export declare type TPostFarmerResponse = PostFarmerResponse | ErrorResponse;
|
|
16
|
-
export declare function post_farmer(agent:
|
|
16
|
+
export declare function post_farmer(agent: RPCAgent, data: TPostFarmerRequest): Promise<TPostFarmerResponse>;
|
|
17
17
|
export declare type TPutFarmerRequest = PutFarmerRequest;
|
|
18
18
|
export declare type TPutFarmerResponse = PutFarmerResponse | ErrorResponse;
|
|
19
|
-
export declare function put_farmer(agent:
|
|
19
|
+
export declare function put_farmer(agent: RPCAgent, data: TPutFarmerRequest): Promise<TPutFarmerResponse>;
|
|
20
20
|
export declare type TPartialRequest = PostPartialRequest;
|
|
21
21
|
export declare type TPartialResponse = PostPartialResponse | ErrorResponse;
|
|
22
|
-
export declare function partial(agent:
|
|
22
|
+
export declare function partial(agent: RPCAgent, data: TPartialRequest): Promise<TPartialResponse>;
|
|
23
23
|
export declare type TLoginRequest = {
|
|
24
24
|
launcher_id: str;
|
|
25
25
|
authentication_token: uint64;
|
|
@@ -29,4 +29,4 @@ export declare type TLoginResponse = {
|
|
|
29
29
|
farmer_record: FarmerRecord;
|
|
30
30
|
recent_partials: Array<[uint64, uint64]>;
|
|
31
31
|
} | {};
|
|
32
|
-
export declare function login(agent:
|
|
32
|
+
export declare function login(agent: RPCAgent, data: TLoginRequest): Promise<TLoginResponse>;
|
package/api/rpc/pool/index.js
CHANGED
|
@@ -18,19 +18,19 @@ function pool_info(agent) {
|
|
|
18
18
|
exports.pool_info = pool_info;
|
|
19
19
|
function get_farmer(agent, data) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
return agent.request("GET", "farmer");
|
|
21
|
+
return agent.request("GET", "farmer", data);
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
exports.get_farmer = get_farmer;
|
|
25
25
|
function post_farmer(agent, data) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
return agent.request("POST", "farmer");
|
|
27
|
+
return agent.request("POST", "farmer", data);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
exports.post_farmer = post_farmer;
|
|
31
31
|
function put_farmer(agent, data) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return agent.request("PUT", "farmer");
|
|
33
|
+
return agent.request("PUT", "farmer", data);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
exports.put_farmer = put_farmer;
|
package/api/types.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare type GetMessageType<O extends string, C extends string, D> = {
|
|
|
11
11
|
request_id: string;
|
|
12
12
|
destination: string;
|
|
13
13
|
};
|
|
14
|
-
export declare type ResType<T extends TRPCAgent | TDaemon, A, D> = T extends
|
|
14
|
+
export declare type ResType<T extends TRPCAgent | TDaemon, A, D> = T extends TDaemon ? D : A;
|
|
15
15
|
export declare const wallet_ui_service = "wallet_ui";
|
|
16
16
|
export declare const metrics_service = "metrics";
|
|
17
17
|
export declare type TConnectionGeneral = {
|
package/package.json
CHANGED
package/rpc/index.d.ts
CHANGED
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
import { Agent as HttpsAgent } from "https";
|
|
3
3
|
import { Agent as HttpAgent } from "http";
|
|
4
4
|
import { TConfig } from "../config/index";
|
|
5
|
+
import { APIAgent } from "../agent/index";
|
|
5
6
|
declare type TDestination = "farmer" | "harvester" | "full_node" | "wallet" | "data_layer" | "daemon" | "pool";
|
|
6
7
|
export declare function getConnectionInfoFromConfig(destination: TDestination, config: TConfig): {
|
|
7
8
|
hostname: string;
|
|
8
9
|
port: number;
|
|
9
10
|
};
|
|
11
|
+
export declare function getConf(configPath?: string): TConfig;
|
|
12
|
+
export declare function loadCertFilesFromConfig(config: TConfig): {
|
|
13
|
+
clientCert: Buffer;
|
|
14
|
+
clientKey: Buffer;
|
|
15
|
+
caCert: Buffer;
|
|
16
|
+
};
|
|
10
17
|
export declare type TRPCAgentProps = {
|
|
11
18
|
protocol: "https";
|
|
12
19
|
host: string;
|
|
@@ -47,29 +54,20 @@ export declare type TRPCAgentProps = {
|
|
|
47
54
|
keepAliveMsecs?: number;
|
|
48
55
|
maxSockets?: number;
|
|
49
56
|
timeout?: number;
|
|
57
|
+
} | {
|
|
58
|
+
httpsAgent: HttpsAgent;
|
|
59
|
+
skip_hostname_verification?: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
httpAgent: HttpAgent;
|
|
62
|
+
skip_hostname_verification?: boolean;
|
|
50
63
|
};
|
|
51
|
-
export declare class RPCAgent {
|
|
64
|
+
export declare class RPCAgent implements APIAgent {
|
|
52
65
|
protected _protocol: "http" | "https";
|
|
53
|
-
protected _hostname: string;
|
|
54
|
-
protected _port: number;
|
|
55
|
-
protected _caCert?: string | Buffer;
|
|
56
|
-
protected _clientCert?: string | Buffer;
|
|
57
|
-
protected _clientKey?: string | Buffer;
|
|
58
66
|
protected _agent: HttpsAgent | HttpAgent;
|
|
59
67
|
protected _skip_hostname_verification: boolean;
|
|
60
|
-
protected _keepAlive: boolean;
|
|
61
|
-
protected _keepAliveMsecs: number;
|
|
62
|
-
protected _maxSockets: number;
|
|
63
|
-
protected _timeout?: number;
|
|
64
68
|
constructor(props: TRPCAgentProps);
|
|
65
|
-
protected _getConfig(configPath?: string): TConfig;
|
|
66
|
-
protected _loadCertFilesFromConfig(config: TConfig): {
|
|
67
|
-
clientCert: Buffer;
|
|
68
|
-
clientKey: Buffer;
|
|
69
|
-
caCert: Buffer;
|
|
70
|
-
};
|
|
71
69
|
sendMessage<M extends unknown>(destination: string, command: string, data?: Record<string, unknown>): Promise<M>;
|
|
72
70
|
request<R>(method: string, path: string, data?: any): Promise<R>;
|
|
73
71
|
}
|
|
74
|
-
export declare type TRPCAgent =
|
|
72
|
+
export declare type TRPCAgent = APIAgent;
|
|
75
73
|
export {};
|
package/rpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RPCAgent = exports.getConnectionInfoFromConfig = void 0;
|
|
12
|
+
exports.RPCAgent = exports.loadCertFilesFromConfig = exports.getConf = exports.getConnectionInfoFromConfig = void 0;
|
|
13
13
|
const https_1 = require("https");
|
|
14
14
|
const http_1 = require("http");
|
|
15
15
|
const fs_1 = require("fs");
|
|
@@ -60,129 +60,135 @@ function getConnectionInfoFromConfig(destination, config) {
|
|
|
60
60
|
return { hostname, port };
|
|
61
61
|
}
|
|
62
62
|
exports.getConnectionInfoFromConfig = getConnectionInfoFromConfig;
|
|
63
|
+
function getConf(configPath) {
|
|
64
|
+
configPath = configPath || index_1.configPath;
|
|
65
|
+
if (!fs_1.existsSync(configPath)) {
|
|
66
|
+
logger_1.getLogger().error(`chia config file does not exist at: ${configPath}`);
|
|
67
|
+
throw new Error("chia config file Not Found.");
|
|
68
|
+
}
|
|
69
|
+
return index_1.getConfig(configPath);
|
|
70
|
+
}
|
|
71
|
+
exports.getConf = getConf;
|
|
72
|
+
function loadCertFilesFromConfig(config) {
|
|
73
|
+
const clientCertPath = index_1.resolveFromChiaRoot([config["/daemon_ssl/private_crt"]]);
|
|
74
|
+
const clientKeyPath = index_1.resolveFromChiaRoot([config["/daemon_ssl/private_key"]]);
|
|
75
|
+
const caCertPath = index_1.resolveFromChiaRoot([config["/private_ssl_ca/crt"]]);
|
|
76
|
+
logger_1.getLogger().debug(`Loading client cert file from ${clientCertPath}`);
|
|
77
|
+
logger_1.getLogger().debug(`Loading client key file from ${clientKeyPath}`);
|
|
78
|
+
logger_1.getLogger().debug(`Loading ca cert file from ${caCertPath}`);
|
|
79
|
+
const getCertOrKey = (path) => {
|
|
80
|
+
if (!fs_1.existsSync(path)) {
|
|
81
|
+
logger_1.getLogger().error(`ssl crt/key does not exist at: ${path}`);
|
|
82
|
+
throw new Error(`crt/key Not Found at ${path}`);
|
|
83
|
+
}
|
|
84
|
+
return fs_1.readFileSync(path);
|
|
85
|
+
};
|
|
86
|
+
const clientCert = getCertOrKey(clientCertPath);
|
|
87
|
+
const clientKey = getCertOrKey(clientKeyPath);
|
|
88
|
+
const caCert = getCertOrKey(caCertPath);
|
|
89
|
+
return { clientCert, clientKey, caCert };
|
|
90
|
+
}
|
|
91
|
+
exports.loadCertFilesFromConfig = loadCertFilesFromConfig;
|
|
63
92
|
const userAgent = "chia-agent/1.0.0";
|
|
64
93
|
class RPCAgent {
|
|
65
94
|
constructor(props) {
|
|
66
|
-
this._caCert = "";
|
|
67
|
-
this._clientCert = "";
|
|
68
|
-
this._clientKey = "";
|
|
69
95
|
this._skip_hostname_verification = false;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
96
|
+
if ("httpsAgent" in props) {
|
|
97
|
+
this._protocol = "https";
|
|
98
|
+
this._agent = props.httpsAgent;
|
|
99
|
+
this._skip_hostname_verification = Boolean(props.skip_hostname_verification);
|
|
100
|
+
}
|
|
101
|
+
else if ("httpAgent" in props) {
|
|
102
|
+
this._protocol = "http";
|
|
103
|
+
this._agent = props.httpAgent;
|
|
104
|
+
this._skip_hostname_verification = Boolean(props.skip_hostname_verification);
|
|
105
|
+
}
|
|
106
|
+
else if ("protocol" in props) {
|
|
75
107
|
this._protocol = props.protocol;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
props.
|
|
83
|
-
|
|
84
|
-
props.
|
|
108
|
+
const { host, port } = props;
|
|
109
|
+
let clientCert;
|
|
110
|
+
let clientKey;
|
|
111
|
+
let caCert;
|
|
112
|
+
const keepAlive = props.keepAlive !== false;
|
|
113
|
+
const keepAliveMsecs = typeof props.keepAliveMsecs === "number" && props.keepAliveMsecs > 0 ?
|
|
114
|
+
props.keepAliveMsecs : 1000;
|
|
115
|
+
const maxSockets = typeof props.maxSockets === "number" && props.maxSockets > 0 ?
|
|
116
|
+
props.maxSockets : Infinity;
|
|
117
|
+
const timeout = typeof props.timeout === "number" && props.timeout > 0 ?
|
|
118
|
+
props.timeout : undefined;
|
|
85
119
|
if (props.protocol === "https") {
|
|
86
120
|
if ("configPath" in props) {
|
|
87
|
-
const config =
|
|
88
|
-
const certs =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
121
|
+
const config = getConf(props.configPath);
|
|
122
|
+
const certs = loadCertFilesFromConfig(config);
|
|
123
|
+
clientCert = certs.clientCert;
|
|
124
|
+
clientKey = certs.clientKey;
|
|
125
|
+
caCert = certs.caCert;
|
|
92
126
|
this._skip_hostname_verification = Boolean(props.skip_hostname_verification);
|
|
93
127
|
}
|
|
94
128
|
else {
|
|
95
|
-
|
|
96
|
-
this._clientCert = props.client_cert;
|
|
97
|
-
this._clientKey = props.client_key;
|
|
129
|
+
({ client_cert: clientCert, client_key: clientKey, ca_cert: caCert } = props);
|
|
98
130
|
this._skip_hostname_verification = Boolean(props.skip_hostname_verification);
|
|
99
131
|
}
|
|
100
132
|
this._agent = new https_1.Agent({
|
|
101
|
-
host
|
|
102
|
-
port
|
|
103
|
-
ca:
|
|
104
|
-
cert:
|
|
105
|
-
key:
|
|
106
|
-
rejectUnauthorized: Boolean(
|
|
107
|
-
keepAlive
|
|
108
|
-
keepAliveMsecs
|
|
109
|
-
maxSockets
|
|
110
|
-
timeout
|
|
133
|
+
host,
|
|
134
|
+
port,
|
|
135
|
+
ca: caCert,
|
|
136
|
+
cert: clientCert,
|
|
137
|
+
key: clientKey,
|
|
138
|
+
rejectUnauthorized: Boolean(caCert) && host !== "localhost",
|
|
139
|
+
keepAlive,
|
|
140
|
+
keepAliveMsecs,
|
|
141
|
+
maxSockets,
|
|
142
|
+
timeout,
|
|
111
143
|
});
|
|
112
144
|
}
|
|
113
145
|
else {
|
|
114
146
|
this._agent = new http_1.Agent({
|
|
115
|
-
keepAlive
|
|
116
|
-
keepAliveMsecs
|
|
117
|
-
maxSockets
|
|
118
|
-
timeout
|
|
147
|
+
keepAlive,
|
|
148
|
+
keepAliveMsecs,
|
|
149
|
+
maxSockets,
|
|
150
|
+
timeout,
|
|
119
151
|
});
|
|
120
152
|
}
|
|
121
153
|
}
|
|
122
154
|
else {
|
|
123
155
|
this._protocol = "https";
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
156
|
+
let host;
|
|
157
|
+
let port;
|
|
158
|
+
const keepAlive = props.keepAlive !== false;
|
|
159
|
+
const keepAliveMsecs = typeof props.keepAliveMsecs === "number" && props.keepAliveMsecs > 0 ?
|
|
160
|
+
props.keepAliveMsecs : 1000;
|
|
161
|
+
const maxSockets = typeof props.maxSockets === "number" && props.maxSockets > 0 ?
|
|
162
|
+
props.maxSockets : Infinity;
|
|
163
|
+
const timeout = typeof props.timeout === "number" && props.timeout > 0 ?
|
|
164
|
+
props.timeout : undefined;
|
|
165
|
+
const config = getConf("configPath" in props ? props.configPath : undefined);
|
|
130
166
|
if (props.host && typeof props.port === "number") {
|
|
131
|
-
|
|
132
|
-
this._port = props.port;
|
|
167
|
+
({ host, port } = props);
|
|
133
168
|
}
|
|
134
169
|
else {
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
170
|
+
const info = getConnectionInfoFromConfig(props.service, config);
|
|
171
|
+
host = props.host ? props.host : info.hostname;
|
|
172
|
+
port = typeof props.port === "number" ? props.port : info.port;
|
|
138
173
|
}
|
|
139
|
-
logger_1.getLogger().debug(`Picked ${
|
|
140
|
-
const certs =
|
|
141
|
-
|
|
142
|
-
this._clientKey = certs.clientKey;
|
|
143
|
-
this._caCert = certs.caCert;
|
|
174
|
+
logger_1.getLogger().debug(`Picked ${host}:${port} for ${props.service}`);
|
|
175
|
+
const certs = loadCertFilesFromConfig(config);
|
|
176
|
+
const { clientCert, clientKey, caCert } = certs;
|
|
144
177
|
this._skip_hostname_verification = Boolean(props.skip_hostname_verification);
|
|
145
178
|
this._agent = new https_1.Agent({
|
|
146
|
-
host:
|
|
147
|
-
port:
|
|
148
|
-
ca:
|
|
149
|
-
cert:
|
|
150
|
-
key:
|
|
151
|
-
rejectUnauthorized: Boolean(
|
|
152
|
-
keepAlive
|
|
153
|
-
keepAliveMsecs
|
|
154
|
-
maxSockets
|
|
155
|
-
timeout
|
|
179
|
+
host: host,
|
|
180
|
+
port: port,
|
|
181
|
+
ca: caCert,
|
|
182
|
+
cert: clientCert,
|
|
183
|
+
key: clientKey,
|
|
184
|
+
rejectUnauthorized: Boolean(caCert) && host !== "localhost",
|
|
185
|
+
keepAlive,
|
|
186
|
+
keepAliveMsecs,
|
|
187
|
+
maxSockets,
|
|
188
|
+
timeout,
|
|
156
189
|
});
|
|
157
190
|
}
|
|
158
191
|
}
|
|
159
|
-
_getConfig(configPath) {
|
|
160
|
-
configPath = configPath || index_1.configPath;
|
|
161
|
-
if (!fs_1.existsSync(configPath)) {
|
|
162
|
-
logger_1.getLogger().error(`chia config file does not exist at: ${configPath}`);
|
|
163
|
-
throw new Error("chia config file Not Found.");
|
|
164
|
-
}
|
|
165
|
-
return index_1.getConfig(configPath);
|
|
166
|
-
}
|
|
167
|
-
_loadCertFilesFromConfig(config) {
|
|
168
|
-
const clientCertPath = index_1.resolveFromChiaRoot([config["/daemon_ssl/private_crt"]]);
|
|
169
|
-
const clientKeyPath = index_1.resolveFromChiaRoot([config["/daemon_ssl/private_key"]]);
|
|
170
|
-
const caCertPath = index_1.resolveFromChiaRoot([config["/private_ssl_ca/crt"]]);
|
|
171
|
-
logger_1.getLogger().debug(`Loading client cert file from ${clientCertPath}`);
|
|
172
|
-
logger_1.getLogger().debug(`Loading client key file from ${clientKeyPath}`);
|
|
173
|
-
logger_1.getLogger().debug(`Loading ca cert file from ${caCertPath}`);
|
|
174
|
-
const getCertOrKey = (path) => {
|
|
175
|
-
if (!fs_1.existsSync(path)) {
|
|
176
|
-
logger_1.getLogger().error(`ssl crt/key does not exist at: ${path}`);
|
|
177
|
-
throw new Error(`crt/key Not Found at ${path}`);
|
|
178
|
-
}
|
|
179
|
-
return fs_1.readFileSync(path);
|
|
180
|
-
};
|
|
181
|
-
const clientCert = getCertOrKey(clientCertPath);
|
|
182
|
-
const clientKey = getCertOrKey(clientKeyPath);
|
|
183
|
-
const caCert = getCertOrKey(caCertPath);
|
|
184
|
-
return { clientCert, clientKey, caCert };
|
|
185
|
-
}
|
|
186
192
|
sendMessage(destination, command, data) {
|
|
187
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
194
|
// parameter `destination` is not used because target rpc server is determined by url.
|
|
@@ -197,9 +203,6 @@ class RPCAgent {
|
|
|
197
203
|
const pathname = `/${path.replace(/^\/+/, "")}`;
|
|
198
204
|
const METHOD = method.toUpperCase();
|
|
199
205
|
const options = {
|
|
200
|
-
protocol: this._protocol + ":",
|
|
201
|
-
hostname: this._hostname,
|
|
202
|
-
port: `${this._port}`,
|
|
203
206
|
path: pathname,
|
|
204
207
|
method: METHOD,
|
|
205
208
|
agent: this._agent,
|