From b92b718b31be8a8aac44e82bef84e77905180e91 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 1 Aug 2022 15:06:34 +0800 Subject: [PATCH] Move sender::Params to Configuration --- bip78/src/lib.rs | 2 ++ bip78/src/sender/mod.rs | 12 ++++++------ bip78/src/uri.rs | 4 ++-- bip78/tests/integration.rs | 2 +- payjoin-client/src/main.rs | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bip78/src/lib.rs b/bip78/src/lib.rs index 118d2aae..19d5bb4f 100644 --- a/bip78/src/lib.rs +++ b/bip78/src/lib.rs @@ -32,6 +32,8 @@ pub(crate) mod weight; #[cfg(any(feature = "sender", feature = "receiver"))] pub(crate) mod fee_rate; #[cfg(any(feature = "sender", feature = "receiver"))] +pub(crate) mod params; +#[cfg(any(feature = "sender", feature = "receiver"))] pub(crate) mod psbt; pub use uri::{Uri, PjUri, UriExt, PjUriExt, PjParseError}; diff --git a/bip78/src/sender/mod.rs b/bip78/src/sender/mod.rs index 0806cbac..6beb1286 100644 --- a/bip78/src/sender/mod.rs +++ b/bip78/src/sender/mod.rs @@ -36,14 +36,14 @@ type InternalResult = Result; /// Builder for sender-side payjoin parameters /// /// These parameters define how client wants to handle PayJoin. -pub struct Params { +pub struct Configuration { disable_output_substitution: bool, fee_contribution: Option<(bitcoin::Amount, Option)>, clamp_fee_contribution: bool, min_fee_rate: FeeRate, } -impl Params { +impl Configuration { /// Offer the receiver contribution to pay for his input. /// /// These parameters will allow the receiver to take `max_fee_contribution` from given change @@ -52,7 +52,7 @@ impl Params { /// `change_index` specifies which output can be used to pay fee. I `None` is provided, then /// the output is auto-detected unless the supplied transaction has more than two outputs. pub fn with_fee_contribution(max_fee_contribution: bitcoin::Amount, change_index: Option) -> Self { - Params { + Configuration { disable_output_substitution: false, fee_contribution: Some((max_fee_contribution, change_index)), clamp_fee_contribution: false, @@ -65,7 +65,7 @@ impl Params { /// While it's generally better to offer some contribution some users may wish not to. /// This function disables contribution. pub fn non_incentivizing() -> Self { - Params { + Configuration { disable_output_substitution: false, fee_contribution: None, clamp_fee_contribution: false, @@ -432,7 +432,7 @@ fn check_change_index(psbt: &Psbt, payee: &Script, fee: bitcoin::Amount, index: Ok((check_fee_output_amount(output, fee, clamp_fee_contribution)?, index)) } -fn determine_fee_contribution(psbt: &Psbt, payee: &Script, params: &Params) -> Result, InternalCreateRequestError> { +fn determine_fee_contribution(psbt: &Psbt, payee: &Script, params: &Configuration) -> Result, InternalCreateRequestError> { Ok(match params.fee_contribution { Some((fee, None)) => find_change_index(psbt, payee, fee, params.clamp_fee_contribution)?, Some((fee, Some(index))) => Some(check_change_index(psbt, payee, fee, index, params.clamp_fee_contribution)?), @@ -475,7 +475,7 @@ fn serialize_psbt(psbt: &Psbt) -> Vec { .expect("Vec doesn't return errors in its write implementation") } -pub(crate) fn from_psbt_and_uri(mut psbt: Psbt, uri: crate::uri::PjUri<'_>, params: Params) -> Result<(Request, Context), CreateRequestError> { +pub(crate) fn from_psbt_and_uri(mut psbt: Psbt, uri: crate::uri::PjUri<'_>, params: Configuration) -> Result<(Request, Context), CreateRequestError> { psbt .validate_input_utxos(true) .map_err(InternalCreateRequestError::InvalidOriginalInput)?; diff --git a/bip78/src/uri.rs b/bip78/src/uri.rs index 49495a97..4b798515 100644 --- a/bip78/src/uri.rs +++ b/bip78/src/uri.rs @@ -40,7 +40,7 @@ pub trait PjUriExt: sealed::UriExt { fn create_pj_request( self, psbt: bitcoin::util::psbt::PartiallySignedTransaction, - params: sender::Params, + params: sender::Configuration, ) -> Result<(sender::Request, sender::Context), sender::CreateRequestError>; } @@ -53,7 +53,7 @@ impl<'a> PjUriExt for PjUri<'a> { fn create_pj_request( self, psbt: bitcoin::util::psbt::PartiallySignedTransaction, - params: sender::Params, + params: sender::Configuration, ) -> Result<(sender::Request, sender::Context), sender::CreateRequestError> { sender::from_psbt_and_uri(psbt.try_into().map_err(sender::InternalCreateRequestError::InconsistentOriginalPsbt)?, self, params) } diff --git a/bip78/tests/integration.rs b/bip78/tests/integration.rs index fa45a84e..cabebbe8 100644 --- a/bip78/tests/integration.rs +++ b/bip78/tests/integration.rs @@ -69,7 +69,7 @@ mod integration { .psbt; let psbt = load_psbt_from_base64(psbt.as_bytes()).unwrap(); debug!("Original psbt: {:#?}", psbt); - let pj_params = bip78::sender::Params::with_fee_contribution(bip78::bitcoin::Amount::from_sat(10000), None); + let pj_params = bip78::sender::Configuration::with_fee_contribution(bip78::bitcoin::Amount::from_sat(10000), None); let (req, ctx) = pj_uri.create_request(psbt, pj_params).unwrap(); let headers = MockHeaders::from_vec(&req.body); diff --git a/payjoin-client/src/main.rs b/payjoin-client/src/main.rs index e43f83a5..bac6aecd 100644 --- a/payjoin-client/src/main.rs +++ b/payjoin-client/src/main.rs @@ -57,7 +57,7 @@ fn main() { .psbt; let psbt = load_psbt_from_base64(psbt.as_bytes()).unwrap(); println!("Original psbt: {:#?}", psbt); - let pj_params = bip78::sender::Params::with_fee_contribution(bip78::bitcoin::Amount::from_sat(10000), None); + let pj_params = bip78::sender::Configuration::with_fee_contribution(bip78::bitcoin::Amount::from_sat(10000), None); let (req, ctx) = link.create_pj_request(psbt, pj_params).unwrap(); let response = reqwest::blocking::Client::new() .post(req.url)