From 1fe20e27fe65010bd76b5814160d90ecd58a5ab4 Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Mon, 19 Feb 2024 01:36:17 +0800 Subject: [PATCH] fix serialization/deserialization of some enum types (#55) --- src/receipt.rs | 18 +++++++++++++++--- src/transaction/mod.rs | 12 ++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/receipt.rs b/src/receipt.rs index a5026a3..23ab8e6 100644 --- a/src/receipt.rs +++ b/src/receipt.rs @@ -84,7 +84,11 @@ impl EnvelopedDecodable for ReceiptV1 { feature = "with-codec", derive(codec::Encode, codec::Decode, scale_info::TypeInfo) )] -#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "with-serde", + derive(serde::Serialize, serde::Deserialize), + serde(untagged) +)] pub enum ReceiptV2 { /// Legacy receipt type Legacy(EIP658ReceiptData), @@ -147,7 +151,11 @@ impl From for EIP658ReceiptData { feature = "with-codec", derive(codec::Encode, codec::Decode, scale_info::TypeInfo) )] -#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "with-serde", + derive(serde::Serialize, serde::Deserialize), + serde(untagged) +)] pub enum ReceiptV3 { /// Legacy receipt type Legacy(EIP658ReceiptData), @@ -219,7 +227,11 @@ impl From for EIP658ReceiptData { feature = "with-codec", derive(codec::Encode, codec::Decode, scale_info::TypeInfo) )] -#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "with-serde", + derive(serde::Serialize, serde::Deserialize), + serde(untagged) +)] pub enum ReceiptAny { /// Frontier receipt type Frontier(FrontierReceiptData), diff --git a/src/transaction/mod.rs b/src/transaction/mod.rs index 86cd63a..ba9a575 100644 --- a/src/transaction/mod.rs +++ b/src/transaction/mod.rs @@ -40,7 +40,11 @@ impl EnvelopedDecodable for TransactionV0 { feature = "with-codec", derive(codec::Encode, codec::Decode, scale_info::TypeInfo) )] -#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "with-serde", + derive(serde::Serialize, serde::Deserialize), + serde(untagged) +)] pub enum TransactionV1 { /// Legacy transaction type Legacy(LegacyTransaction), @@ -103,7 +107,11 @@ impl EnvelopedDecodable for TransactionV1 { feature = "with-codec", derive(codec::Encode, codec::Decode, scale_info::TypeInfo) )] -#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "with-serde", + derive(serde::Serialize, serde::Deserialize), + serde(untagged) +)] pub enum TransactionV2 { /// Legacy transaction type Legacy(LegacyTransaction),