Skip to content

Commit

Permalink
fix: add derives to legacy macro (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm authored Aug 30, 2024
1 parent d374921 commit 0d29bb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/rs-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions crates/rs-macro/src/macro_inputs_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) struct ContractAbiLegacy {
pub abi: Vec<RawLegacyAbiEntry>,
pub output_path: Option<String>,
pub type_aliases: HashMap<String, String>,
pub derives: Vec<String>,
}

impl Parse for ContractAbiLegacy {
Expand Down Expand Up @@ -87,6 +88,7 @@ impl Parse for ContractAbiLegacy {

let mut output_path: Option<String> = None;
let mut type_aliases = HashMap::new();
let mut derives = Vec::new();

loop {
if input.parse::<Token![,]>().is_err() {
Expand Down Expand Up @@ -131,6 +133,15 @@ impl Parse for ContractAbiLegacy {
parenthesized!(content in input);
output_path = Some(content.parse::<LitStr>()?.value());
}
"derives" => {
let content;
parenthesized!(content in input);
let parsed = content.parse_terminated(Spanned::<Type>::parse, Token![,])?;

for derive in parsed {
derives.push(derive.to_token_stream().to_string());
}
}
_ => emit_error!(name.span(), format!("unexpected named parameter `{name}`")),
}
}
Expand All @@ -140,6 +151,7 @@ impl Parse for ContractAbiLegacy {
abi,
output_path,
type_aliases,
derives,
})
}
}
Expand Down

0 comments on commit 0d29bb0

Please sign in to comment.