Add fee estimation RPC method and CLI command #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add fee estimation RPC method and CLI command
Summary
This PR adds fee estimation capabilities to spaced, allowing users to query Bitcoin fee estimates through both RPC and command-line interfaces. Previously, fee estimation was only available internally when wallet operations needed it, requiring users to call Bitcoin Core directly for fee information.
Features Added
1. RPC Method:
estimatefeeA new RPC method that exposes Bitcoin Core's
estimatesmartfeefunctionality through spaced, with automatic conversion from BTC/kB to sat/vB for consistency.Parameters:
conf_target(u32): Target number of blocks for confirmation (1-1008)estimate_mode(Option): Fee estimation mode -"unset","conservative", or"economical"(defaults to"unset")Response:
{ "feerate_sat_vb": 1, "blocks": 6 }2. CLI Command:
space-cli estimatefeeA new command-line subcommand for easy fee estimation access.
Usage:
Changes
client/src/rpc.rsFeeEstimateResponsestruct withfeerate_sat_vbandblocksfieldsestimate_feemethod toRpctraitestimate_feeinRpcServerImpl:tokio::task::spawn_blockingto handle blocking Bitcoin RPC calls in async contextestimatesmartfeeRPCclient/src/bin/space-cli.rsEstimateFeevariant toCommandsenumImplementation Details
(fee_rate * 100_000.0).ceil() as u64spawn_blockingto handle blocking RPC calls without blocking the async runtimeRpcWallet::estimate_fee_rate()Usage Examples
RPC Call
{ "jsonrpc": "2.0", "id": "1", "method": "estimatefee", "params": [6, "unset"] }CLI Output (Text)
CLI Output (JSON)
{ "feerate_sat_vb": 1, "blocks": 6 }Benefits
Testing
Impact
Related Documentation
See
example_fee_estimation_rpc.mdfor comprehensive examples and usage instructions covering:PR_ESTIMATEFEE.md
example_fee_estimation_rpc.md