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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -148,6 +148,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -592,6 +592,19 @@ macro_rules! impl_client_v17__send_to_address {
};
}

/// 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.

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 @@ -165,6 +165,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -161,6 +161,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -158,6 +158,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -160,6 +160,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -160,6 +160,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -162,6 +162,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -159,6 +159,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -159,6 +159,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -165,6 +165,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -161,6 +161,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -163,6 +163,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -163,6 +163,7 @@ crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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("fee_rate");
Copy link
Member

Choose a reason for hiding this comment

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

Since you have to rebase anyways can you change this to

Suggested change
let fee_rate = FeeRate::from_sat_per_vb(2).expect("fee_rate");
let fee_rate = FeeRate::from_sat_per_vb(2).expect("2 sat/vb is valid");

The idea being the expect message is basically a comment to those reading the code and is never going to be hit at runtime.


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 @@ -267,7 +267,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