Skip to content

Commit

Permalink
add: maxfeerate & maxburnamount to sendrawtransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
0xB10C committed Dec 20, 2023
1 parent 1b51e3d commit 6a504fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,16 @@ pub trait RpcApi: Sized {
self.call("ping", &[])
}

fn send_raw_transaction<R: RawTx>(&self, tx: R) -> Result<bitcoin::Txid> {
self.call("sendrawtransaction", &[tx.raw_hex().into()])
fn send_raw_transaction<R: RawTx>(&self, tx: R, maxfeerate: Option<Amount>, maxburnamount: Option<Amount>) -> Result<bitcoin::Txid> {
let maxfeerate_sat: Option<f64> = match maxfeerate {
Some(maxfeerate) => Some(maxfeerate.to_btc()),
None => None,
};
let maxburn_sat: Option<f64> = match maxburnamount {
Some(maxburnamount) => Some(maxburnamount.to_btc()),
None => None,
};
self.call("sendrawtransaction", &[tx.raw_hex().into(), opt_into_json(maxfeerate_sat)?, opt_into_json(maxburn_sat)?])
}

fn estimate_smart_fee(
Expand Down Expand Up @@ -1365,10 +1373,10 @@ mod tests {
let client = Client::new("http://localhost/".into(), Auth::None).unwrap();
let tx: bitcoin::Transaction = encode::deserialize(&Vec::<u8>::from_hex("0200000001586bd02815cf5faabfec986a4e50d25dbee089bd2758621e61c5fab06c334af0000000006b483045022100e85425f6d7c589972ee061413bcf08dc8c8e589ce37b217535a42af924f0e4d602205c9ba9cb14ef15513c9d946fa1c4b797883e748e8c32171bdf6166583946e35c012103dae30a4d7870cd87b45dd53e6012f71318fdd059c1c2623b8cc73f8af287bb2dfeffffff021dc4260c010000001976a914f602e88b2b5901d8aab15ebe4a97cf92ec6e03b388ac00e1f505000000001976a914687ffeffe8cf4e4c038da46a9b1d37db385a472d88acfd211500").unwrap()).unwrap();

assert!(client.send_raw_transaction(&tx).is_err());
assert!(client.send_raw_transaction(&encode::serialize(&tx)).is_err());
assert!(client.send_raw_transaction("deadbeef").is_err());
assert!(client.send_raw_transaction("deadbeef".to_owned()).is_err());
assert!(client.send_raw_transaction(&tx, None, None).is_err());
assert!(client.send_raw_transaction(&encode::serialize(&tx), None, None).is_err());
assert!(client.send_raw_transaction("deadbeef", None, None).is_err());
assert!(client.send_raw_transaction("deadbeef".to_owned(), None, None).is_err());
}

fn test_handle_defaults_inner() -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
};
let res = cl.sign_raw_transaction_with_wallet(&tx, Some(&[input]), None).unwrap();
assert!(res.complete);
let txid = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap();
let txid = cl.send_raw_transaction(&res.transaction().unwrap(), None, None).unwrap();

let tx = Transaction {
version: transaction::Version::ONE,
Expand All @@ -634,7 +634,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
.sign_raw_transaction_with_key(&tx, &[sk], None, Some(sighash::EcdsaSighashType::All.into()))
.unwrap();
assert!(res.complete);
let _ = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap();
let _ = cl.send_raw_transaction(&res.transaction().unwrap(), None, None).unwrap();
}

fn test_invalidate_block_reconsider_block(cl: &Client) {
Expand Down

0 comments on commit 6a504fa

Please sign in to comment.