|
1 | | -use crate::parse::{GroupedVariants, ProcessedVariant, VariantKind}; |
2 | | -use alloy_primitives::U8; |
| 1 | +use crate::parse::{GroupedVariants, ProcessedVariant}; |
3 | 2 | use proc_macro2::TokenStream; |
4 | 3 | use quote::quote; |
5 | 4 | use syn::{Ident, Path}; |
@@ -87,44 +86,28 @@ impl<'a> SerdeGenerator<'a> { |
87 | 86 | self.variants |
88 | 87 | .typed |
89 | 88 | .iter() |
90 | | - .filter_map(|v| { |
| 89 | + .map(|v| { |
91 | 90 | let ProcessedVariant { name, ty, kind, serde_attrs, typed: _, doc_attrs: _ } = v; |
92 | 91 |
|
93 | | - if let VariantKind::Typed(tx_type) = kind { |
94 | | - let tx_type = U8::from(*tx_type); |
95 | | - let rename = format!("0x{tx_type:x}"); |
| 92 | + let (rename, aliases) = kind.serde_tag_and_aliases(); |
96 | 93 |
|
97 | | - let mut aliases = vec![]; |
98 | | - // Add alias for single digit hex values (e.g., "0x0" for "0x00") |
99 | | - if rename.len() == 3 { |
100 | | - aliases.push(format!("0x0{}", rename.chars().last().unwrap())); |
| 94 | + // Special handling for legacy transactions |
| 95 | + let maybe_with = if v.is_legacy() { |
| 96 | + let alloy_consensus = &self.alloy_consensus; |
| 97 | + let path = quote! { |
| 98 | + #alloy_consensus::transaction::signed_legacy_serde |
101 | 99 | } |
| 100 | + .to_string(); |
| 101 | + quote! { with = #path, } |
| 102 | + } else { |
| 103 | + quote! {} |
| 104 | + }; |
102 | 105 |
|
103 | | - // Add alias for uppercase values (e.g., "0x7E" for "0x7e") |
104 | | - if rename != rename.to_uppercase() { |
105 | | - aliases.push(rename.to_uppercase()); |
106 | | - } |
| 106 | + let maybe_other = serde_attrs.clone().unwrap_or_default(); |
107 | 107 |
|
108 | | - // Special handling for legacy transactions |
109 | | - let maybe_with = if v.is_legacy() { |
110 | | - let alloy_consensus = &self.alloy_consensus; |
111 | | - let path = quote! { |
112 | | - #alloy_consensus::transaction::signed_legacy_serde |
113 | | - } |
114 | | - .to_string(); |
115 | | - quote! { with = #path, } |
116 | | - } else { |
117 | | - quote! {} |
118 | | - }; |
119 | | - |
120 | | - let maybe_other = serde_attrs.clone().unwrap_or_default(); |
121 | | - |
122 | | - Some(quote! { |
123 | | - #[serde(rename = #rename, #(alias = #aliases,)* #maybe_with #maybe_other)] |
124 | | - #name(#ty) |
125 | | - }) |
126 | | - } else { |
127 | | - None |
| 108 | + quote! { |
| 109 | + #[serde(rename = #rename, #(alias = #aliases,)* #maybe_with #maybe_other)] |
| 110 | + #name(#ty) |
128 | 111 | } |
129 | 112 | }) |
130 | 113 | .collect() |
|
0 commit comments