Skip to content

Commit 21fc483

Browse files
committed
Dedupe ImplementationError
1 parent 64d411c commit 21fc483

File tree

10 files changed

+22
-14
lines changed

10 files changed

+22
-14
lines changed

payjoin-cli/src/app/v2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::sync::Arc;
22

33
use anyhow::{anyhow, Context, Result};
4+
use payjoin::ImplementationError;
45
use payjoin::bitcoin::consensus::encode::serialize_hex;
56
use payjoin::bitcoin::psbt::Psbt;
67
use payjoin::bitcoin::{Amount, FeeRate};
78
use payjoin::receive::v2::{NewReceiver, Receiver, UncheckedProposal};
8-
use payjoin::receive::{Error, ImplementationError, ReplyableError};
9+
use payjoin::receive::{Error, ReplyableError};
910
use payjoin::send::v2::{Sender, SenderBuilder};
1011
use payjoin::Uri;
1112
use tokio::sync::watch;

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/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::{IntoUrl, IntoUrlError, ImplementationError, Request};
2726

2827
mod error;
2928
mod persist;

payjoin/src/send/v2/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use core::fmt;
22

33
use crate::uri::url_ext::ParseReceiverPubkeyParamError;
44

5-
pub type ImplementationError = Box<dyn std::error::Error + Send + Sync>;
65
/// Error returned when request could not be created.
76
///
87
/// This error can currently only happen due to programmer mistake.

payjoin/src/send/v2/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! wallet and http client.
2323
2424
use bitcoin::hashes::{sha256, Hash};
25-
pub use error::{CreateRequestError, EncapsulationError, ImplementationError};
25+
pub use error::{CreateRequestError, EncapsulationError};
2626
use error::{InternalCreateRequestError, InternalEncapsulationError};
2727
use ohttp::ClientResponse;
2828
pub use persist::SenderToken;
@@ -31,6 +31,7 @@ use url::Url;
3131

3232
use super::error::BuildSenderError;
3333
use super::*;
34+
use crate::core::error::ImplementationError;
3435
use crate::hpke::{decrypt_message_b, encrypt_message_a, HpkeSecretKey};
3536
use crate::ohttp::{ohttp_decapsulate, ohttp_encapsulate};
3637
use crate::persist::Persister;

0 commit comments

Comments
 (0)