From a8b95dc966790c6c34eb48e8f6b35a32b05507fa Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 15 Dec 2024 22:15:05 +0100 Subject: [PATCH] seals: add serde support --- Cargo.lock | 1 + single_use_seals/Cargo.toml | 3 ++- single_use_seals/src/lib.rs | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 52c2b515..a278122c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,6 +382,7 @@ dependencies = [ name = "single_use_seals" version = "0.12.0-beta.1" dependencies = [ + "serde", "strict_encoding", ] diff --git a/single_use_seals/Cargo.toml b/single_use_seals/Cargo.toml index 364bc9e7..bd6be1b5 100644 --- a/single_use_seals/Cargo.toml +++ b/single_use_seals/Cargo.toml @@ -18,10 +18,11 @@ path = "src/lib.rs" [dependencies] strict_encoding = { workspace = true, optional = true } +serde = { workspace = true, optional = true } [features] default = [] -all = ["strict_encoding"] +all = ["strict_encoding", "serde"] [package.metadata.docs.rs] features = ["all"] diff --git a/single_use_seals/src/lib.rs b/single_use_seals/src/lib.rs index b99e0b60..5615c59e 100644 --- a/single_use_seals/src/lib.rs +++ b/single_use_seals/src/lib.rs @@ -107,6 +107,10 @@ #[macro_use] extern crate strict_encoding; +#[cfg(feature = "serde")] +#[macro_use] +extern crate serde; + use core::borrow::Borrow; use core::convert::Infallible; use core::error::Error; @@ -202,11 +206,18 @@ pub trait PublishedWitness { derive(StrictType, StrictDumb, StrictEncode, StrictDecode), strict_type(lib = "SingleUseSeals") )] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(bound = "Seal::PubWitness: serde::Serialize + for<'d> serde::Deserialize<'d>, \ + Seal::CliWitness: serde::Serialize + for<'d> serde::Deserialize<'d>") +)] pub struct SealWitness where Seal: SingleUseSeal { pub published: Seal::PubWitness, pub client: Seal::CliWitness, + #[cfg_attr(feature = "serde", serde(skip))] #[cfg_attr(feature = "strict_encoding", strict_type(skip))] _phantom: PhantomData, }