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
14 changes: 7 additions & 7 deletions payjoin-ffi/src/send/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ impl From<FfiValidationError> for SenderInputError {
#[error(transparent)]
pub struct CreateRequestError(#[from] send::v2::CreateRequestError);

/// Error returned for v2-specific payload encapsulation errors.
/// Error returned for v2-specific payload decapsulation errors.
#[derive(Debug, thiserror::Error, uniffi::Object)]
#[uniffi::export(Debug, Display)]
#[error(transparent)]
pub struct EncapsulationError(#[from] send::v2::EncapsulationError);
pub struct DecapsulationError(#[from] send::v2::DecapsulationError);

/// Error that may occur when the response from receiver is malformed.
#[derive(Debug, thiserror::Error, uniffi::Object)]
Expand Down Expand Up @@ -126,9 +126,9 @@ pub struct SenderReplayError(
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[error(transparent)]
pub enum SenderPersistedError {
/// rust-payjoin sender Encapsulation error
/// rust-payjoin sender Decapsulation error
#[error(transparent)]
EncapsulationError(Arc<EncapsulationError>),
DecapsulationError(Arc<DecapsulationError>),
/// rust-payjoin sender response error
#[error(transparent)]
ResponseError(ResponseError),
Expand All @@ -147,20 +147,20 @@ impl From<ImplementationError> for SenderPersistedError {
fn from(value: ImplementationError) -> Self { SenderPersistedError::Storage(Arc::new(value)) }
}

impl<S> From<payjoin::persist::PersistedError<send::v2::EncapsulationError, S>>
impl<S> From<payjoin::persist::PersistedError<send::v2::DecapsulationError, S>>
for SenderPersistedError
where
S: std::error::Error + Send + Sync + 'static,
{
fn from(err: payjoin::persist::PersistedError<send::v2::EncapsulationError, S>) -> Self {
fn from(err: payjoin::persist::PersistedError<send::v2::DecapsulationError, S>) -> Self {
if err.storage_error_ref().is_some() {
if let Some(storage_err) = err.storage_error() {
return SenderPersistedError::from(ImplementationError::new(storage_err));
}
return SenderPersistedError::Unexpected;
}
if let Some(api_err) = err.api_error() {
return SenderPersistedError::EncapsulationError(Arc::new(api_err.into()));
return SenderPersistedError::DecapsulationError(Arc::new(api_err.into()));
}
SenderPersistedError::Unexpected
}
Expand Down
4 changes: 2 additions & 2 deletions payjoin-ffi/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;
use std::sync::{Arc, RwLock};

pub use error::{
BuildSenderError, CreateRequestError, EncapsulationError, PsbtParseError, ResponseError,
BuildSenderError, CreateRequestError, DecapsulationError, PsbtParseError, ResponseError,
SenderInputError,
};

Expand Down Expand Up @@ -456,7 +456,7 @@ pub struct WithReplyKeyTransition(
payjoin::persist::MaybeFatalTransition<
payjoin::send::v2::SessionEvent,
payjoin::send::v2::Sender<payjoin::send::v2::PollingForProposal>,
payjoin::send::v2::EncapsulationError,
payjoin::send::v2::DecapsulationError,
>,
>,
>,
Expand Down
6 changes: 3 additions & 3 deletions payjoin/src/core/send/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) enum InternalValidationError {
ContentTooLarge,
Proposal(InternalProposalError),
#[cfg(feature = "v2")]
V2Encapsulation(crate::send::v2::EncapsulationError),
V2Decapsulation(crate::send::v2::DecapsulationError),
}

impl From<InternalValidationError> for ValidationError {
Expand Down Expand Up @@ -126,7 +126,7 @@ impl fmt::Display for ValidationError {
}
Proposal(e) => write!(f, "proposal PSBT error: {e}"),
#[cfg(feature = "v2")]
V2Encapsulation(e) => write!(f, "v2 encapsulation error: {e}"),
V2Decapsulation(e) => write!(f, "v2 encapsulation error: {e}"),
}
}
}
Expand All @@ -141,7 +141,7 @@ impl std::error::Error for ValidationError {
ContentTooLarge => None,
Proposal(e) => Some(e),
#[cfg(feature = "v2")]
V2Encapsulation(e) => Some(e),
V2Decapsulation(e) => Some(e),
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions payjoin/src/core/send/v2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ impl From<crate::into_url::Error> for CreateRequestError {
}
}

/// Error returned for v2-specific payload encapsulation errors.
/// Error returned for v2-specific payload decapsulation errors.
#[derive(Debug)]
pub struct EncapsulationError(InternalEncapsulationError);
pub struct DecapsulationError(InternalDecapsulationError);

#[derive(Debug)]
pub(crate) enum InternalEncapsulationError {
pub(crate) enum InternalDecapsulationError {
/// The HPKE failed.
Hpke(crate::hpke::HpkeError),
/// The directory returned a bad response
DirectoryResponse(DirectoryResponseError),
}

impl fmt::Display for EncapsulationError {
impl fmt::Display for DecapsulationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use InternalEncapsulationError::*;
use InternalDecapsulationError::*;

match &self.0 {
Hpke(error) => write!(f, "HPKE error: {error}"),
Expand All @@ -78,9 +78,9 @@ impl fmt::Display for EncapsulationError {
}
}

impl std::error::Error for EncapsulationError {
impl std::error::Error for DecapsulationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use InternalEncapsulationError::*;
use InternalDecapsulationError::*;

match &self.0 {
Hpke(error) => Some(error),
Expand All @@ -89,12 +89,12 @@ impl std::error::Error for EncapsulationError {
}
}

impl From<InternalEncapsulationError> for EncapsulationError {
fn from(value: InternalEncapsulationError) -> Self { EncapsulationError(value) }
impl From<InternalDecapsulationError> for DecapsulationError {
fn from(value: InternalDecapsulationError) -> Self { DecapsulationError(value) }
}

impl From<InternalEncapsulationError> for super::ResponseError {
fn from(value: InternalEncapsulationError) -> Self {
super::InternalValidationError::V2Encapsulation(value.into()).into()
impl From<InternalDecapsulationError> for super::ResponseError {
fn from(value: InternalDecapsulationError) -> Self {
super::InternalValidationError::V2Decapsulation(value.into()).into()
}
}
16 changes: 8 additions & 8 deletions payjoin/src/core/send/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

use bitcoin::hashes::{sha256, Hash};
use bitcoin::Address;
pub use error::{CreateRequestError, EncapsulationError};
use error::{InternalCreateRequestError, InternalEncapsulationError};
pub use error::{CreateRequestError, DecapsulationError};
use error::{InternalCreateRequestError, InternalDecapsulationError};
use ohttp::ClientResponse;
use serde::{Deserialize, Serialize};
pub use session::{
Expand Down Expand Up @@ -392,18 +392,18 @@ impl Sender<WithReplyKey> {
self,
response: &[u8],
post_ctx: ClientResponse,
) -> MaybeFatalTransition<SessionEvent, Sender<PollingForProposal>, EncapsulationError> {
) -> MaybeFatalTransition<SessionEvent, Sender<PollingForProposal>, DecapsulationError> {
match process_post_res(response, post_ctx) {
Ok(()) => {}
Err(e) =>
if e.is_fatal() {
return MaybeFatalTransition::fatal(
SessionEvent::Closed(SessionOutcome::Failure),
InternalEncapsulationError::DirectoryResponse(e).into(),
InternalDecapsulationError::DirectoryResponse(e).into(),
);
} else {
return MaybeFatalTransition::transient(
InternalEncapsulationError::DirectoryResponse(e).into(),
InternalDecapsulationError::DirectoryResponse(e).into(),
);
},
}
Expand Down Expand Up @@ -533,11 +533,11 @@ impl Sender<PollingForProposal> {
if e.is_fatal() {
return MaybeSuccessTransitionWithNoResults::fatal(
SessionEvent::Closed(SessionOutcome::Failure),
InternalEncapsulationError::DirectoryResponse(e).into(),
InternalDecapsulationError::DirectoryResponse(e).into(),
);
} else {
return MaybeSuccessTransitionWithNoResults::transient(
InternalEncapsulationError::DirectoryResponse(e).into(),
InternalDecapsulationError::DirectoryResponse(e).into(),
);
},
};
Expand All @@ -551,7 +551,7 @@ impl Sender<PollingForProposal> {
Err(e) =>
return MaybeSuccessTransitionWithNoResults::fatal(
SessionEvent::Closed(SessionOutcome::Failure),
InternalEncapsulationError::Hpke(e).into(),
InternalDecapsulationError::Hpke(e).into(),
),
};

Expand Down
Loading