Skip to content

Commit

Permalink
Add serialize to structs
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-kaufman committed Aug 30, 2024
1 parent 6556cd2 commit fccbed0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use bitcoin::Psbt;

use pyo3::types::PyModule;
use pyo3::{IntoPy, PyObject};
use serde::{Deserialize, Deserializer};
use serde::{Deserialize, Deserializer, Serialize};

#[cfg(feature = "miniscript")]
use miniscript::{Descriptor, DescriptorPublicKey};
use pyo3::prelude::PyAnyMethods;

use crate::error::{Error, ErrorCode};

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIExtendedPubKey {
pub xpub: Xpub,
}
Expand All @@ -32,7 +32,7 @@ impl Deref for HWIExtendedPubKey {
}
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWISignature {
#[serde(deserialize_with = "from_b64")]
pub signature: Vec<u8>,
Expand All @@ -55,12 +55,12 @@ impl Deref for HWISignature {
}
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIAddress {
pub address: Address<NetworkUnchecked>,
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIPartiallySignedTransaction {
#[serde(deserialize_with = "deserialize_psbt")]
pub psbt: Psbt,
Expand All @@ -84,7 +84,7 @@ impl ToDescriptor for String {}
#[cfg(feature = "miniscript")]
impl ToDescriptor for Descriptor<DescriptorPublicKey> {}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIDescriptor<T>
where
T: ToDescriptor,
Expand All @@ -93,7 +93,7 @@ where
pub receive: Vec<T>,
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIKeyPoolElement {
pub desc: String,
pub range: Vec<u32>,
Expand All @@ -103,7 +103,7 @@ pub struct HWIKeyPoolElement {
pub watchonly: bool,
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
#[allow(non_camel_case_types)]
pub enum HWIAddressType {
Legacy,
Expand Down Expand Up @@ -138,7 +138,7 @@ impl IntoPy<PyObject> for HWIAddressType {
}
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIChain(bitcoin::Network);

impl fmt::Display for HWIChain {
Expand Down Expand Up @@ -186,7 +186,7 @@ pub const TESTNET: HWIChain = HWIChain(Network::Testnet);
// Used internally to deserialize the result of `hwi enumerate`. This might
// contain an `error`, when it does, it might not contain all the fields `HWIDevice`
// is supposed to have - for this reason, they're all Option.
#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub(crate) struct HWIDeviceInternal {
#[serde(rename(deserialize = "type"))]
pub device_type: Option<String>,
Expand All @@ -199,7 +199,7 @@ pub(crate) struct HWIDeviceInternal {
pub code: Option<i8>,
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIDevice {
#[serde(rename(deserialize = "type"))]
pub device_type: HWIDeviceType,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl TryFrom<HWIDeviceInternal> for HWIDevice {
}
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct HWIStatus {
pub success: bool,
}
Expand All @@ -256,7 +256,7 @@ impl From<HWIStatus> for Result<(), Error> {
}
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum HWIDeviceType {
Ledger,
Expand Down

0 comments on commit fccbed0

Please sign in to comment.