Skip to content

Commit c3015bc

Browse files
committed
Fix macro optional and tuple processing
1 parent 551fd74 commit c3015bc

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

proc/src/generator.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::properties::StructProperty;
88
pub struct FunctionDescriptionTokens {
99
pub body: proc_macro2::TokenStream,
1010
pub input: proc_macro2::TokenStream,
11-
pub output: proc_macro2::TokenStream,
11+
pub output: Option<proc_macro2::TokenStream>,
1212

1313
pub inner_models: Vec<proc_macro2::TokenStream>,
1414
}
@@ -42,7 +42,7 @@ impl StructGenerator {
4242
FunctionDescriptionTokens {
4343
body: func,
4444
input: input_token,
45-
output: output_token,
45+
output: Some(output_token),
4646
inner_models: inner_modes,
4747
}
4848
}
@@ -63,7 +63,7 @@ impl StructGenerator {
6363
FunctionDescriptionTokens {
6464
body: func,
6565
input: input_token,
66-
output: proc_macro2::TokenStream::default(), //event has no output
66+
output: None, //event has no output
6767
inner_models: inner_modes,
6868
}
6969
}
@@ -216,9 +216,17 @@ impl StructGenerator {
216216
is_event: bool,
217217
) -> proc_macro2::TokenStream {
218218
let struct_name = if is_event {
219-
format!("{}EventInput", name.to_camel())
219+
if name.starts_with("_") {
220+
format!("{}EventInputExt", name.to_camel())
221+
} else {
222+
format!("{}EventInput", name.to_camel())
223+
}
220224
} else {
221-
format!("{}FunctionInput", name.to_camel())
225+
if name.starts_with("_") {
226+
format!("{}FunctionInputExt", name.to_camel())
227+
} else {
228+
format!("{}FunctionInput", name.to_camel())
229+
}
222230
};
223231
let model = self.generate_model(&struct_name, inputs.clone());
224232

@@ -235,9 +243,13 @@ impl StructGenerator {
235243
name: &str,
236244
outputs: Arc<[NamedAbiType]>,
237245
) -> proc_macro2::TokenStream {
238-
let struct_name = format!("{}FunctionOutput", name.to_camel());
246+
let struct_name = if name.starts_with("_") {
247+
format!("{}FunctionOutputExt", name.to_camel())
248+
} else {
249+
format!("{}FunctionOutput", name.to_camel())
250+
};
251+
239252
let model = self.generate_model(&struct_name, outputs.clone());
240-
241253
if !self.generated_structs.contains_key(&struct_name) {
242254
self.generated_structs
243255
.insert(struct_name.clone(), outputs.to_vec());
@@ -301,6 +313,10 @@ impl StructGenerator {
301313
type_name: syn::parse_str(ty).unwrap(),
302314
}
303315
}
316+
AbiType::VarUint(value) if value.get() == 16 => StructProperty::Simple {
317+
name,
318+
type_name: syn::parse_quote!(everscale_types::num::Tokens),
319+
},
304320
AbiType::VarUint(_) | AbiType::VarInt(_) => StructProperty::Simple {
305321
name,
306322
type_name: syn::parse_quote!(num_bigint::BigUint),
@@ -380,7 +396,9 @@ impl StructGenerator {
380396
_ => panic!("Map key is not allowed type"),
381397
};
382398

383-
let value = self.make_struct_property(None, b.as_ref());
399+
let rust_name = name.clone().map(|x| x.to_snake()).unwrap_or_default();
400+
let value_name = format!("{rust_name}_value");
401+
let value = self.make_struct_property(Some(value_name), b.as_ref());
384402

385403
StructProperty::HashMap {
386404
name: name.unwrap_or_default(),
@@ -405,7 +423,10 @@ impl StructGenerator {
405423
type_name: syn::parse_quote!(everscale_types::num::Tokens),
406424
},
407425
AbiType::Optional(a) => {
408-
let internal_struct = self.make_struct_property(None, a.as_ref());
426+
let rust_name = name.clone().map(|x| x.to_snake()).unwrap_or_default();
427+
let rust_name = format!("{rust_name}_value");
428+
let internal_struct = self.make_struct_property(Some(rust_name), a.as_ref());
429+
409430
StructProperty::Option {
410431
name: name.unwrap_or_default(),
411432
internal: Box::new(internal_struct),
@@ -511,8 +532,9 @@ fn quote_abi_type(ty: &AbiType) -> proc_macro2::TokenStream {
511532
let value_type = quote_abi_type(&value);
512533
syn::parse_quote!(everscale_types::abi::AbiType::Map(#key_type, std::sync::Arc::new(#value_type)))
513534
}
514-
AbiType::Optional(_) => {
515-
let ty = quote_abi_type(ty);
535+
AbiType::Optional(ty) => {
536+
println!("making abi type {ty:?}");
537+
let ty = quote_abi_type(ty.as_ref());
516538
quote! {
517539
everscale_types::abi::AbiType::Optional(std::sync::Arc<#ty>)
518540
}

proc/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ pub fn abi(params: TokenStream, input: TokenStream) -> TokenStream {
6060
generated_functions.push(body);
6161

6262
generated_structs.push(input);
63-
generated_structs.push(output);
63+
if let Some(output) = output {
64+
generated_structs.push(output);
65+
}
6466
generated_structs.extend_from_slice(inner_models.as_slice());
6567
});
6668

6769
contract.events.iter().for_each(|(_, event)| {
6870
let FunctionDescriptionTokens {
6971
body,
7072
input,
71-
output,
7273
inner_models,
74+
..
7375
} = struct_gen.process_event(event);
7476

7577
generated_events.push(body);
76-
7778
generated_structs.push(input);
78-
generated_structs.push(output);
7979
generated_structs.extend_from_slice(inner_models.as_slice());
8080
});
8181

0 commit comments

Comments
 (0)