Skip to content

Commit eda3230

Browse files
committed
Dedupe ImplementationError
Opted for creating a new `core` module that can be used for other common/core stuff
1 parent 64d411c commit eda3230

File tree

15 files changed

+30
-24
lines changed

15 files changed

+30
-24
lines changed

payjoin-cli/src/app/v1.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ use hyper_util::rt::TokioIo;
1515
use payjoin::bitcoin::psbt::Psbt;
1616
use payjoin::bitcoin::FeeRate;
1717
use payjoin::receive::v1::{PayjoinProposal, UncheckedProposal};
18-
use payjoin::receive::ImplementationError;
1918
use payjoin::receive::ReplyableError::{self, Implementation, V1};
2019
use payjoin::send::v1::SenderBuilder;
21-
use payjoin::{Uri, UriExt};
20+
use payjoin::{ImplementationError, Uri, UriExt};
2221
use tokio::net::TcpListener;
2322
use tokio::sync::watch;
2423

payjoin-cli/src/app/v2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use payjoin::bitcoin::consensus::encode::serialize_hex;
55
use payjoin::bitcoin::psbt::Psbt;
66
use payjoin::bitcoin::{Amount, FeeRate};
77
use payjoin::receive::v2::{NewReceiver, Receiver, UncheckedProposal};
8-
use payjoin::receive::{Error, ImplementationError, ReplyableError};
8+
use payjoin::receive::{Error, ReplyableError};
99
use payjoin::send::v2::{Sender, SenderBuilder};
10-
use payjoin::Uri;
10+
use payjoin::{ImplementationError, Uri};
1111
use tokio::sync::watch;
1212

1313
use super::config::Config;

payjoin/src/core/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use std::error;
2+
3+
pub type ImplementationError = Box<dyn error::Error + Send + Sync>;

payjoin/src/core/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Core Payjoin
2+
//!
3+
//! This module contains types and methods used to implement Payjoin.
4+
pub mod error;

payjoin/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ pub use uri::{PjParseError, PjUri, Uri, UriExt};
6969
#[cfg(feature = "_core")]
7070
pub use url::{ParseError, Url};
7171
#[cfg(feature = "_core")]
72+
pub mod core;
73+
#[cfg(feature = "_core")]
7274
pub(crate) mod error_codes;
75+
#[cfg(feature = "_core")]
76+
pub use core::error::ImplementationError;

payjoin/src/receive/error.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use crate::error_codes::ErrorCode::{
44
self, NotEnoughMoney, OriginalPsbtRejected, Unavailable, VersionUnsupported,
55
};
66

7-
pub type ImplementationError = Box<dyn error::Error + Send + Sync>;
8-
97
/// The top-level error type for the payjoin receiver
108
#[derive(Debug)]
119
#[non_exhaustive]
@@ -60,7 +58,7 @@ pub enum ReplyableError {
6058
/// Error arising due to the specific receiver implementation
6159
///
6260
/// e.g. database errors, network failures, wallet errors
63-
Implementation(ImplementationError),
61+
Implementation(crate::core::error::ImplementationError),
6462
}
6563

6664
/// The standard format for errors that can be replied as JSON.

payjoin/src/receive/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::str::FromStr;
1414
use bitcoin::{psbt, AddressType, Psbt, TxIn, TxOut};
1515
pub(crate) use error::InternalPayloadError;
1616
pub use error::{
17-
Error, ImplementationError, InputContributionError, JsonReply, OutputSubstitutionError,
18-
PayloadError, ReplyableError, SelectionError,
17+
Error, InputContributionError, JsonReply, OutputSubstitutionError, PayloadError,
18+
ReplyableError, SelectionError,
1919
};
2020
use optional_parameters::Params;
2121

payjoin/src/receive/multiparty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use bitcoin::{FeeRate, Psbt};
22

33
use super::error::InputContributionError;
4-
use super::{v1, v2, Error, ImplementationError, InputPair};
4+
use super::{v1, v2, Error, InputPair};
55
use crate::psbt::merge::merge_unsigned_tx;
66
use crate::receive::multiparty::error::{InternalMultipartyError, MultipartyError};
77
use crate::receive::v2::SessionContext;
8+
use crate::ImplementationError;
89

910
pub(crate) mod error;
1011

payjoin/src/receive/v1/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ use super::error::{
3636
InternalSelectionError,
3737
};
3838
use super::optional_parameters::Params;
39-
use super::{
40-
ImplementationError, InputPair, OutputSubstitutionError, ReplyableError, SelectionError,
41-
};
39+
use super::{InputPair, OutputSubstitutionError, ReplyableError, SelectionError};
4240
use crate::output_substitution::OutputSubstitution;
4341
use crate::psbt::PsbtExt;
4442
use crate::receive::InternalPayloadError;
43+
use crate::ImplementationError;
4544

4645
#[cfg(feature = "v1")]
4746
mod exclusive;

payjoin/src/receive/v2/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ use url::Url;
1414

1515
use super::error::{Error, InputContributionError};
1616
use super::{
17-
v1, ImplementationError, InternalPayloadError, JsonReply, OutputSubstitutionError,
18-
ReplyableError, SelectionError,
17+
v1, InternalPayloadError, JsonReply, OutputSubstitutionError, ReplyableError, SelectionError,
1918
};
2019
use crate::hpke::{decrypt_message_a, encrypt_message_b, HpkeKeyPair, HpkePublicKey};
2120
use crate::ohttp::{ohttp_decapsulate, ohttp_encapsulate, OhttpEncapsulationError, OhttpKeys};
2221
use crate::output_substitution::OutputSubstitution;
2322
use crate::persist::Persister;
2423
use crate::receive::{parse_payload, InputPair};
2524
use crate::uri::ShortId;
26-
use crate::{IntoUrl, IntoUrlError, Request};
25+
use crate::{ImplementationError, IntoUrl, IntoUrlError, Request};
2726

2827
mod error;
2928
mod persist;

0 commit comments

Comments
 (0)