From 0d29bb06b3f7cb7fcb8f0749c3b2ad105a5551dd Mon Sep 17 00:00:00 2001 From: glihm Date: Thu, 29 Aug 2024 22:48:47 -0600 Subject: [PATCH] fix: add derives to legacy macro (#53) --- crates/rs-macro/src/lib.rs | 2 +- crates/rs-macro/src/macro_inputs_legacy.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/rs-macro/src/lib.rs b/crates/rs-macro/src/lib.rs index c2c5ce0..dac8a80 100644 --- a/crates/rs-macro/src/lib.rs +++ b/crates/rs-macro/src/lib.rs @@ -65,7 +65,7 @@ fn abigen_internal_legacy(input: TokenStream) -> TokenStream { &contract_name.to_string(), &abi_tokens, cainome_rs::ExecutionVersion::V1, - &[], + &contract_abi.derives, ); if let Some(out_path) = contract_abi.output_path { diff --git a/crates/rs-macro/src/macro_inputs_legacy.rs b/crates/rs-macro/src/macro_inputs_legacy.rs index e95967b..43cd6d1 100644 --- a/crates/rs-macro/src/macro_inputs_legacy.rs +++ b/crates/rs-macro/src/macro_inputs_legacy.rs @@ -35,6 +35,7 @@ pub(crate) struct ContractAbiLegacy { pub abi: Vec, pub output_path: Option, pub type_aliases: HashMap, + pub derives: Vec, } impl Parse for ContractAbiLegacy { @@ -87,6 +88,7 @@ impl Parse for ContractAbiLegacy { let mut output_path: Option = None; let mut type_aliases = HashMap::new(); + let mut derives = Vec::new(); loop { if input.parse::().is_err() { @@ -131,6 +133,15 @@ impl Parse for ContractAbiLegacy { parenthesized!(content in input); output_path = Some(content.parse::()?.value()); } + "derives" => { + let content; + parenthesized!(content in input); + let parsed = content.parse_terminated(Spanned::::parse, Token![,])?; + + for derive in parsed { + derives.push(derive.to_token_stream().to_string()); + } + } _ => emit_error!(name.span(), format!("unexpected named parameter `{name}`")), } } @@ -140,6 +151,7 @@ impl Parse for ContractAbiLegacy { abi, output_path, type_aliases, + derives, }) } }