Skip to content
Draft
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
10 changes: 2 additions & 8 deletions rust/src/api/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ pub async fn fetch_ohttp_keys_with_cert(
}

pub mod error {
use crate::frb_generated::RustAutoOpaque;
use crate::ffi_opaque_wrapper;

pub struct FfiIoError(pub(crate) RustAutoOpaque<payjoin_ffi::io::IoError>);

impl From<payjoin_ffi::io::IoError> for FfiIoError {
fn from(value: payjoin_ffi::io::IoError) -> Self {
Self(RustAutoOpaque::new(value))
}
}
ffi_opaque_wrapper!(FfiIoError, payjoin_ffi::io::IoError);
}
36 changes: 19 additions & 17 deletions rust/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ pub mod receive;
pub mod send;
pub mod uri;

use crate::frb_generated::RustAutoOpaque;

pub struct FfiSerdeJsonError(pub(crate) RustAutoOpaque<payjoin_ffi::error::SerdeJsonError>);

impl From<payjoin_ffi::error::SerdeJsonError> for FfiSerdeJsonError {
fn from(value: payjoin_ffi::error::SerdeJsonError) -> Self {
Self(RustAutoOpaque::new(value))
}
#[macro_export]
macro_rules! ffi_opaque_wrapper {
($wrapper:ident, $inner:path) => {
pub struct $wrapper(pub(crate) crate::frb_generated::RustAutoOpaque<$inner>);
impl From<$inner> for $wrapper {
fn from(value: $inner) -> Self {
Self(crate::frb_generated::RustAutoOpaque::new(value))
}
}
impl $wrapper {
#[flutter_rust_bridge::frb(sync)]
pub fn message(&self) -> String {
self.0.blocking_read().to_string()
}
}
};
}

ffi_opaque_wrapper!(FfiSerdeJsonError, payjoin_ffi::error::SerdeJsonError);

pub mod ohttp {
pub mod error {
use crate::frb_generated::RustAutoOpaque;

pub struct FfiOhttpError(pub(crate) RustAutoOpaque<payjoin_ffi::ohttp::error::OhttpError>);

impl From<payjoin_ffi::ohttp::error::OhttpError> for FfiOhttpError {
fn from(value: payjoin_ffi::ohttp::error::OhttpError) -> Self {
Self(RustAutoOpaque::new(value))
}
}
ffi_opaque_wrapper!(FfiOhttpError, payjoin_ffi::ohttp::error::OhttpError);
}
}
80 changes: 9 additions & 71 deletions rust/src/api/receive/error.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,20 @@
use crate::frb_generated::RustAutoOpaque;
use crate::ffi_opaque_wrapper;

pub struct FfiError(pub(crate) RustAutoOpaque<payjoin_ffi::receive::Error>);
ffi_opaque_wrapper!(FfiError, payjoin_ffi::receive::Error);
ffi_opaque_wrapper!(FfiImplementationError, payjoin_ffi::receive::ImplementationError);
ffi_opaque_wrapper!(FfiSessionError, payjoin_ffi::receive::SessionError);
ffi_opaque_wrapper!(FfiInputContributionError, payjoin_ffi::receive::InputContributionError);
ffi_opaque_wrapper!(FfiOutputSubstitutionError, payjoin_ffi::receive::OutputSubstitutionError);
ffi_opaque_wrapper!(FfiPsbtInputError, payjoin_ffi::receive::PsbtInputError);
ffi_opaque_wrapper!(FfiReplyableError, payjoin_ffi::receive::ReplyableError);
ffi_opaque_wrapper!(FfiSelectionError, payjoin_ffi::receive::SelectionError);

impl From<payjoin_ffi::receive::Error> for FfiError {
fn from(value: payjoin_ffi::receive::Error) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiImplementationError(
pub(crate) RustAutoOpaque<payjoin_ffi::receive::ImplementationError>,
);

impl From<payjoin_ffi::receive::ImplementationError> for FfiImplementationError {
fn from(value: payjoin_ffi::receive::ImplementationError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiSessionError(pub(crate) RustAutoOpaque<payjoin_ffi::receive::SessionError>);

impl From<payjoin_ffi::receive::SessionError> for FfiSessionError {
fn from(value: payjoin_ffi::receive::SessionError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiInputContributionError(
pub RustAutoOpaque<payjoin_ffi::receive::InputContributionError>,
);

impl From<payjoin_ffi::receive::InputContributionError> for FfiInputContributionError {
fn from(value: payjoin_ffi::receive::InputContributionError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiOutputSubstitutionError(
pub(crate) RustAutoOpaque<payjoin_ffi::receive::OutputSubstitutionError>,
);

impl From<payjoin_ffi::receive::OutputSubstitutionError> for FfiOutputSubstitutionError {
fn from(value: payjoin_ffi::receive::OutputSubstitutionError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiPsbtInputError(pub(crate) RustAutoOpaque<payjoin_ffi::receive::PsbtInputError>);

impl From<payjoin_ffi::receive::PsbtInputError> for FfiPsbtInputError {
fn from(value: payjoin_ffi::receive::PsbtInputError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiReplyableError(pub(crate) RustAutoOpaque<payjoin_ffi::receive::ReplyableError>);

impl From<payjoin_ffi::receive::ReplyableError> for FfiReplyableError {
fn from(value: payjoin_ffi::receive::ReplyableError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiSelectionError(pub(crate) RustAutoOpaque<payjoin_ffi::receive::SelectionError>);

impl From<payjoin_ffi::receive::SelectionError> for FfiSelectionError {
fn from(value: payjoin_ffi::receive::SelectionError) -> Self {
Self(RustAutoOpaque::new(value))
}
}
pub struct FfiJsonReply(pub(crate) payjoin_ffi::receive::JsonReply);

impl From<payjoin_ffi::receive::JsonReply> for FfiJsonReply {
fn from(value: payjoin_ffi::receive::JsonReply) -> Self {
Self(value)
}
}

impl From<FfiJsonReply> for payjoin_ffi::receive::JsonReply {
fn from(value: FfiJsonReply) -> Self {
value.0
Expand Down
22 changes: 4 additions & 18 deletions rust/src/api/send/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::frb_generated::RustAutoOpaque;
use crate::ffi_opaque_wrapper;

pub struct FfiBuildSenderError {
pub(crate) msg: String,
Expand Down Expand Up @@ -30,20 +30,6 @@ impl From<payjoin_ffi::send::EncapsulationError> for FfiEncapsulationError {
}
}

pub struct FfiValidationError(pub(crate) RustAutoOpaque<payjoin_ffi::send::error::ValidationError>);

impl From<payjoin_ffi::send::error::ValidationError> for FfiValidationError {
fn from(value: payjoin_ffi::send::error::ValidationError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiWellKnownError(pub(crate) RustAutoOpaque<payjoin_ffi::send::error::WellKnownError>);

pub struct FfiResponseError(pub(crate) RustAutoOpaque<payjoin_ffi::send::error::ResponseError>);

impl From<payjoin_ffi::send::error::ResponseError> for FfiResponseError {
fn from(value: payjoin_ffi::send::error::ResponseError) -> Self {
Self(RustAutoOpaque::new(value))
}
}
ffi_opaque_wrapper!(FfiValidationError, payjoin_ffi::send::error::ValidationError);
ffi_opaque_wrapper!(FfiWellKnownError, payjoin_ffi::send::error::WellKnownError);
ffi_opaque_wrapper!(FfiResponseError, payjoin_ffi::send::error::ResponseError);
37 changes: 5 additions & 32 deletions rust/src/api/uri/error.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
use crate::frb_generated::RustAutoOpaque;
use crate::ffi_opaque_wrapper;

pub struct FfiIntoUrlError(pub(crate) RustAutoOpaque<payjoin_ffi::uri::error::IntoUrlError>);

impl From<payjoin_ffi::uri::error::IntoUrlError> for FfiIntoUrlError {
fn from(value: payjoin_ffi::uri::error::IntoUrlError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiPjParseError(pub(crate) RustAutoOpaque<payjoin_ffi::uri::PjParseError>);

impl From<payjoin_ffi::uri::PjParseError> for FfiPjParseError {
fn from(value: payjoin_ffi::uri::PjParseError) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiPjNotSupported(pub(crate) RustAutoOpaque<payjoin_ffi::uri::PjNotSupported>);

impl From<payjoin_ffi::uri::PjNotSupported> for FfiPjNotSupported {
fn from(value: payjoin_ffi::uri::PjNotSupported) -> Self {
Self(RustAutoOpaque::new(value))
}
}

pub struct FfiUrlParseError(pub(crate) RustAutoOpaque<payjoin_ffi::uri::UrlParseError>);

impl From<payjoin_ffi::uri::UrlParseError> for FfiUrlParseError {
fn from(value: payjoin_ffi::uri::UrlParseError) -> Self {
Self(RustAutoOpaque::new(value))
}
}
ffi_opaque_wrapper!(FfiIntoUrlError, payjoin_ffi::uri::error::IntoUrlError);
ffi_opaque_wrapper!(FfiPjParseError, payjoin_ffi::uri::PjParseError);
ffi_opaque_wrapper!(FfiPjNotSupported, payjoin_ffi::uri::PjNotSupported);
ffi_opaque_wrapper!(FfiUrlParseError, payjoin_ffi::uri::UrlParseError);