From 0d60028452686def6d6acade57c73daecc3db252 Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 8 Mar 2024 13:46:27 +0100 Subject: [PATCH] add missing serde feature cfg attributes --- Cargo.lock | 1 + Cargo.toml | 1 + src/descriptor.rs | 18 +++++++++--------- src/runtime.rs | 7 ++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 613d946..f98481a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1654,6 +1654,7 @@ dependencies = [ "bp-esplora", "bp-std", "bp-wallet", + "cfg_eval", "chrono", "commit_verify", "descriptors", diff --git a/Cargo.toml b/Cargo.toml index e500ede..a008771 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,7 @@ serde_crate = { workspace = true, optional = true } serde_yaml = { workspace = true, optional = true } serde_with = { workspace = true, optional = true } log = { workspace = true, optional = true } +cfg_eval = "0.1.2" [features] default = ["esplora_blocking"] diff --git a/src/descriptor.rs b/src/descriptor.rs index 75107e2..8c9c80a 100644 --- a/src/descriptor.rs +++ b/src/descriptor.rs @@ -50,8 +50,8 @@ pub trait DescriptorRgb: Descriptor { } #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)] -#[derive(Serialize, Deserialize)] -#[serde(crate = "serde_crate", rename_all = "camelCase")] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "serde_crate", rename_all = "camelCase"))] #[repr(u8)] pub enum RgbKeychain { #[display("0", alt = "0")] @@ -106,15 +106,15 @@ impl From for Keychain { fn from(keychain: RgbKeychain) -> Self { Keychain::from(keychain as u8) } } -#[serde_as] +#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)] #[derive(Clone, Eq, PartialEq, Debug)] -#[derive(Serialize, Deserialize)] -#[serde(crate = "serde_crate", rename_all = "camelCase")] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "serde_crate", rename_all = "camelCase"))] pub struct TapretKey { pub internal_key: K, // TODO: Allow multiple tweaks per index by introducing derivation using new Terminal trait // TODO: Change serde implementation for both Terminal and TapretCommitment - #[serde_as(as = "HashMap")] + #[cfg_attr(feature = "serde", serde_as(as = "HashMap"))] pub tweaks: HashMap, } @@ -224,15 +224,15 @@ impl DescriptorRgb for TapretKey { } #[derive(Clone, Eq, PartialEq, Debug, From)] -#[derive(Serialize, Deserialize)] -#[serde( +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde( crate = "serde_crate", rename_all = "camelCase", bound( serialize = "S::Compr: serde::Serialize, S::XOnly: serde::Serialize", deserialize = "S::Compr: serde::Deserialize<'de>, S::XOnly: serde::Deserialize<'de>" ) -)] +))] #[non_exhaustive] pub enum RgbDescr { #[from] diff --git a/src/runtime.rs b/src/runtime.rs index 84947cd..43bad09 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -24,6 +24,7 @@ use std::collections::HashMap; use std::convert::Infallible; use std::io; +#[cfg(feature = "serde")] use std::io::ErrorKind; use std::ops::{Deref, DerefMut}; use std::path::PathBuf; @@ -31,6 +32,7 @@ use std::path::PathBuf; use amplify::IoError; use bpstd::{Network, XpubDerivable}; use bpwallet::Wallet; +#[cfg(feature = "serde")] use rgbfs::StockFs; use rgbstd::containers::{Contract, LoadError, Transfer}; use rgbstd::interface::{ @@ -43,7 +45,9 @@ use rgbstd::persistence::{ use rgbstd::resolvers::ResolveHeight; use rgbstd::validation::{self, ResolveWitness}; use rgbstd::{AssignmentWitness, ContractId, WitnessId, XChain, XOutpoint}; -use strict_types::encoding::{DecodeError, DeserializeError, Ident, SerializeError, TypeName}; +use strict_types::encoding::{DeserializeError, Ident, SerializeError, TypeName}; +#[cfg(feature = "serde")] +use strict_types::encoding::DecodeError; use crate::{DescriptorRgb, RgbDescr}; @@ -109,6 +113,7 @@ pub enum RuntimeError { #[from] Esplora(esplora::Error), + #[cfg(feature = "serde")] #[from] Yaml(serde_yaml::Error),