Skip to content

Commit a5d8283

Browse files
committed
Format payjoin-ffi crate
Changes were automatically applied by running `cd payjoin-ffi && cargo fmt`
1 parent c3f1ce2 commit a5d8283

File tree

4 files changed

+51
-33
lines changed

4 files changed

+51
-33
lines changed

payjoin-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod send;
1212
pub mod test_utils;
1313
pub mod uri;
1414

15-
pub use payjoin::persist::{NoopSessionPersister};
15+
pub use payjoin::persist::NoopSessionPersister;
1616

1717
pub use crate::bitcoin_ffi::*;
1818
pub use crate::ohttp::*;

payjoin-ffi/src/send/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl From<ImplementationError> for SenderPersistedError {
120120
fn from(value: ImplementationError) -> Self { SenderPersistedError::Storage(Arc::new(value)) }
121121
}
122122

123-
impl<S> From<payjoin::persist::PersistedError<send::v2::EncapsulationError, S>> for SenderPersistedError
123+
impl<S> From<payjoin::persist::PersistedError<send::v2::EncapsulationError, S>>
124+
for SenderPersistedError
124125
where
125126
S: std::error::Error,
126127
{

payjoin-ffi/src/send/mod.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ impl From<payjoin::send::v2::SendSession> for SendSession {
3333
fn from(value: payjoin::send::v2::SendSession) -> Self { Self(value) }
3434
}
3535

36-
pub fn replay_event_log<P>(persister: &P) -> Result<(SendSession, SessionHistory), SenderReplayError>
36+
pub fn replay_event_log<P>(
37+
persister: &P,
38+
) -> Result<(SendSession, SessionHistory), SenderReplayError>
3739
where
3840
P: SessionPersister + Clone,
3941
P::SessionEvent: Into<payjoin::send::v2::SessionEvent> + Clone,
@@ -69,12 +71,17 @@ impl InitInputsTransition {
6971
where
7072
P: SessionPersister<SessionEvent = payjoin::send::v2::SessionEvent>,
7173
{
72-
let mut inner =
73-
self.0.write().map_err(|_| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Lock poisoned".to_string()))))?;
74-
75-
let value = inner
76-
.take()
77-
.ok_or_else(|| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Already saved or moved".to_string()))))?;
74+
let mut inner = self.0.write().map_err(|_| {
75+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
76+
"Lock poisoned".to_string(),
77+
)))
78+
})?;
79+
80+
let value = inner.take().ok_or_else(|| {
81+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
82+
"Already saved or moved".to_string(),
83+
)))
84+
})?;
7885

7986
let res = value.save(persister).map_err(|e| SenderPersistedError::from(e))?;
8087
Ok(res.into())
@@ -195,12 +202,17 @@ impl WithReplyKeyTransition {
195202
where
196203
P: SessionPersister<SessionEvent = payjoin::send::v2::SessionEvent>,
197204
{
198-
let mut inner =
199-
self.0.write().map_err(|_| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Lock poisoned".to_string()))))?;
200-
201-
let value = inner
202-
.take()
203-
.ok_or_else(|| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Already saved or moved".to_string()))))?;
205+
let mut inner = self.0.write().map_err(|_| {
206+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
207+
"Lock poisoned".to_string(),
208+
)))
209+
})?;
210+
211+
let value = inner.take().ok_or_else(|| {
212+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
213+
"Already saved or moved".to_string(),
214+
)))
215+
})?;
204216

205217
let res = value.save(persister).map_err(|e| SenderPersistedError::from(e))?;
206218
Ok(res.into())
@@ -287,9 +299,7 @@ impl V2GetContextTransitionOutcome {
287299

288300
pub fn is_success(&self) -> bool { self.0.is_success() }
289301

290-
pub fn success(&self) -> Option<Psbt> {
291-
self.0.success().map(|r| r.clone().into())
292-
}
302+
pub fn success(&self) -> Option<Psbt> { self.0.success().map(|r| r.clone().into()) }
293303
}
294304

