Skip to content

Commit

Permalink
Move sender::Params to Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Oct 27, 2022
1 parent 541501d commit a5f5b26
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions bip78/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
12 changes: 6 additions & 6 deletions bip78/src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ type InternalResult<T> = Result<T, InternalValidationError>;
/// 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<usize>)>,
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
Expand All @@ -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<usize>) -> Self {
Params {
Configuration {
disable_output_substitution: false,
fee_contribution: Some((max_fee_contribution, change_index)),
clamp_fee_contribution: false,
Expand All @@ -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,
Expand Down Expand Up @@ -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<Option<(bitcoin::Amount, usize)>, InternalCreateRequestError> {
fn determine_fee_contribution(psbt: &Psbt, payee: &Script, params: &Configuration) -> Result<Option<(bitcoin::Amount, usize)>, 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)?),
Expand Down Expand Up @@ -475,7 +475,7 @@ fn serialize_psbt(psbt: &Psbt) -> Vec<u8> {
.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)?;
Expand Down
4 changes: 2 additions & 2 deletions bip78/src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion bip78/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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 = HeaderMock::from_vec(&req.body);

Expand Down
2 changes: 1 addition & 1 deletion payjoin-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a5f5b26

Please sign in to comment.