Skip to content

Implement settxfee method and test #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v17__unload_wallet!();
Expand Down
13 changes: 13 additions & 0 deletions client/src/client_sync/v17/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ macro_rules! impl_client_v17__set_hd_seed {
};
}

/// Implements Bitcoin Core JSON-RPC API method `settxfee`
#[macro_export]
macro_rules! impl_client_v17__set_tx_fee {
() => {
impl Client {
pub fn set_tx_fee(&self, fee_rate: bitcoin::FeeRate) -> Result<SetTxFee> {
let fee_rate_btc_kvb = fee_rate.to_sat_per_vb_floor() as f64 / 100_000.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct and drinks on me because you found an API hole in rust-bitcoin. See rust-bitcoin/rust-bitcoin#4688 if you are interested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woaw, interesting, reading through the issue and conversations.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly copilot picked this out as an issue with the PR: although mathematically correct, it says "rust-bitcoin does not provide a safe, explicit conversion between FeeRate and the units expected by Core's settxfee". It managed to actually look at the referenced issue and give a sane answer. It has improved even in the last 6 months. Still can't trust it though 😊.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mad, keep me posted of any AI wins please. I"m a bit of a ludite and I don't want to fall too far behind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly copilot picked this out as an issue with the PR: although mathematically correct, it says "rust-bitcoin does not provide a safe, explicit conversion between FeeRate and the units expected by Core's settxfee". It managed to actually look at the referenced issue and give a sane answer. It has improved even in the last 6 months. Still can't trust it though 😊.

Woah, that’s cool. They’ve definitely come a long way...

self.call("settxfee", &[fee_rate_btc_kvb.into()])
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `signmessage`.
#[macro_export]
macro_rules! impl_client_v17__sign_message {
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v17__unload_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
Expand Down
11 changes: 10 additions & 1 deletion integration_test/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#[cfg(feature = "TODO")]
use bitcoin::address::{Address, NetworkChecked};
use bitcoin::{Amount, PrivateKey, PublicKey};
use bitcoin::{Amount, FeeRate, PrivateKey, PublicKey};
use integration_test::{Node, NodeExt as _, Wallet};
use node::{mtype, AddressType, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp};
use node::vtype::*; // All the version specific types.
Expand Down Expand Up @@ -558,6 +558,15 @@ fn wallet__send_to_address__modelled() {
model.unwrap();
}

#[test]
fn wallet__set_tx_fee() {
let node = Node::with_wallet(Wallet::Default, &[]);
let fee_rate = FeeRate::from_sat_per_vb(2).expect("2 sat/vb is valid");

let json: SetTxFee = node.client.set_tx_fee(fee_rate).expect("settxfee");
assert!(json.0);
}

#[cfg(not(feature = "v18_and_below"))]
#[test]
fn wallet__set_wallet_flag() {
Expand Down
4 changes: 2 additions & 2 deletions types/src/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
//! | sendtoaddress | version + model | |
//! | setaccount | returns nothing | |
//! | sethdseed | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
//! | unloadwallet | returns nothing | |
Expand Down Expand Up @@ -284,7 +284,7 @@ pub use self::{
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspent, ListUnspentItem,
ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, RescanBlockchain, SendMany,
SendToAddress, SignMessage, TransactionCategory, WalletCreateFundedPsbt,
SendToAddress, SetTxFee, SignMessage, TransactionCategory, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt,
},
zmq::GetZmqNotifications,
Expand Down
9 changes: 9 additions & 0 deletions types/src/v17/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,15 @@ impl SendToAddress {
pub fn txid(self) -> Result<Txid, hex::HexToArrayError> { Ok(self.into_model()?.txid) }
}

/// Result of JSON-RPC method `settxfee`.
///
/// > settxfee
/// >
/// > Arguments:
/// > 1. amount (numeric or string, required) The transaction fee in BTC/kB
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SetTxFee(pub bool);

/// Result of the JSON-RPC method `signmessage`.
///
/// > signmessage "address" "message"
Expand Down
10 changes: 5 additions & 5 deletions types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
//! | unloadwallet | returns nothing | |
Expand Down Expand Up @@ -277,9 +277,9 @@ pub use crate::v17::{
Logging, MapMempoolEntryError, MempoolAcceptance, MempoolEntryError, MempoolEntryFees,
MempoolEntryFeesError, PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript, RawTransaction,
RawTransactionError, RawTransactionInput, RawTransactionOutput, RescanBlockchain, SendMany,
SendRawTransaction, SendToAddress, SetNetworkActive, SignFail, SignFailError, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, Softfork, SoftforkReject,
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError,
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignFail, SignFailError,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, Softfork,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
};
4 changes: 2 additions & 2 deletions types/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand Down Expand Up @@ -277,7 +277,7 @@ pub use crate::v17::{
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet,
LockUnspent, Locked, Logging, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget,
ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof,
WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand Down Expand Up @@ -269,7 +269,7 @@ pub use crate::{
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand Down Expand Up @@ -273,7 +273,7 @@ pub use crate::{
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand Down Expand Up @@ -283,7 +283,7 @@ pub use crate::{
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand Down Expand Up @@ -282,7 +282,7 @@ pub use crate::{
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
//! | sendtoaddress | version + model | |
//! | sethdseed | returns nothing | |
//! | setlabel | returns nothing | |
//! | settxfee | returns boolean | |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand Down Expand Up @@ -284,7 +284,7 @@ pub use crate::{
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
Expand Down
Loading