Skip to content

Commit a7352f8

Browse files
committed
restore previous serde usage in payjoin
1 parent fa68437 commit a7352f8

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

payjoin/src/core/receive/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ pub enum ProtocolError {
7777
/// "message": "Human readable error message"
7878
/// }
7979
/// ```
80-
#[derive(Debug, Clone, PartialEq, Eq)]
81-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
8281
pub struct JsonReply {
8382
/// The error code
8483
error_code: ErrorCode,

payjoin/src/core/receive/v2/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//! Note: Even fresh requests may be linkable via metadata (e.g. client IP, request timing),
2525
//! but request reuse makes correlation trivial for the relay.
2626
27+
use std::str::FromStr;
2728
#[cfg(not(target_arch = "wasm32"))]
2829
use std::time::Duration;
2930

@@ -32,6 +33,8 @@ use bitcoin::psbt::Psbt;
3233
use bitcoin::{Address, Amount, FeeRate, OutPoint, Script, TxOut, Txid};
3334
pub(crate) use error::InternalSessionError;
3435
pub use error::SessionError;
36+
use serde::de::Deserializer;
37+
use serde::{Deserialize, Serialize};
3538
pub use session::{replay_event_log, SessionEvent, SessionHistory, SessionOutcome, SessionStatus};
3639
use url::Url;
3740
#[cfg(target_arch = "wasm32")]
@@ -63,10 +66,9 @@ const SUPPORTED_VERSIONS: &[Version] = &[Version::One, Version::Two];
6366

6467
static TWENTY_FOUR_HOURS_DEFAULT_EXPIRATION: Duration = Duration::from_secs(60 * 60 * 24);
6568

66-
#[derive(Debug, Clone, PartialEq, Eq)]
67-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
69+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6870
pub struct SessionContext {
69-
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_address_assume_checked"))]
71+
#[serde(deserialize_with = "deserialize_address_assume_checked")]
7072
address: Address,
7173
directory: url::Url,
7274
ohttp_keys: OhttpKeys,
@@ -108,14 +110,10 @@ impl SessionContext {
108110
}
109111
}
110112

111-
#[cfg(feature = "serde")]
112113
fn deserialize_address_assume_checked<'de, D>(deserializer: D) -> Result<Address, D::Error>
113114
where
114-
D: serde::de::Deserializer<'de>,
115+
D: Deserializer<'de>,
115116
{
116-
use std::str::FromStr;
117-
118-
use serde::Deserialize;
119117
let s = String::deserialize(deserializer)?;
120118
let address = Address::from_str(&s).map_err(serde::de::Error::custom)?;
121119
Ok(address.assume_checked())
@@ -267,7 +265,7 @@ pub trait State: sealed::State {}
267265
/// various functions to accomplish the goals of the typestate, and one or more functions which
268266
/// will commit the changes/checks in the current typestate and move to the next one. For more
269267
/// information on the typestate pattern, see [The Typestate Pattern in Rust](https://cliffle.com/blog/rust-typestate/).
270-
#[derive(Debug, Clone, PartialEq, Eq)]
268+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
271269
pub struct Receiver<State> {
272270
/// Data associated with the current state of the receiver.
273271
pub(crate) state: State,
@@ -344,7 +342,7 @@ impl ReceiverBuilder {
344342
}
345343
}
346344

347-
#[derive(Debug, Clone, PartialEq, Eq)]
345+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
348346
pub struct Initialized {}
349347

350348
impl Receiver<Initialized> {
@@ -1216,7 +1214,7 @@ impl Receiver<HasReplyableError> {
12161214
}
12171215
}
12181216

1219-
#[derive(Debug, Clone, PartialEq, Eq)]
1217+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12201218
pub struct Monitor {
12211219
psbt_context: PsbtContext,
12221220
}

payjoin/src/core/receive/v2/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use serde::{Deserialize, Serialize};
2+
13
use super::{ReceiveSession, SessionContext};
24
use crate::error::{InternalReplayError, ReplayError};
35
use crate::output_substitution::OutputSubstitution;
@@ -140,8 +142,7 @@ pub enum SessionStatus {
140142

141143
/// Represents a piece of information that the receiver has obtained from the session
142144
/// Each event can be used to transition the receiver state machine to a new state
143-
#[derive(Debug, Clone, PartialEq, Eq)]
144-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
145+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
145146
pub enum SessionEvent {
146147
Created(SessionContext),
147148
RetrievedOriginalPayload { original: OriginalPayload, reply_key: Option<crate::HpkePublicKey> },
@@ -159,8 +160,7 @@ pub enum SessionEvent {
159160
}
160161

161162
/// Represents all possible outcomes for a closed Payjoin session
162-
#[derive(Debug, Clone, PartialEq, Eq)]
163-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
163+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
164164
pub enum SessionOutcome {
165165
/// Payjoin completed successfully
166166
Success(Vec<(bitcoin::ScriptBuf, bitcoin::Witness)>),

payjoin/src/core/send/v2/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use bitcoin::Address;
3333
pub use error::{CreateRequestError, EncapsulationError};
3434
use error::{InternalCreateRequestError, InternalEncapsulationError};
3535
use ohttp::ClientResponse;
36+
use serde::{Deserialize, Serialize};
3637
pub use session::{replay_event_log, SessionEvent, SessionHistory, SessionOutcome, SessionStatus};
3738
use url::Url;
3839

@@ -189,14 +190,13 @@ mod sealed {
189190
/// can implement this trait, ensuring type safety and protocol integrity.
190191
pub trait State: sealed::State {}
191192

192-
#[derive(Debug, Clone, PartialEq, Eq)]
193+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
193194
pub struct Sender<State> {
194195
pub(crate) state: State,
195196
pub(crate) session_context: SessionContext,
196197
}
197198

198-
#[derive(Debug, Clone, PartialEq, Eq)]
199-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
199+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
200200
pub struct SessionContext {
201201
/// The endpoint in the Payjoin URI
202202
pub(crate) pj_param: PjParam,
@@ -278,7 +278,7 @@ impl SendSession {
278278

279279
/// A payjoin V2 sender, allowing the construction of a payjoin V2 request
280280
/// and the resulting [`ClientResponse`].
281-
#[derive(Debug, Clone, PartialEq, Eq)]
281+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
282282
pub struct WithReplyKey;
283283

284284
impl Sender<WithReplyKey> {
@@ -412,7 +412,7 @@ pub(crate) fn serialize_v2_body(
412412
///
413413
/// This type is used to make a BIP77 GET request and process the response.
414414
/// Call [`Sender<PollingForProposal>::process_response`] on it to continue the BIP77 flow.
415-
#[derive(Debug, Clone, PartialEq, Eq)]
415+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
416416
pub struct PollingForProposal;
417417

418418
impl ResponseError {

payjoin/src/core/send/v2/session.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ pub enum SessionStatus {
103103
Completed,
104104
}
105105

106-
#[derive(Debug, Clone, PartialEq, Eq)]
107-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
108107
pub enum SessionEvent {
109108
/// Sender was created with session data
110109
Created(Box<SessionContext>),
@@ -115,8 +114,7 @@ pub enum SessionEvent {
115114
}
116115

117116
/// Represents all possible outcomes for a closed Payjoin session
118-
#[derive(Debug, Clone, PartialEq, Eq)]
119-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
117+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
120118
pub enum SessionOutcome {
121119
/// Successful payjoin
122120
Success(bitcoin::Psbt),

0 commit comments

Comments
 (0)