Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions payjoin-ffi/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ impl SenderSessionEvent {
}

#[derive(Clone, uniffi::Object)]
pub struct SenderSessionOutcome {
inner: payjoin::send::v2::SessionOutcome,
}
pub struct SenderSessionOutcome(payjoin::send::v2::SessionOutcome);

impl From<payjoin::send::v2::SessionOutcome> for SenderSessionOutcome {
fn from(value: payjoin::send::v2::SessionOutcome) -> Self { Self { inner: value } }
fn from(value: payjoin::send::v2::SessionOutcome) -> Self { Self(value) }
}

impl From<SenderSessionOutcome> for payjoin::send::v2::SessionOutcome {
fn from(value: SenderSessionOutcome) -> Self { value.inner }
fn from(value: SenderSessionOutcome) -> Self { value.0 }
}

#[derive(Clone, uniffi::Enum)]
Expand Down Expand Up @@ -116,6 +114,32 @@ pub fn replay_sender_event_log(
Ok(SenderReplayResult { state: state.into(), session_history: session_history.into() })
}

/// Represents the status of a session that can be inferred from the information in the session
/// event log.
#[derive(uniffi::Object)]
pub struct SenderSessionStatus {
inner: payjoin::send::v2::SessionStatus,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is inner idiomatic? or should it just be pub struct SenderSessionStatus(payjoin::send::v2::SessionStatus)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a perfectly consistent approach that we take, SenderSessionEvent has a tuple struct while SenderSessionOutcome has named fields, this seems fine imo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer tuple struct where there's only one inner value, but we can make this consistent in a follow-up.

}

impl From<payjoin::send::v2::SessionStatus> for SenderSessionStatus {
fn from(value: payjoin::send::v2::SessionStatus) -> Self { Self { inner: value } }
}

impl From<SenderSessionStatus> for payjoin::send::v2::SessionStatus {
fn from(value: SenderSessionStatus) -> Self { value.inner }
}

#[derive(uniffi::Object)]
pub struct PjParam(payjoin::uri::v2::PjParam);

impl From<payjoin::uri::v2::PjParam> for PjParam {
fn from(value: payjoin::uri::v2::PjParam) -> Self { Self(value) }
}

impl From<PjParam> for payjoin::uri::v2::PjParam {
fn from(value: PjParam) -> Self { value.0 }
}

#[derive(uniffi::Object, Clone)]
pub struct SenderSessionHistory(pub payjoin::send::v2::SessionHistory);

Expand All @@ -131,6 +155,10 @@ impl From<SenderSessionHistory> for payjoin::send::v2::SessionHistory {
impl SenderSessionHistory {
/// Fallback transaction from the session if present
pub fn fallback_tx(&self) -> Arc<crate::Transaction> { Arc::new(self.0.fallback_tx().into()) }

pub fn pj_param(&self) -> Arc<PjParam> { Arc::new(self.0.pj_param().to_owned().into()) }

pub fn status(&self) -> SenderSessionStatus { self.0.status().into() }
}

#[derive(uniffi::Object)]
Expand Down
2 changes: 1 addition & 1 deletion payjoin/src/core/send/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use error::{CreateRequestError, EncapsulationError};
use error::{InternalCreateRequestError, InternalEncapsulationError};
use ohttp::ClientResponse;
use serde::{Deserialize, Serialize};
pub use session::{replay_event_log, SessionEvent, SessionHistory, SessionOutcome};
pub use session::{replay_event_log, SessionEvent, SessionHistory, SessionOutcome, SessionStatus};
use url::Url;

use super::error::BuildSenderError;
Expand Down