295305
impl
@@ -326,16 +336,24 @@ pub struct V2GetContextTransition(
326336
);
327337

328338
impl V2GetContextTransition {
329-
pub fn save<P>(&self, persister: &P) -> Result<V2GetContextTransitionOutcome, SenderPersistedError>
339+
pub fn save<P>(
340+
&self,
341+
persister: &P,
342+
) -> Result<V2GetContextTransitionOutcome, SenderPersistedError>
330343
where
331344
P: SessionPersister<SessionEvent = payjoin::send::v2::SessionEvent>,
332345
{
333-
let mut inner =
334-
self.0.write().map_err(|_| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Lock poisoned".to_string()))))?;
335-
336-
let value = inner
337-
.take()
338-
.ok_or_else(|| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Already saved or moved".to_string()))))?;
346+
let mut inner = self.0.write().map_err(|_| {
347+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
348+
"Lock poisoned".to_string(),
349+
)))
350+
})?;
351+
352+
let value = inner.take().ok_or_else(|| {
353+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
354+
"Already saved or moved".to_string(),
355+
)))
356+
})?;
339357

340358
let res = value.save(persister).map_err(|e| SenderPersistedError::from(e))?;
341359
Ok(res.into())

payjoin-ffi/src/send/uni.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use std::sync::{Arc, RwLock};
22

33
use bitcoin_ffi::Psbt;
44

5-
use crate::{error::ForeignError, Url};
5+
use crate::error::ForeignError;
66
use crate::send::error::{SenderPersistedError, SenderReplayError};
77
pub use crate::send::{
88
BuildSenderError, CreateRequestError, EncapsulationError, ResponseError, SerdeJsonError,
99
};
10-
use crate::{ClientResponse, PjUri, Request};
10+
use crate::{ClientResponse, PjUri, Request, Url};
1111

1212
#[derive(uniffi::Object, Debug, Clone, serde::Serialize, serde::Deserialize)]
1313
pub struct SenderSessionEvent(super::SessionEvent);
@@ -71,12 +71,12 @@ impl From<SenderSessionHistory> for super::SessionHistory {
7171
#[uniffi::export]
7272
impl SenderSessionHistory {
7373
pub fn endpoint(&self) -> Option<Arc<Url>> {
74-
self.0.0.endpoint().map(|url| Arc::new(url.clone().into()))
74+
self.0 .0.endpoint().map(|url| Arc::new(url.clone().into()))
7575
}
7676

7777
/// Fallback transaction from the session if present
7878
pub fn fallback_tx(&self) -> Option<Arc<crate::Transaction>> {
79-
self.0.0.fallback_tx().map(|tx| Arc::new(tx.into()))
79+
self.0 .0.fallback_tx().map(|tx| Arc::new(tx.into()))
8080
}
8181
}
8282

@@ -98,7 +98,8 @@ pub fn replay_sender_event_log(
9898
persister: Arc<dyn JsonSenderSessionPersister>,
9999
) -> Result<SenderReplayResult, SenderReplayError> {
100100
let adapter = CallbackPersisterAdapter::new(persister);
101-
let (state, session_history) = super::replay_event_log(&adapter).map_err(SenderReplayError::from)?;
101+
let (state, session_history) =
102+
super::replay_event_log(&adapter).map_err(SenderReplayError::from)?;
102103
Ok(SenderReplayResult { state: state.into(), session_history: session_history.into() })
103104
}
104105

@@ -312,9 +313,7 @@ impl V2GetContextTransitionOutcome {
312313

313314
pub fn is_success(&self) -> bool { self.0.is_success() }
314315

315-
pub fn success(&self) -> Option<Arc<Psbt>> {
316-
self.0.success().map(|p| p.into())
317-
}
316+
pub fn success(&self) -> Option<Arc<Psbt>> { self.0.success().map(|p| p.into()) }
318317
}
319318

320319
#[derive(uniffi::Object)]

0 commit comments

Comments
 (0)