Skip to content

Commit

Permalink
Log warnings in release
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Oct 27, 2022
1 parent 98fb17f commit d8294b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bip78/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ base64 = "0.13.0"
rand = { version = "0.8.4", optional = true }
bip21 = "0.1.1"
url = "2.2.2"
log = { version = "0.4.14", optional = true }

[dev-dependencies]
bitcoind = { version = "0.18.0", features = ["0_21_1"] }
env_logger = "0.9.0"
log = "0.4.14"
12 changes: 12 additions & 0 deletions bip78/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ pub(crate) mod params;
pub(crate) mod psbt;

pub use uri::{Uri, PjUri, UriExt, PjUriExt, PjParseError};

#[cfg(feature = "log")]
macro_rules! log_warn {
($($args:tt)*) => { log::warn!($($args)*) }
}

#[cfg(not(feature = "log"))]
macro_rules! log_warn {
($($args:tt)*) => {}
}
pub(crate) use log_warn;

26 changes: 20 additions & 6 deletions bip78/src/params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Borrow;
use std::fmt;

use crate::log_warn;
use crate::fee_rate::FeeRate;

#[derive(Debug)]
Expand Down Expand Up @@ -44,25 +45,38 @@ impl Params {
return Err(ParamsError::UnknownVersion)
},
("additionalfeeoutputindex", index) => {
if let Ok(index) = index.parse::<usize>() {
additional_fee_output_index = Some(index);
additional_fee_output_index = match index.parse::<usize>() {
Ok(index) => Some(index),
Err(_error) => {
log_warn!("bad `additionalfeeoutputindex` query value '{}': {}", index, _error);
None
}
}
},
("maxadditionalfeecontribution", fee) => {
max_additional_fee_contribution = bitcoin::Amount::from_str_in(&fee, bitcoin::Denomination::Bitcoin).ok();
max_additional_fee_contribution = match bitcoin::Amount::from_str_in(&fee, bitcoin::Denomination::Bitcoin) {
Ok(contribution) => Some(contribution),
Err(_error) => {
log_warn!("bad `maxadditionalfeecontribution` query value '{}': {}", fee, _error);
None
}
}
}
("minfeerate", feerate) => {
params.min_feerate = match feerate.parse::<u64>() {
Ok(rate) => FeeRate::from_sat_per_vb(rate),
Err(e) => return Err(ParamsError::FeeRate(e)),
}
}
("disableoutputsubstitution", v) => params.disable_output_substitution = v == "true", // existance is truthy
("disableoutputsubstitution", v) => params.disable_output_substitution = v == "true",
_ => (),
}
}
if let (Some(amount), Some(index)) = (max_additional_fee_contribution, additional_fee_output_index) {
params.additional_fee_contribution = Some((amount, index));

match (max_additional_fee_contribution, additional_fee_output_index) {
(Some(amount), Some(index)) => params.additional_fee_contribution = Some((amount, index)),
(Some(_), None) | (None, Some(_)) => { log_warn!("only one parameter specified: {}", params); },
_ => ()
}

Ok(params)
Expand Down

0 comments on commit d8294b9

Please sign in to comment.