Skip to content

Commit

Permalink
code formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
BitcoinZavior committed Jul 18, 2024
1 parent cde4354 commit 93ded99
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum PayjoinError {
PjParseError { message: String },

#[error("{message}")]
PjNotSupported{ message: String },
PjNotSupported { message: String },

#[error("Malformed response from receiver: {message}")]
ValidationError { message: String },
Expand Down
7 changes: 5 additions & 2 deletions src/receive/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ impl MaybeInputsOwned {
self.0
.clone()
.check_inputs_not_owned(|input| {
is_owned(&input.to_bytes()).map_err(|e| payjoin::receive::Error::Server(Box::new(e)))
is_owned(&input.to_bytes())
.map_err(|e| payjoin::receive::Error::Server(Box::new(e)))
})
.map_err(|e| e.into())
.map(|e| Arc::new(e.into()))
Expand Down Expand Up @@ -222,7 +223,9 @@ impl MaybeInputsSeen {
self.0
.clone()
.check_no_inputs_seen_before(|outpoint| {
is_known.callback(outpoint.clone().into()).map_err(|e| pdk::Error::Server(Box::new(e)))
is_known
.callback(outpoint.clone().into())
.map_err(|e| pdk::Error::Server(Box::new(e)))
})
.map_err(|e| e.into())
.map(|e| Arc::new(e.into()))
Expand Down
7 changes: 5 additions & 2 deletions src/receive/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ impl V2MaybeInputsOwned {
self.0
.clone()
.check_inputs_not_owned(|input| {
is_owned(&input.to_bytes()).map_err(|e| payjoin::receive::Error::Server(Box::new(e)))
is_owned(&input.to_bytes())
.map_err(|e| payjoin::receive::Error::Server(Box::new(e)))
})
.map_err(|e| e.into())
.map(|e| Arc::new(e.into()))
Expand Down Expand Up @@ -382,7 +383,9 @@ impl V2MaybeInputsSeen {
self.0
.clone()
.check_no_inputs_seen_before(|outpoint| {
is_known.callback(outpoint.clone().into()).map_err(|e| pdk::Error::Server(Box::new(e)))
is_known
.callback(outpoint.clone().into())
.map_err(|e| pdk::Error::Server(Box::new(e)))
})
.map(|e| Arc::new(e.into()))
.map_err(|e| e.into())
Expand Down
23 changes: 16 additions & 7 deletions src/uri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::str::FromStr;
use std::time::{Duration, UNIX_EPOCH};
use std::time::{Duration, UNIX_EPOCH};

use payjoin::bitcoin::address::NetworkChecked;
use payjoin::UriExt;
Expand Down Expand Up @@ -33,13 +33,16 @@ impl Uri {
}
///Gets the amount in satoshis.
pub fn amount(&self) -> Option<f64> {

self.0.amount.map(|x| x.to_btc())
}
pub fn check_pj_supported(&self) -> Result<PjUri,PayjoinError > {
match self.0.clone().check_pj_supported(){
pub fn check_pj_supported(&self) -> Result<PjUri, PayjoinError> {
match self.0.clone().check_pj_supported() {
Ok(e) => Ok(e.into()),
Err(_) => Err(PayjoinError::PjNotSupported{message:"Uri doesn't support payjoin".to_string()})
Err(_) => {
Err(PayjoinError::PjNotSupported {
message: "Uri doesn't support payjoin".to_string(),
})
}
}
}
pub fn as_string(&self) -> String {
Expand Down Expand Up @@ -130,7 +133,13 @@ impl PjUriBuilder {
expiry: Option<u64>,
) -> Result<Self, PayjoinError> {
let address = payjoin::bitcoin::Address::from_str(&address)?.assume_checked();
Ok(payjoin::PjUriBuilder::new(address, pj.into(), ohttp_keys.map(|e| e.0), expiry.map(|e| UNIX_EPOCH + Duration::from_secs(e)),).into())
Ok(payjoin::PjUriBuilder::new(
address,
pj.into(),
ohttp_keys.map(|e| e.0),
expiry.map(|e| UNIX_EPOCH + Duration::from_secs(e)),
)
.into())
}
///Accepts the amount you want to receive in sats and sets it in btc .
pub fn amount(&self, amount: u64) -> Self {
Expand Down Expand Up @@ -175,7 +184,7 @@ mod tests {
address.to_string(),
Url::from_str(pj.to_string()).unwrap(),
None,
None
None,
)
.unwrap();
let uri = builder
Expand Down

0 comments on commit 93ded99

Please sign in to comment.