Skip to content

Commit dbdf25c

Browse files
authored
Fix ffi fmt and run fmt --check in CI (payjoin#832)
2 parents da49c64 + 9fb87d4 commit dbdf25c

File tree

5 files changed

+64
-33
lines changed

5 files changed

+64
-33
lines changed

.github/workflows/rust.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ jobs:
3737
- run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
3838
- name: "Run formatting check"
3939
run: cargo fmt --all -- --check
40+
41+
Format-FFI:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: "Checkout repo"
45+
uses: actions/checkout@v4
46+
- name: "Install nightly toolchain"
47+
uses: dtolnay/rust-toolchain@nightly
48+
- name: "Use cache"
49+
uses: Swatinem/rust-cache@v2
50+
- run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
51+
- name: "Run formatting check"
52+
run: cd payjoin-ffi && cargo fmt --all -- --check
4053

4154
Lint:
4255
runs-on: ubuntu-latest

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())
@@ -291,9 +303,7 @@ impl V2GetContextTransitionOutcome {
291303

292304
pub fn is_success(&self) -> bool { self.0.is_success() }
293305

294-
pub fn success(&self) -> Option<Psbt> {
295-
self.0.success().map(|r| r.clone().into())
296-
}
306+
pub fn success(&self) -> Option<Psbt> { self.0.success().map(|r| r.clone().into()) }
297307
}
298308

299309
impl
@@ -330,16 +340,24 @@ pub struct V2GetContextTransition(
330340
);
331341

332342
impl V2GetContextTransition {
333-
pub fn save<P>(&self, persister: &P) -> Result<V2GetContextTransitionOutcome, SenderPersistedError>
343+
pub fn save<P>(
344+
&self,
345+
persister: &P,
346+
) -> Result<V2GetContextTransitionOutcome, SenderPersistedError>
334347
where
335348
P: SessionPersister<SessionEvent = payjoin::send::v2::SessionEvent>,
336349
{
337-
let mut inner =
338-
self.0.write().map_err(|_| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Lock poisoned".to_string()))))?;
339-
340-
let value = inner
341-
.take()
342-
.ok_or_else(|| SenderPersistedError::Storage(Arc::new(ImplementationError::from("Already saved or moved".to_string()))))?;
350+
let mut inner = self.0.write().map_err(|_| {
351+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
352+
"Lock poisoned".to_string(),
353+
)))
354+
})?;
355+
356+
let value = inner.take().ok_or_else(|| {
357+
SenderPersistedError::Storage(Arc::new(ImplementationError::from(
358+
"Already saved or moved".to_string(),
359+
)))
360+
})?;
343361

344362
let res = value.save(persister).map_err(|e| SenderPersistedError::from(e))?;
345363
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

@@ -317,9 +318,7 @@ impl V2GetContextTransitionOutcome {
317318

318319
pub fn is_success(&self) -> bool { self.0.is_success() }
319320

320-
pub fn success(&self) -> Option<Arc<Psbt>> {
321-
self.0.success().map(|p| p.into())
322-
}
321+
pub fn success(&self) -> Option<Arc<Psbt>> { self.0.success().map(|p| p.into()) }
323322
}
324323

325324
#[derive(uniffi::Object)]

0 commit comments

Comments
 (0)