From d9114fc3091166c4e3c91a2f598f313696ad9cd6 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Tue, 19 Mar 2024 00:35:29 +0200 Subject: [PATCH 01/25] add enum in proxy --- .../src/crowdfunding_esdt.rs | 1 + .../crowdfunding-esdt/src/temp_proxy.rs | 157 ++++++++++++++++++ framework/base/src/abi/type_description.rs | 24 +++ .../wrapped/egld_or_esdt_token_identifier.rs | 4 + .../contract/generate_proxy/proxy_gen_main.rs | 4 +- .../generate_proxy/proxy_template_gen.rs | 21 +++ 6 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 contracts/examples/crowdfunding-esdt/src/temp_proxy.rs diff --git a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs index 8fa04d2e46..5b4af4b037 100644 --- a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs +++ b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs @@ -1,6 +1,7 @@ #![no_std] use multiversx_sc::{derive_imports::*, imports::*}; +pub mod temp_proxy; #[derive(TopEncode, TopDecode, TypeAbi, PartialEq, Eq, Clone, Copy, Debug)] pub enum Status { diff --git a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs new file mode 100644 index 0000000000..1e197ae2f1 --- /dev/null +++ b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs @@ -0,0 +1,157 @@ +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(clippy::all)] + +use multiversx_sc::imports::*; + +pub enum Status { + FundingPeriod, + Successful, + Failed, +} +pub struct CrowdfundingProxy; + +impl TxProxyTrait for CrowdfundingProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = CrowdfundingProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + CrowdfundingProxyMethods { wrapped_tx: tx } + } +} + +pub struct CrowdfundingProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +impl CrowdfundingProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init< + Arg0: CodecInto>, + Arg1: CodecInto, + Arg2: CodecInto>, + >( + self, + target: Arg0, + deadline: Arg1, + token_identifier: Arg2, + ) -> Tx, OriginalResultMarker<()>> { + self.wrapped_tx + .raw_deploy() + .argument(&target) + .argument(&deadline) + .argument(&token_identifier) + .original_result() + } +} +impl CrowdfundingProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn fund( + self, + ) -> Tx, OriginalResultMarker<()>> { + self.wrapped_tx + .raw_call() + .function_name("fund") + .original_result() + } + + pub fn status( + self, + ) -> Tx, OriginalResultMarker> { + self.wrapped_tx + .raw_call() + .function_name("status") + .original_result() + } + + pub fn get_current_funds( + self, + ) -> Tx, OriginalResultMarker>> + { + self.wrapped_tx + .raw_call() + .function_name("getCurrentFunds") + .original_result() + } + + pub fn claim( + self, + ) -> Tx, OriginalResultMarker<()>> { + self.wrapped_tx + .raw_call() + .function_name("claim") + .original_result() + } + + pub fn target( + self, + ) -> Tx, OriginalResultMarker>> + { + self.wrapped_tx + .raw_call() + .function_name("getTarget") + .original_result() + } + + pub fn deadline( + self, + ) -> Tx, OriginalResultMarker> { + self.wrapped_tx + .raw_call() + .function_name("getDeadline") + .original_result() + } + + pub fn deposit>>( + self, + donor: Arg0, + ) -> Tx, OriginalResultMarker>> + { + self.wrapped_tx + .raw_call() + .function_name("getDeposit") + .argument(&donor) + .original_result() + } + + pub fn cf_token_identifier( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("getCrowdfundingTokenIdentifier") + .original_result() + } +} diff --git a/framework/base/src/abi/type_description.rs b/framework/base/src/abi/type_description.rs index b9755fcaae..4084ffd85a 100644 --- a/framework/base/src/abi/type_description.rs +++ b/framework/base/src/abi/type_description.rs @@ -50,6 +50,30 @@ impl TypeContents { pub fn is_specified(&self) -> bool { !matches!(*self, TypeContents::NotSpecified) } + + pub fn extract_names(&self) -> Vec { + let mut names = Vec::new(); + match &self { + TypeContents::Enum(enum_variants) => { + for enum_variant in enum_variants.into_iter() { + names.push(enum_variant.name.clone()); + } + }, + TypeContents::Struct(struct_fields) => { + for struct_field in struct_fields { + todo!() + } + }, + TypeContents::ExplicitEnum(explicit_enum_variants) => { + for explicit_enum_variant in explicit_enum_variants { + todo!() + } + }, + TypeContents::NotSpecified => {}, + } + + names + } } #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/framework/base/src/types/managed/wrapped/egld_or_esdt_token_identifier.rs b/framework/base/src/types/managed/wrapped/egld_or_esdt_token_identifier.rs index ed2c7083a7..3635ddaba2 100644 --- a/framework/base/src/types/managed/wrapped/egld_or_esdt_token_identifier.rs +++ b/framework/base/src/types/managed/wrapped/egld_or_esdt_token_identifier.rs @@ -214,6 +214,10 @@ impl TypeAbi for EgldOrEsdtTokenIdentifier { fn type_name() -> TypeName { "EgldOrEsdtTokenIdentifier".into() } + + fn type_name_rust() -> TypeName { + "EgldOrEsdtTokenIdentifier<$API>".into() + } } impl SCDisplay for EgldOrEsdtTokenIdentifier { diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs index 3510eb640a..93cdb7a8e6 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs @@ -9,7 +9,8 @@ use super::{ proxy_crate_gen::create_file, proxy_sc_functions_gen::write_content, proxy_template_gen::{ - write_header, write_impl_for_tx_proxy, write_struct_template, write_struct_tx_proxy_methods, + write_header, write_impl_for_tx_proxy, write_struct_template, + write_struct_tx_proxy_methods, write_types, }, }; @@ -24,6 +25,7 @@ impl MetaConfig { fn write_proxies_to_file(mut file: File, abi: ContractAbi) { write_header(&mut file); + write_types(&mut file, &abi.type_descriptions); write_struct_template(&mut file, &abi.name); write_impl_for_tx_proxy(&mut file, &abi.name); write_struct_tx_proxy_methods(&mut file, &abi.name); diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 71dc2e2287..7dfdd56c1a 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -1,5 +1,7 @@ use std::{fs::File, io::Write}; +use multiversx_sc::abi::{TypeContents, TypeDescription, TypeDescriptionContainerImpl}; + use crate::cmd::contract::generate_snippets::snippet_gen_common::write_newline; use super::proxy_naming::{proxy_methods_type_name, proxy_type_name}; @@ -20,6 +22,14 @@ pub(crate) fn write_header(file: &mut File) { write_newline(file); } +pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) { + for t in types.0.iter() { + if matches!(t.1.contents, TypeContents::Enum(_)) { + write_enum(file, &t.1); + } + } +} + pub(crate) fn write_struct_template(file: &mut File, name: &str) { let proxy_type_name = proxy_type_name(name); writeln!(file, "pub struct {proxy_type_name};").unwrap(); @@ -68,3 +78,14 @@ where write_newline(file); } + +fn write_enum(file: &mut File, type_description: &TypeDescription) { + writeln!(file, r#"pub enum {} {{"#, type_description.names.abi).unwrap(); + + for content in type_description.contents.extract_names() { + writeln!(file, " {content},").unwrap(); + } + + writeln!(file, "}}").unwrap(); + write_newline(file); +} From 0d8124425bedd720c67af4770cedbdf2275b2c8f Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 19 Mar 2024 10:52:02 +0200 Subject: [PATCH 02/25] tx proxy gen - TypeAbi derive rust name fix --- framework/derive/src/type_abi_derive.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/derive/src/type_abi_derive.rs b/framework/derive/src/type_abi_derive.rs index 2d5848cc2d..bdbe24208f 100644 --- a/framework/derive/src/type_abi_derive.rs +++ b/framework/derive/src/type_abi_derive.rs @@ -122,6 +122,10 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { #name_str.into() } + fn type_name_rust() -> multiversx_sc::abi::TypeName { + #name_str.into() + } + #type_description_impl } }; From 1c0fc9ded24a42f2e8c662e511247d1d71d9daa9 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Tue, 19 Mar 2024 15:45:59 +0200 Subject: [PATCH 03/25] tx proxy gen - extract attributes macro --- .../crowdfunding-esdt/src/crowdfunding_esdt.rs | 3 ++- framework/base/src/abi/type_description.rs | 16 ++++++++-------- framework/derive/src/lib.rs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs index 5b4af4b037..e82411c0e1 100644 --- a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs +++ b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs @@ -3,7 +3,8 @@ use multiversx_sc::{derive_imports::*, imports::*}; pub mod temp_proxy; -#[derive(TopEncode, TopDecode, TypeAbi, PartialEq, Eq, Clone, Copy, Debug)] +#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] pub enum Status { FundingPeriod, Successful, diff --git a/framework/base/src/abi/type_description.rs b/framework/base/src/abi/type_description.rs index 4084ffd85a..b127e1844e 100644 --- a/framework/base/src/abi/type_description.rs +++ b/framework/base/src/abi/type_description.rs @@ -59,15 +59,15 @@ impl TypeContents { names.push(enum_variant.name.clone()); } }, - TypeContents::Struct(struct_fields) => { - for struct_field in struct_fields { - todo!() - } + TypeContents::Struct(_struct_fields) => { + // for struct_field in struct_fields { + // todo!() + // } }, - TypeContents::ExplicitEnum(explicit_enum_variants) => { - for explicit_enum_variant in explicit_enum_variants { - todo!() - } + TypeContents::ExplicitEnum(_explicit_enum_variants) => { + // for explicit_enum_variant in explicit_enum_variants { + // todo!() + // } }, TypeContents::NotSpecified => {}, } diff --git a/framework/derive/src/lib.rs b/framework/derive/src/lib.rs index a68d493c97..66531e3205 100644 --- a/framework/derive/src/lib.rs +++ b/framework/derive/src/lib.rs @@ -48,7 +48,18 @@ pub fn proxy( #[proc_macro_derive(TypeAbi)] pub fn type_abi_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let ast = syn::parse(input).unwrap(); + let ast: syn::DeriveInput = syn::parse(input).unwrap(); + for a in ast.clone().attrs { + match &a.meta { + syn::Meta::Path(_path) => {}, + syn::Meta::List(list) => { + for token in ::clone(&list.tokens).into_iter() { + println!(">>>{}", token.to_string()); + } + }, + syn::Meta::NameValue(_name_value) => {}, + } + } type_abi_derive::type_abi_derive(&ast) } From 37de8ba950a60c1114fad8e410b2d656d248efa3 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Wed, 20 Mar 2024 00:31:22 +0200 Subject: [PATCH 04/25] tx proxy gen - add macro_attibutes in proxy for enum --- .../crowdfunding-esdt/src/temp_proxy.rs | 92 ++++++++++++++++--- framework/base/src/abi/type_abi.rs | 1 + framework/base/src/abi/type_description.rs | 12 ++- .../types/io/operation_completion_status.rs | 1 + framework/derive/src/lib.rs | 11 --- .../derive/src/parse/attributes/doc_attr.rs | 14 +++ framework/derive/src/parse/attributes/mod.rs | 2 +- framework/derive/src/type_abi_derive.rs | 6 ++ framework/meta/src/abi_json/type_abi_json.rs | 1 + .../generate_proxy/proxy_template_gen.rs | 15 +++ 10 files changed, 129 insertions(+), 26 deletions(-) diff --git a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs index 1e197ae2f1..1c4d10dbb9 100644 --- a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs +++ b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs @@ -6,11 +6,14 @@ use multiversx_sc::imports::*; +#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] pub enum Status { FundingPeriod, Successful, Failed, } + pub struct CrowdfundingProxy; impl TxProxyTrait for CrowdfundingProxy @@ -53,7 +56,15 @@ where target: Arg0, deadline: Arg1, token_identifier: Arg2, - ) -> Tx, OriginalResultMarker<()>> { + ) -> Tx< + Env, + From, + (), + (), + Gas, + DeployCall, + OriginalResultMarker<()>, + > { self.wrapped_tx .raw_deploy() .argument(&target) @@ -61,6 +72,7 @@ where .argument(&token_identifier) .original_result() } + } impl CrowdfundingProxyMethods where @@ -72,7 +84,15 @@ where { pub fn fund( self, - ) -> Tx, OriginalResultMarker<()>> { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { self.wrapped_tx .raw_call() .function_name("fund") @@ -81,7 +101,15 @@ where pub fn status( self, - ) -> Tx, OriginalResultMarker> { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { self.wrapped_tx .raw_call() .function_name("status") @@ -90,8 +118,15 @@ where pub fn get_current_funds( self, - ) -> Tx, OriginalResultMarker>> - { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { self.wrapped_tx .raw_call() .function_name("getCurrentFunds") @@ -100,7 +135,15 @@ where pub fn claim( self, - ) -> Tx, OriginalResultMarker<()>> { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { self.wrapped_tx .raw_call() .function_name("claim") @@ -109,8 +152,15 @@ where pub fn target( self, - ) -> Tx, OriginalResultMarker>> - { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { self.wrapped_tx .raw_call() .function_name("getTarget") @@ -119,18 +169,35 @@ where pub fn deadline( self, - ) -> Tx, OriginalResultMarker> { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { self.wrapped_tx .raw_call() .function_name("getDeadline") .original_result() } - pub fn deposit>>( + pub fn deposit< + Arg0: CodecInto>, + >( self, donor: Arg0, - ) -> Tx, OriginalResultMarker>> - { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { self.wrapped_tx .raw_call() .function_name("getDeposit") @@ -154,4 +221,5 @@ where .function_name("getCrowdfundingTokenIdentifier") .original_result() } + } diff --git a/framework/base/src/abi/type_abi.rs b/framework/base/src/abi/type_abi.rs index 62633e2a70..215cb36464 100644 --- a/framework/base/src/abi/type_abi.rs +++ b/framework/base/src/abi/type_abi.rs @@ -29,6 +29,7 @@ pub trait TypeAbi { docs: Vec::new(), names: Self::type_names(), contents: TypeContents::NotSpecified, + macro_attributes: Vec::new() }, ); } diff --git a/framework/base/src/abi/type_description.rs b/framework/base/src/abi/type_description.rs index b127e1844e..cee01bfa58 100644 --- a/framework/base/src/abi/type_description.rs +++ b/framework/base/src/abi/type_description.rs @@ -10,6 +10,7 @@ pub struct TypeDescription { pub docs: Vec, pub names: TypeNames, pub contents: TypeContents, + pub macro_attributes: Vec, } impl TypeDescription { @@ -24,16 +25,23 @@ impl TypeDescription { rust: String::new(), }, contents: TypeContents::NotSpecified, + macro_attributes: Vec::new(), }; } impl TypeDescription { /// Used in code generation. - pub fn new(docs: &[&str], names: TypeNames, contents: TypeContents) -> Self { + pub fn new( + docs: &[&str], + names: TypeNames, + contents: TypeContents, + macro_attributes: &[&str], + ) -> Self { TypeDescription { docs: docs.iter().map(|s| s.to_string()).collect(), names, contents, + macro_attributes: macro_attributes.iter().map(|s| s.to_string()).collect(), } } } @@ -55,7 +63,7 @@ impl TypeContents { let mut names = Vec::new(); match &self { TypeContents::Enum(enum_variants) => { - for enum_variant in enum_variants.into_iter() { + for enum_variant in enum_variants { names.push(enum_variant.name.clone()); } }, diff --git a/framework/base/src/types/io/operation_completion_status.rs b/framework/base/src/types/io/operation_completion_status.rs index 207b9d760f..b69af9624a 100644 --- a/framework/base/src/types/io/operation_completion_status.rs +++ b/framework/base/src/types/io/operation_completion_status.rs @@ -98,6 +98,7 @@ impl TypeAbi for OperationCompletionStatus { INTERRUPTED_STR, ) ].to_vec()), + macro_attributes: Vec::new() }, ); } diff --git a/framework/derive/src/lib.rs b/framework/derive/src/lib.rs index 66531e3205..bdc33883fe 100644 --- a/framework/derive/src/lib.rs +++ b/framework/derive/src/lib.rs @@ -49,17 +49,6 @@ pub fn proxy( #[proc_macro_derive(TypeAbi)] pub fn type_abi_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let ast: syn::DeriveInput = syn::parse(input).unwrap(); - for a in ast.clone().attrs { - match &a.meta { - syn::Meta::Path(_path) => {}, - syn::Meta::List(list) => { - for token in ::clone(&list.tokens).into_iter() { - println!(">>>{}", token.to_string()); - } - }, - syn::Meta::NameValue(_name_value) => {}, - } - } type_abi_derive::type_abi_derive(&ast) } diff --git a/framework/derive/src/parse/attributes/doc_attr.rs b/framework/derive/src/parse/attributes/doc_attr.rs index c2a670abb5..d9d3b22658 100644 --- a/framework/derive/src/parse/attributes/doc_attr.rs +++ b/framework/derive/src/parse/attributes/doc_attr.rs @@ -45,6 +45,20 @@ pub fn extract_doc(attrs: &[syn::Attribute]) -> Vec { .collect() } +pub fn extract_macro_attributes(attrs: &[syn::Attribute]) -> Vec { + let mut macro_attributes = Vec::new(); + + for a in attrs { + if let syn::Meta::List(list) = &a.meta { + for token in list.tokens.clone().into_iter() { + macro_attributes.push(token.to_string()); + } + } + } + + macro_attributes +} + fn remove_backslashes(input: &str) -> String { input .trim_matches('\"') diff --git a/framework/derive/src/parse/attributes/mod.rs b/framework/derive/src/parse/attributes/mod.rs index e355c78e61..e58c1a912e 100644 --- a/framework/derive/src/parse/attributes/mod.rs +++ b/framework/derive/src/parse/attributes/mod.rs @@ -11,7 +11,7 @@ mod trait_prop_names; mod util; pub use argument_attr::*; -pub use doc_attr::{extract_doc, OutputNameAttribute}; +pub use doc_attr::{extract_doc, extract_macro_attributes, OutputNameAttribute}; pub use endpoint_attr::*; pub use event_attr::*; pub use label_attr::*; diff --git a/framework/derive/src/type_abi_derive.rs b/framework/derive/src/type_abi_derive.rs index bdbe24208f..13fab6baa3 100644 --- a/framework/derive/src/type_abi_derive.rs +++ b/framework/derive/src/type_abi_derive.rs @@ -1,3 +1,5 @@ +use crate::parse::attributes::extract_macro_attributes; + use super::parse::attributes::extract_doc; use proc_macro::TokenStream; use quote::quote; @@ -45,6 +47,8 @@ fn fields_snippets(fields: &syn::Fields) -> Vec { pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { let type_docs = extract_doc(ast.attrs.as_slice()); + let macro_attributes = extract_macro_attributes(ast.attrs.as_slice()); + let type_description_impl = match &ast.data { syn::Data::Struct(data_struct) => { let struct_field_snippets = fields_snippets(&data_struct.fields); @@ -61,6 +65,7 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { &[ #(#type_docs),* ], type_names, multiversx_sc::abi::TypeContents::Struct(field_descriptions), + &[ #(#macro_attributes),* ], ), ); } @@ -104,6 +109,7 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { &[ #(#type_docs),* ], type_names, multiversx_sc::abi::TypeContents::Enum(variant_descriptions), + &[ #(#macro_attributes),* ], ), ); } diff --git a/framework/meta/src/abi_json/type_abi_json.rs b/framework/meta/src/abi_json/type_abi_json.rs index c7735f04d6..dac3f7c029 100644 --- a/framework/meta/src/abi_json/type_abi_json.rs +++ b/framework/meta/src/abi_json/type_abi_json.rs @@ -87,6 +87,7 @@ impl TypeDescriptionJson { ), _ => TypeContents::NotSpecified, }, + macro_attributes: Vec::new() } } } diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 7dfdd56c1a..1267cb839c 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -80,6 +80,7 @@ where } fn write_enum(file: &mut File, type_description: &TypeDescription) { + write_macro_attributes(file, &type_description.macro_attributes); writeln!(file, r#"pub enum {} {{"#, type_description.names.abi).unwrap(); for content in type_description.contents.extract_names() { @@ -89,3 +90,17 @@ fn write_enum(file: &mut File, type_description: &TypeDescription) { writeln!(file, "}}").unwrap(); write_newline(file); } + +fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { + writeln!(file, "#[derive(TypeAbi)]").unwrap(); + if !macro_attributes.is_empty() { + write!(file, "#[derive(").unwrap(); + } + + let attributes = macro_attributes.join("").replace(',', ", "); + write!(file, "{attributes}").unwrap(); + + if !macro_attributes.is_empty() { + writeln!(file, ")]").unwrap(); + } +} From 775f0e8208a1f15ff10d3097b10d1bb3f4e654a7 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Wed, 20 Mar 2024 10:15:59 +0200 Subject: [PATCH 05/25] tx proxy gen - add derive imports --- contracts/examples/crowdfunding-esdt/src/temp_proxy.rs | 2 ++ .../src/cmd/contract/generate_proxy/proxy_template_gen.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs index 1c4d10dbb9..98ab96c104 100644 --- a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs +++ b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs @@ -6,6 +6,8 @@ use multiversx_sc::imports::*; +use multiversx_sc::derive_imports::*; + #[derive(TypeAbi)] #[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] pub enum Status { diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 1267cb839c..25dd7a150d 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -15,6 +15,8 @@ const IMPORTS: &str = "#![allow(clippy::all)] use multiversx_sc::imports::*;"; +const DERIVE_IMPORTS: &str = "use multiversx_sc::derive_imports::*;"; + pub(crate) fn write_header(file: &mut File) { writeln!(file, "{PREFIX_AUTO_GENERATED}").unwrap(); writeln!(file, r#"{IMPORTS}"#).unwrap(); @@ -80,6 +82,7 @@ where } fn write_enum(file: &mut File, type_description: &TypeDescription) { + write_derive_imports(file); write_macro_attributes(file, &type_description.macro_attributes); writeln!(file, r#"pub enum {} {{"#, type_description.names.abi).unwrap(); @@ -104,3 +107,8 @@ fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { writeln!(file, ")]").unwrap(); } } + +fn write_derive_imports(file: &mut File) { + writeln!(file, "{DERIVE_IMPORTS}").unwrap(); + write_newline(file); +} From 4a06a1ec96297fc449093c3867feed671ffb82e6 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Wed, 20 Mar 2024 20:26:26 +0200 Subject: [PATCH 06/25] tx proxy gen - generate code for struct --- contracts/examples/crypto-zombies/src/lib.rs | 1 + .../examples/crypto-zombies/src/temp_proxy.rs | 428 ++++++++++++++++++ .../examples/crypto-zombies/src/zombie.rs | 3 +- .../examples/digital-cash/src/deposit_info.rs | 3 +- framework/base/src/abi/type_description.rs | 15 +- framework/derive/src/type_abi_derive.rs | 19 +- .../generate_proxy/proxy_template_gen.rs | 38 +- 7 files changed, 490 insertions(+), 17 deletions(-) create mode 100644 contracts/examples/crypto-zombies/src/temp_proxy.rs diff --git a/contracts/examples/crypto-zombies/src/lib.rs b/contracts/examples/crypto-zombies/src/lib.rs index f2f47688ad..ed6b9befba 100644 --- a/contracts/examples/crypto-zombies/src/lib.rs +++ b/contracts/examples/crypto-zombies/src/lib.rs @@ -9,6 +9,7 @@ mod zombie_attack; mod zombie_factory; mod zombie_feeding; mod zombie_helper; +pub mod temp_proxy; #[multiversx_sc::contract] pub trait CryptoZombies: diff --git a/contracts/examples/crypto-zombies/src/temp_proxy.rs b/contracts/examples/crypto-zombies/src/temp_proxy.rs new file mode 100644 index 0000000000..163be5ffa1 --- /dev/null +++ b/contracts/examples/crypto-zombies/src/temp_proxy.rs @@ -0,0 +1,428 @@ +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(clippy::all)] + +use multiversx_sc::imports::*; + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] +pub struct Zombie +where + Api: ManagedTypeApi, +{ + pub name: ManagedBuffer, + pub dna: u64, + pub level: u16, + pub ready_time: u64, + pub win_count: usize, + pub loss_count: usize, +} + +pub struct CryptoZombiesProxy; + +impl TxProxyTrait for CryptoZombiesProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = CryptoZombiesProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + CryptoZombiesProxyMethods { wrapped_tx: tx } + } +} + +pub struct CryptoZombiesProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +impl CryptoZombiesProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> Tx< + Env, + From, + (), + (), + Gas, + DeployCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_deploy() + .original_result() + } + +} +impl CryptoZombiesProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn set_crypto_kitties_sc_address< + Arg0: CodecInto>, + >( + self, + address: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("set_crypto_kitties_sc_address") + .argument(&address) + .original_result() + } + + pub fn generate_random_dna( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("generate_random_dna") + .original_result() + } + + pub fn create_random_zombie< + Arg0: CodecInto>, + >( + self, + name: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("create_random_zombie") + .argument(&name) + .original_result() + } + + pub fn is_ready< + Arg0: CodecInto, + >( + self, + zombie_id: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("is_ready") + .argument(&zombie_id) + .original_result() + } + + pub fn feed_on_kitty< + Arg0: CodecInto, + Arg1: CodecInto, + >( + self, + zombie_id: Arg0, + kitty_id: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("feed_on_kitty") + .argument(&zombie_id) + .argument(&kitty_id) + .original_result() + } + + pub fn dna_digits( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("dna_digits") + .original_result() + } + + pub fn zombies_count( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("zombies_count") + .original_result() + } + + pub fn zombies< + Arg0: CodecInto, + >( + self, + id: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("zombies") + .argument(&id) + .original_result() + } + + pub fn zombie_owner< + Arg0: CodecInto, + >( + self, + id: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("zombie_owner") + .argument(&id) + .original_result() + } + + pub fn crypto_kitties_sc_address( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("crypto_kitties_sc_address") + .original_result() + } + + pub fn cooldown_time( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("cooldown_time") + .original_result() + } + + pub fn owned_zombies< + Arg0: CodecInto>, + >( + self, + owner: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("owned_zombies") + .argument(&owner) + .original_result() + } + + pub fn level_up< + Arg0: CodecInto, + >( + self, + zombie_id: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("level_up") + .argument(&zombie_id) + .original_result() + } + + pub fn withdraw( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("withdraw") + .original_result() + } + + pub fn change_name< + Arg0: CodecInto, + Arg1: CodecInto>, + >( + self, + zombie_id: Arg0, + name: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("change_name") + .argument(&zombie_id) + .argument(&name) + .original_result() + } + + pub fn change_dna< + Arg0: CodecInto, + Arg1: CodecInto, + >( + self, + zombie_id: Arg0, + dna: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("change_dna") + .argument(&zombie_id) + .argument(&dna) + .original_result() + } + + pub fn attack< + Arg0: CodecInto, + Arg1: CodecInto, + >( + self, + zombie_id: Arg0, + target_id: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("attack") + .argument(&zombie_id) + .argument(&target_id) + .original_result() + } + +} diff --git a/contracts/examples/crypto-zombies/src/zombie.rs b/contracts/examples/crypto-zombies/src/zombie.rs index 414c343f28..858d1b791c 100644 --- a/contracts/examples/crypto-zombies/src/zombie.rs +++ b/contracts/examples/crypto-zombies/src/zombie.rs @@ -1,6 +1,7 @@ use multiversx_sc::{derive_imports::*, imports::*}; -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct Zombie { pub name: ManagedBuffer, pub dna: u64, diff --git a/contracts/examples/digital-cash/src/deposit_info.rs b/contracts/examples/digital-cash/src/deposit_info.rs index 9fb14661ea..0164db2090 100644 --- a/contracts/examples/digital-cash/src/deposit_info.rs +++ b/contracts/examples/digital-cash/src/deposit_info.rs @@ -1,6 +1,7 @@ use multiversx_sc::{derive_imports::*, imports::*}; -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct DepositInfo { pub depositor_address: ManagedAddress, pub esdt_funds: ManagedVec>, diff --git a/framework/base/src/abi/type_description.rs b/framework/base/src/abi/type_description.rs index cee01bfa58..011b07d00c 100644 --- a/framework/base/src/abi/type_description.rs +++ b/framework/base/src/abi/type_description.rs @@ -67,16 +67,13 @@ impl TypeContents { names.push(enum_variant.name.clone()); } }, - TypeContents::Struct(_struct_fields) => { - // for struct_field in struct_fields { - // todo!() - // } - }, - TypeContents::ExplicitEnum(_explicit_enum_variants) => { - // for explicit_enum_variant in explicit_enum_variants { - // todo!() - // } + TypeContents::Struct(struct_fields) => { + for struct_field in struct_fields { + names.push(struct_field.name.clone()); + names.push(struct_field.field_type.clone()); + } }, + TypeContents::ExplicitEnum(_explicit_enum_variants) => {}, TypeContents::NotSpecified => {}, } diff --git a/framework/derive/src/type_abi_derive.rs b/framework/derive/src/type_abi_derive.rs index 13fab6baa3..aad347ba31 100644 --- a/framework/derive/src/type_abi_derive.rs +++ b/framework/derive/src/type_abi_derive.rs @@ -2,7 +2,7 @@ use crate::parse::attributes::extract_macro_attributes; use super::parse::attributes::extract_doc; use proc_macro::TokenStream; -use quote::quote; +use quote::{quote, ToTokens}; pub struct ExplicitDiscriminant { pub variant_index: usize, @@ -21,7 +21,7 @@ fn field_snippet(index: usize, field: &syn::Field) -> proc_macro2::TokenStream { field_descriptions.push(multiversx_sc::abi::StructFieldDescription::new( &[ #(#field_docs),* ], #field_name_str, - <#field_ty>::type_name(), + <#field_ty>::type_name_rust(), )); <#field_ty>::provide_type_descriptions(accumulator); } @@ -122,6 +122,7 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { let name = &ast.ident; let name_str = name.to_string(); let (impl_generics, ty_generics, where_clause) = &ast.generics.split_for_impl(); + let name_rust = extract_rust_type(ty_generics, name_str.clone()); let type_abi_impl = quote! { impl #impl_generics multiversx_sc::abi::TypeAbi for #name #ty_generics #where_clause { fn type_name() -> multiversx_sc::abi::TypeName { @@ -129,7 +130,7 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { } fn type_name_rust() -> multiversx_sc::abi::TypeName { - #name_str.into() + #name_rust.into() } #type_description_impl @@ -180,3 +181,15 @@ pub fn get_discriminant( quote! { #next_value} } + +fn extract_rust_type(ty_generics: &syn::TypeGenerics<'_>, mut output_name: String) -> String { + let mut ty_generics_tokens = proc_macro2::TokenStream::new(); + ty_generics.to_tokens(&mut ty_generics_tokens); + + if ty_generics_tokens.to_string().is_empty() { + return output_name; + } + + output_name.push_str("<$API>"); + return output_name; +} diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 25dd7a150d..5ae0202317 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -25,9 +25,12 @@ pub(crate) fn write_header(file: &mut File) { } pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) { - for t in types.0.iter() { - if matches!(t.1.contents, TypeContents::Enum(_)) { - write_enum(file, &t.1); + for (_, type_description) in &types.0 { + match &type_description.contents { + TypeContents::Enum(_) => write_enum(file, type_description), + TypeContents::Struct(_) => write_struct(file, type_description), + TypeContents::NotSpecified => {}, + TypeContents::ExplicitEnum(_) => {}, } } } @@ -94,6 +97,35 @@ fn write_enum(file: &mut File, type_description: &TypeDescription) { write_newline(file); } +fn write_struct(file: &mut File, type_description: &TypeDescription) { + let struct_name = type_description.names.rust.replace("$API", "Api"); + + write_derive_imports(file); + write_macro_attributes(file, &type_description.macro_attributes); + writeln!(file, r#"pub struct {}"#, struct_name).unwrap(); + + if struct_name.contains("") { + writeln!( + file, + r#"where + Api: ManagedTypeApi,"# + ) + .unwrap(); + } + + writeln!(file, r#"{{"#).unwrap(); + + for content in type_description.contents.extract_names().chunks_exact(2) { + let variable_name = &content[0]; + let variable_type = &content[1].replace("$API", "Api"); + + writeln!(file, " pub {variable_name}: {variable_type},").unwrap(); + } + + writeln!(file, "}}").unwrap(); + write_newline(file); +} + fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { writeln!(file, "#[derive(TypeAbi)]").unwrap(); if !macro_attributes.is_empty() { From 1ca8287df4cc9a39e1097c78418f8748b9df8d2a Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Wed, 20 Mar 2024 20:34:26 +0200 Subject: [PATCH 07/25] tx proxy gen - cleanup --- .../examples/crypto-zombies/src/temp_proxy.rs | 32 +++++++++---------- framework/derive/src/type_abi_derive.rs | 2 +- .../contract/generate_proxy/proxy_gen_main.rs | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/contracts/examples/crypto-zombies/src/temp_proxy.rs b/contracts/examples/crypto-zombies/src/temp_proxy.rs index 163be5ffa1..32f130dfdc 100644 --- a/contracts/examples/crypto-zombies/src/temp_proxy.rs +++ b/contracts/examples/crypto-zombies/src/temp_proxy.rs @@ -6,22 +6,6 @@ use multiversx_sc::imports::*; -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct Zombie -where - Api: ManagedTypeApi, -{ - pub name: ManagedBuffer, - pub dna: u64, - pub level: u16, - pub ready_time: u64, - pub win_count: usize, - pub loss_count: usize, -} - pub struct CryptoZombiesProxy; impl TxProxyTrait for CryptoZombiesProxy @@ -426,3 +410,19 @@ where } } +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] +pub struct Zombie +where + Api: ManagedTypeApi, +{ + pub name: ManagedBuffer, + pub dna: u64, + pub level: u16, + pub ready_time: u64, + pub win_count: usize, + pub loss_count: usize, +} + diff --git a/framework/derive/src/type_abi_derive.rs b/framework/derive/src/type_abi_derive.rs index aad347ba31..cd93bdf33a 100644 --- a/framework/derive/src/type_abi_derive.rs +++ b/framework/derive/src/type_abi_derive.rs @@ -191,5 +191,5 @@ fn extract_rust_type(ty_generics: &syn::TypeGenerics<'_>, mut output_name: Strin } output_name.push_str("<$API>"); - return output_name; + output_name } diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs index 93cdb7a8e6..de78b53162 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs @@ -25,9 +25,9 @@ impl MetaConfig { fn write_proxies_to_file(mut file: File, abi: ContractAbi) { write_header(&mut file); - write_types(&mut file, &abi.type_descriptions); write_struct_template(&mut file, &abi.name); write_impl_for_tx_proxy(&mut file, &abi.name); write_struct_tx_proxy_methods(&mut file, &abi.name); - write_content(&mut file, abi); + write_content(&mut file, abi.clone()); + write_types(&mut file, &abi.type_descriptions); } From 88eb1a4d09bb2155f1fad23bc60fff7ae83ae78b Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 01:33:09 +0200 Subject: [PATCH 08/25] proxy gen - multiple outputs --- .../generate_proxy/proxy_sc_functions_gen.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_sc_functions_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_sc_functions_gen.rs index d1909b25c6..8198bbe325 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_sc_functions_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_sc_functions_gen.rs @@ -210,6 +210,16 @@ fn parse_and_write_outputs(file: &mut File, outputs: Vec) { let adjusted = adjust_type_name(&outputs[0].type_names.rust); write!(file, "{adjusted}").unwrap(); }, - _ => panic!("multiple outputs not yet supported"), + _ => { + write!(file, "MultiValue{}<", outputs.len()).unwrap(); + for (i, output) in outputs.iter().enumerate() { + if i > 0 { + write!(file, ", ").unwrap(); + } + let adjusted = adjust_type_name(&output.type_names.rust); + write!(file, "{adjusted}").unwrap(); + } + write!(file, ">").unwrap(); + }, } } From 2488db86bd4bf36f1e9941a016704f7d65ffc552 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 01:57:59 +0200 Subject: [PATCH 09/25] proxy gen - type fixes --- framework/base/src/abi/type_abi_impl_basic.rs | 24 +++++++++++++++++-- .../base/src/abi/type_abi_impl_codec_multi.rs | 15 +++++++++++- framework/base/src/types/heap/boxed_bytes.rs | 4 ++++ framework/base/src/types/heap/h256.rs | 4 ++++ framework/base/src/types/heap/h256_address.rs | 4 ++++ .../types/managed/wrapped/token_identifier.rs | 4 ++++ 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/framework/base/src/abi/type_abi_impl_basic.rs b/framework/base/src/abi/type_abi_impl_basic.rs index f2e6586e2f..00452263cd 100644 --- a/framework/base/src/abi/type_abi_impl_basic.rs +++ b/framework/base/src/abi/type_abi_impl_basic.rs @@ -204,8 +204,7 @@ macro_rules! tuple_impls { $($name: TypeAbi,)+ { fn type_name() -> TypeName { - let mut repr = TypeName::from("tuple"); - repr.push_str("<"); + let mut repr = TypeName::from("tuple<"); $( if $n > 0 { repr.push(','); @@ -216,6 +215,18 @@ macro_rules! tuple_impls { repr } + fn type_name_rust() -> TypeName { + let mut repr = TypeName::from("("); + $( + if $n > 0 { + repr.push_str(", "); + } + repr.push_str($name::type_name_rust().as_str()); + )+ + repr.push(')'); + repr + } + fn provide_type_descriptions(accumulator: &mut TDC) { $( $name::provide_type_descriptions(accumulator); @@ -255,6 +266,15 @@ impl TypeAbi for [T; N] { repr } + fn type_name_rust() -> TypeName { + let mut repr = TypeName::from("["); + repr.push_str(T::type_name_rust().as_str()); + repr.push_str("; "); + repr.push_str(N.to_string().as_str()); + repr.push(']'); + repr + } + fn provide_type_descriptions(accumulator: &mut TDC) { T::provide_type_descriptions(accumulator); } diff --git a/framework/base/src/abi/type_abi_impl_codec_multi.rs b/framework/base/src/abi/type_abi_impl_codec_multi.rs index 9d34d8b5f9..9d3cce98db 100644 --- a/framework/base/src/abi/type_abi_impl_codec_multi.rs +++ b/framework/base/src/abi/type_abi_impl_codec_multi.rs @@ -12,7 +12,7 @@ impl TypeAbi for crate::codec::multi_types::MultiValueVec { } fn type_name_rust() -> TypeName { - format!("MultiValueVec<$API, {}>", T::type_name_rust()) + format!("MultiValueVec<{}>", T::type_name_rust()) } fn provide_type_descriptions(accumulator: &mut TDC) { @@ -76,6 +76,19 @@ macro_rules! multi_arg_impls { repr } + fn type_name_rust() -> TypeName { + let mut repr = TypeName::from(stringify!($mval_struct)); + repr.push('<'); + $( + if $n > 0 { + repr.push_str(", "); + } + repr.push_str($name::type_name_rust().as_str()); + )+ + repr.push('>'); + repr + } + fn provide_type_descriptions(accumulator: &mut TDC) { $( $name::provide_type_descriptions(accumulator); diff --git a/framework/base/src/types/heap/boxed_bytes.rs b/framework/base/src/types/heap/boxed_bytes.rs index 24c08d1199..1b7c2b35e7 100644 --- a/framework/base/src/types/heap/boxed_bytes.rs +++ b/framework/base/src/types/heap/boxed_bytes.rs @@ -244,6 +244,10 @@ impl TypeAbi for BoxedBytes { fn type_name() -> TypeName { "bytes".into() } + + fn type_name_rust() -> TypeName { + "BoxedBytes".into() + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/framework/base/src/types/heap/h256.rs b/framework/base/src/types/heap/h256.rs index 5dd0a2786b..a097b0d08d 100644 --- a/framework/base/src/types/heap/h256.rs +++ b/framework/base/src/types/heap/h256.rs @@ -228,6 +228,10 @@ impl TypeAbi for H256 { fn type_name() -> TypeName { "H256".into() } + + fn type_name_rust() -> TypeName { + "H256".into() + } } #[cfg(test)] diff --git a/framework/base/src/types/heap/h256_address.rs b/framework/base/src/types/heap/h256_address.rs index e4c9b055d2..5e4712df7a 100644 --- a/framework/base/src/types/heap/h256_address.rs +++ b/framework/base/src/types/heap/h256_address.rs @@ -206,6 +206,10 @@ impl TypeAbi for Address { fn type_name() -> TypeName { "Address".into() } + + fn type_name_rust() -> TypeName { + "Address".into() + } } #[cfg(test)] diff --git a/framework/base/src/types/managed/wrapped/token_identifier.rs b/framework/base/src/types/managed/wrapped/token_identifier.rs index 329b3f2b3d..2c8423b3a6 100644 --- a/framework/base/src/types/managed/wrapped/token_identifier.rs +++ b/framework/base/src/types/managed/wrapped/token_identifier.rs @@ -171,6 +171,10 @@ impl TypeAbi for TokenIdentifier { fn type_name() -> TypeName { "TokenIdentifier".into() } + + fn type_name_rust() -> TypeName { + "TokenIdentifier".into() + } } impl SCDisplay for TokenIdentifier { From f86de72ee50bb2072d10fb39b1404889b18fdffc Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 01:58:23 +0200 Subject: [PATCH 10/25] abi tester proxy - initial commit --- .../feature-tests/abi-tester/sc-config.toml | 1 + .../feature-tests/abi-tester/src/abi_proxy.rs | 908 ++++++++++++++++++ .../abi-tester/src/abi_tester.rs | 1 + 3 files changed, 910 insertions(+) create mode 100644 contracts/feature-tests/abi-tester/src/abi_proxy.rs diff --git a/contracts/feature-tests/abi-tester/sc-config.toml b/contracts/feature-tests/abi-tester/sc-config.toml index 5a61f68d47..20d63c86b8 100644 --- a/contracts/feature-tests/abi-tester/sc-config.toml +++ b/contracts/feature-tests/abi-tester/sc-config.toml @@ -1,6 +1,7 @@ # Abi-tester multi-contract config, used for testing. [settings] +proxy-paths = ["src/abi_proxy.rs"] main = "main" [contracts.main] diff --git a/contracts/feature-tests/abi-tester/src/abi_proxy.rs b/contracts/feature-tests/abi-tester/src/abi_proxy.rs new file mode 100644 index 0000000000..968e8fd345 --- /dev/null +++ b/contracts/feature-tests/abi-tester/src/abi_proxy.rs @@ -0,0 +1,908 @@ +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(clippy::all)] + +use multiversx_sc::imports::*; + +pub struct AbiTesterProxy; + +impl TxProxyTrait for AbiTesterProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = AbiTesterProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + AbiTesterProxyMethods { wrapped_tx: tx } + } +} + +pub struct AbiTesterProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +impl AbiTesterProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + /// Contract constructor. + pub fn init< + Arg0: CodecInto, + Arg1: CodecInto, + >( + self, + _constructor_arg_1: Arg0, + _constructor_arg_2: Arg1, + ) -> Tx< + Env, + From, + (), + (), + Gas, + DeployCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_deploy() + .argument(&_constructor_arg_1) + .argument(&_constructor_arg_2) + .original_result() + } + +} +impl AbiTesterProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + /// Example endpoint docs. + pub fn echo_abi_test_type< + Arg0: CodecInto, + >( + self, + att: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("echo_abi_test_type") + .argument(&att) + .original_result() + } + + pub fn echo_enum< + Arg0: CodecInto, + >( + self, + e: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("echo_enum") + .argument(&e) + .original_result() + } + + pub fn take_managed_type< + Arg0: CodecInto>, + >( + self, + _arg: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("take_managed_type") + .argument(&_arg) + .original_result() + } + + pub fn multi_result_3( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("multi_result_3") + .original_result() + } + + pub fn multi_result_4( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("multi_result_4") + .original_result() + } + + pub fn var_args< + Arg0: CodecInto, + Arg1: CodecInto>>, + >( + self, + _simple_arg: Arg0, + _var_args: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("var_args") + .argument(&_simple_arg) + .argument(&_var_args) + .original_result() + } + + pub fn multi_result_vec( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>>, + > { + self.wrapped_tx + .raw_call() + .function_name("multi_result_vec") + .original_result() + } + + pub fn optional_arg< + Arg0: CodecInto, + Arg1: CodecInto>, + >( + self, + _simple_arg: Arg0, + _opt_args: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("optional_arg") + .argument(&_simple_arg) + .argument(&_opt_args) + .original_result() + } + + pub fn optional_result( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("optional_result") + .original_result() + } + + pub fn address_vs_h256< + Arg0: CodecInto
, + Arg1: CodecInto, + >( + self, + address: Arg0, + h256: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("address_vs_h256") + .argument(&address) + .argument(&h256) + .original_result() + } + + pub fn managed_address_vs_byte_array< + Arg0: CodecInto>, + Arg1: CodecInto>, + >( + self, + address: Arg0, + byte_array: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, ManagedByteArray>>, + > { + self.wrapped_tx + .raw_call() + .function_name("managed_address_vs_byte_array") + .argument(&address) + .argument(&byte_array) + .original_result() + } + + pub fn esdt_local_role( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("esdt_local_role") + .original_result() + } + + pub fn esdt_token_payment( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("esdt_token_payment") + .original_result() + } + + pub fn esdt_token_data( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("esdt_token_data") + .original_result() + } + + pub fn sample_storage_mapper( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("sample_storage_mapper") + .original_result() + } + + pub fn item_for_vec( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_vec") + .original_result() + } + + pub fn item_for_array_vec( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_array_vec") + .original_result() + } + + pub fn item_for_managed_vec( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_managed_vec") + .original_result() + } + + pub fn item_for_array< + Arg0: CodecInto<[OnlyShowsUpAsNestedInArray; 5]>, + >( + self, + _array: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_array") + .argument(&_array) + .original_result() + } + + pub fn item_for_box( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_box") + .original_result() + } + + pub fn item_for_boxed_slice( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<&[OnlyShowsUpAsNestedInBoxedSlice]>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_boxed_slice") + .original_result() + } + + pub fn item_for_ref< + Arg0: CodecInto, + >( + self, + _ref: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_ref") + .argument(&_ref) + .original_result() + } + + pub fn item_for_slice< + Arg0: CodecInto<&[OnlyShowsUpAsNestedInSlice]>, + >( + self, + _ref: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_slice") + .argument(&_ref) + .original_result() + } + + pub fn item_for_option( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("item_for_option") + .original_result() + } + + pub fn payable_egld( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("payable_egld") + .original_result() + } + + pub fn payable_some_token( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("payable_some_token") + .original_result() + } + + pub fn payable_any_token( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("payable_any_token") + .original_result() + } + + pub fn external_view( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("external_view") + .original_result() + } + + pub fn label_a( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("label_a") + .original_result() + } + + pub fn label_b( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("label_b") + .original_result() + } + +} +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpInConstructor +{ + pub something: (), +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct AbiTestType +{ + pub nested: OnlyShowsUpAsNested01, + pub next: Option, + pub tuple_madness: (OnlyShowsUpAsNested02, Option), +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested01 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested02 +{ + pub something: [u8; 0], +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub enum AbiEnum { + Nothing, + Something, + SomethingMore, + SomeStruct, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested08 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested09 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct AbiManagedType +where + Api: ManagedTypeApi, +{ + pub big_uint: BigUint, + pub integer: i32, + pub managed_buffer: ManagedBuffer, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested03 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested04 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested05 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested06 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested07 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub enum EsdtLocalRole { + None, + Mint, + Burn, + NftCreate, + NftAddQuantity, + NftBurn, + NftAddUri, + NftUpdateAttributes, + Transfer, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct EsdtTokenPayment +where + Api: ManagedTypeApi, +{ + pub token_identifier: multiversx_sc::types::managed::wrapped::token_identifier::TokenIdentifier, + pub token_nonce: u64, + pub amount: BigUint, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct EsdtTokenData +where + Api: ManagedTypeApi, +{ + pub token_type: EsdtTokenType, + pub amount: BigUint, + pub frozen: bool, + pub hash: ManagedBuffer, + pub name: ManagedBuffer, + pub attributes: ManagedBuffer, + pub creator: ManagedAddress, + pub royalties: BigUint, + pub uris: ManagedVec>, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub enum EsdtTokenType { + Fungible, + NonFungible, + SemiFungible, + Meta, + Invalid, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInSingleValueMapper +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInVec +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInArrayVec +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct AbiManagedVecItem +{ + pub value1: u32, + pub value2: u32, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInArray +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInBox +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInBoxedSlice +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInRef +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInSlice +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNestedInOption +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpInEsdtAttr +{ + pub field: OnlyShowsUpAsNested10, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub struct OnlyShowsUpAsNested10 +{ +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +pub enum ExplicitDiscriminant { + Zero, + Thirty, + Twelve, + Fifty, + FiftyOne, +} + +use multiversx_sc::derive_imports::*; + +#[derive(TypeAbi)] +#[derive(u8)] +pub enum ExplicitDiscriminantMixed { + Zero, + Unit, + Tuple, + Five, + Struct, +} + diff --git a/contracts/feature-tests/abi-tester/src/abi_tester.rs b/contracts/feature-tests/abi-tester/src/abi_tester.rs index 15fe5f3c4a..48976f5980 100644 --- a/contracts/feature-tests/abi-tester/src/abi_tester.rs +++ b/contracts/feature-tests/abi-tester/src/abi_tester.rs @@ -3,6 +3,7 @@ multiversx_sc::imports!(); mod abi_enum; +// pub mod abi_proxy; mod abi_test_type; mod only_nested; From b682d58d076f9821d3fbc5575893746f9df856a3 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 02:22:44 +0200 Subject: [PATCH 11/25] proxy gen - clean up imports --- framework/base/src/lib.rs | 5 +++++ .../src/types/managed/wrapped/token_identifier.rs | 2 +- .../contract/generate_proxy/proxy_template_gen.rs | 14 +++----------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/framework/base/src/lib.rs b/framework/base/src/lib.rs index 7f2a8b1c2b..7910499169 100644 --- a/framework/base/src/lib.rs +++ b/framework/base/src/lib.rs @@ -76,3 +76,8 @@ pub mod derive_imports { derive::{ManagedVecItem, TypeAbi}, }; } + +/// Conveniently groups all imports required for generated proxies. +pub mod proxy_imports { + pub use crate::{derive_imports::*, imports::*}; +} diff --git a/framework/base/src/types/managed/wrapped/token_identifier.rs b/framework/base/src/types/managed/wrapped/token_identifier.rs index 2c8423b3a6..af113dbc4e 100644 --- a/framework/base/src/types/managed/wrapped/token_identifier.rs +++ b/framework/base/src/types/managed/wrapped/token_identifier.rs @@ -173,7 +173,7 @@ impl TypeAbi for TokenIdentifier { } fn type_name_rust() -> TypeName { - "TokenIdentifier".into() + "TokenIdentifier<$API>".into() } } diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 5ae0202317..054f977b84 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -11,15 +11,13 @@ const PREFIX_AUTO_GENERATED: &str = "/////////////////////////////////////////// //////////////////////////////////////////////////// "; -const IMPORTS: &str = "#![allow(clippy::all)] +const PRELUDE: &str = "#![allow(clippy::all)] -use multiversx_sc::imports::*;"; - -const DERIVE_IMPORTS: &str = "use multiversx_sc::derive_imports::*;"; +use multiversx_sc::proxy_imports::*;"; pub(crate) fn write_header(file: &mut File) { writeln!(file, "{PREFIX_AUTO_GENERATED}").unwrap(); - writeln!(file, r#"{IMPORTS}"#).unwrap(); + writeln!(file, r#"{PRELUDE}"#).unwrap(); write_newline(file); } @@ -85,7 +83,6 @@ where } fn write_enum(file: &mut File, type_description: &TypeDescription) { - write_derive_imports(file); write_macro_attributes(file, &type_description.macro_attributes); writeln!(file, r#"pub enum {} {{"#, type_description.names.abi).unwrap(); @@ -100,7 +97,6 @@ fn write_enum(file: &mut File, type_description: &TypeDescription) { fn write_struct(file: &mut File, type_description: &TypeDescription) { let struct_name = type_description.names.rust.replace("$API", "Api"); - write_derive_imports(file); write_macro_attributes(file, &type_description.macro_attributes); writeln!(file, r#"pub struct {}"#, struct_name).unwrap(); @@ -140,7 +136,3 @@ fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { } } -fn write_derive_imports(file: &mut File) { - writeln!(file, "{DERIVE_IMPORTS}").unwrap(); - write_newline(file); -} From 8ee46b9903d56ccf714d958c2d6c4dcdba99b083 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 03:20:06 +0200 Subject: [PATCH 12/25] proxy gen - derive fix --- .../feature-tests/abi-tester/src/abi_proxy.rs | 141 +++++------------- .../abi-tester/src/abi_test_type.rs | 9 +- .../abi-tester/src/only_nested.rs | 60 +++++--- framework/base/src/abi/type_abi_impl_basic.rs | 10 +- .../derive/src/parse/attributes/doc_attr.rs | 8 +- .../generate_proxy/proxy_template_gen.rs | 16 +- 6 files changed, 101 insertions(+), 143 deletions(-) diff --git a/contracts/feature-tests/abi-tester/src/abi_proxy.rs b/contracts/feature-tests/abi-tester/src/abi_proxy.rs index 968e8fd345..cbc0520f5a 100644 --- a/contracts/feature-tests/abi-tester/src/abi_proxy.rs +++ b/contracts/feature-tests/abi-tester/src/abi_proxy.rs @@ -4,7 +4,7 @@ #![allow(clippy::all)] -use multiversx_sc::imports::*; +use multiversx_sc::proxy_imports::*; pub struct AbiTesterProxy; @@ -449,7 +449,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker, + OriginalResultMarker>, > { self.wrapped_tx .raw_call() @@ -466,7 +466,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker<&[OnlyShowsUpAsNestedInBoxedSlice]>, + OriginalResultMarker>, > { self.wrapped_tx .raw_call() @@ -496,7 +496,7 @@ where } pub fn item_for_slice< - Arg0: CodecInto<&[OnlyShowsUpAsNestedInSlice]>, + Arg0: CodecInto>, >( self, _ref: Arg0, @@ -636,42 +636,32 @@ where } } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpInConstructor { pub something: (), } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct AbiTestType { pub nested: OnlyShowsUpAsNested01, - pub next: Option, - pub tuple_madness: (OnlyShowsUpAsNested02, Option), + pub next: Option>, + pub tuple_madness: (OnlyShowsUpAsNested02, Option>), } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested01 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested02 { pub something: [u8; 0], } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub enum AbiEnum { Nothing, Something, @@ -679,23 +669,17 @@ pub enum AbiEnum { SomeStruct, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested08 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested09 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct AbiManagedType where Api: ManagedTypeApi, @@ -705,44 +689,32 @@ where pub managed_buffer: ManagedBuffer, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested03 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested04 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested05 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested06 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested07 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub enum EsdtLocalRole { None, Mint, @@ -755,26 +727,22 @@ pub enum EsdtLocalRole { Transfer, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub struct EsdtTokenPayment where Api: ManagedTypeApi, { - pub token_identifier: multiversx_sc::types::managed::wrapped::token_identifier::TokenIdentifier, + pub token_identifier: TokenIdentifier, pub token_nonce: u64, pub amount: BigUint, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub struct EsdtTokenData where Api: ManagedTypeApi, { - pub token_type: EsdtTokenType, + pub token_type: self::EsdtTokenType, pub amount: BigUint, pub frozen: bool, pub hash: ManagedBuffer, @@ -785,9 +753,7 @@ where pub uris: ManagedVec>, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub enum EsdtTokenType { Fungible, NonFungible, @@ -796,96 +762,70 @@ pub enum EsdtTokenType { Invalid, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInSingleValueMapper { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInVec { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInArrayVec { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, ManagedVecItem)] pub struct AbiManagedVecItem { pub value1: u32, pub value2: u32, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInArray { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInBox { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInBoxedSlice { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInRef { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInSlice { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInOption { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub struct OnlyShowsUpInEsdtAttr { pub field: OnlyShowsUpAsNested10, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested10 { } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] +#[derive(TopEncode, TopDecode)] pub enum ExplicitDiscriminant { Zero, Thirty, @@ -894,10 +834,7 @@ pub enum ExplicitDiscriminant { FiftyOne, } -use multiversx_sc::derive_imports::*; - -#[derive(TypeAbi)] -#[derive(u8)] +#[derive(TopEncode, TopDecode)] pub enum ExplicitDiscriminantMixed { Zero, Unit, diff --git a/contracts/feature-tests/abi-tester/src/abi_test_type.rs b/contracts/feature-tests/abi-tester/src/abi_test_type.rs index 2cc1fc4db4..b952146aa3 100644 --- a/contracts/feature-tests/abi-tester/src/abi_test_type.rs +++ b/contracts/feature-tests/abi-tester/src/abi_test_type.rs @@ -6,7 +6,8 @@ use multiversx_sc::{ multiversx_sc::derive_imports!(); /// Its only purpose is to test that the ABI generator works fine. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct AbiTestType { /// This type should only appear here. pub nested: OnlyShowsUpAsNested01, @@ -20,7 +21,8 @@ pub struct AbiTestType { } /// Its only purpose is to test that the ABI generator works fine. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct AbiManagedType { pub big_uint: BigUint, pub integer: i32, @@ -28,7 +30,8 @@ pub struct AbiManagedType { } /// Its only purpose is to test that the ABI generator works fine. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi, ManagedVecItem)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, ManagedVecItem)] pub struct AbiManagedVecItem { pub value1: u32, pub value2: u32, diff --git a/contracts/feature-tests/abi-tester/src/only_nested.rs b/contracts/feature-tests/abi-tester/src/only_nested.rs index d1e19441d0..fe17c7e55e 100644 --- a/contracts/feature-tests/abi-tester/src/only_nested.rs +++ b/contracts/feature-tests/abi-tester/src/only_nested.rs @@ -1,85 +1,105 @@ multiversx_sc::derive_imports!(); /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpInConstructor { pub something: (), } /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested01; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested02 { pub something: [u8; 0], } /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested03(); /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested04; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested05; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested06; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested07; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested08; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested09; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested10; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInSingleValueMapper; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInVec; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInArrayVec; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInArray; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInBox; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInBoxedSlice; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInRef; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInSlice; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(TypeAbi)] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInOption; diff --git a/framework/base/src/abi/type_abi_impl_basic.rs b/framework/base/src/abi/type_abi_impl_basic.rs index 00452263cd..c14447b2ba 100644 --- a/framework/base/src/abi/type_abi_impl_basic.rs +++ b/framework/base/src/abi/type_abi_impl_basic.rs @@ -35,7 +35,7 @@ impl TypeAbi for Box { } fn type_name_rust() -> TypeName { - T::type_name_rust() + format!("Box<{}>", T::type_name_rust()) } fn provide_type_descriptions(accumulator: &mut TDC) { @@ -56,7 +56,8 @@ impl TypeAbi for &[T] { } fn type_name_rust() -> TypeName { - format!("&[{}]", T::type_name_rust()) + // we need to convert to an owned type + format!("Box<[{}]>", T::type_name_rust()) } fn provide_type_descriptions(accumulator: &mut TDC) { @@ -98,7 +99,7 @@ impl TypeAbi for Box<[T]> { } fn type_name_rust() -> TypeName { - <&[T]>::type_name_rust() + format!("Box<[{}]>", T::type_name_rust()) } fn provide_type_descriptions(accumulator: &mut TDC) { @@ -118,7 +119,8 @@ impl TypeAbi for &str { } fn type_name_rust() -> TypeName { - "&str".into() + // we need to convert to an owned type + "Box".into() } } diff --git a/framework/derive/src/parse/attributes/doc_attr.rs b/framework/derive/src/parse/attributes/doc_attr.rs index d9d3b22658..5c5ed4d41b 100644 --- a/framework/derive/src/parse/attributes/doc_attr.rs +++ b/framework/derive/src/parse/attributes/doc_attr.rs @@ -50,8 +50,12 @@ pub fn extract_macro_attributes(attrs: &[syn::Attribute]) -> Vec { for a in attrs { if let syn::Meta::List(list) = &a.meta { - for token in list.tokens.clone().into_iter() { - macro_attributes.push(token.to_string()); + if list.path.is_ident("derive") { + for token in list.tokens.clone().into_iter() { + if let proc_macro2::TokenTree::Ident(ident) = token { + macro_attributes.push(ident.to_string()); + } + } } } } diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 054f977b84..699ecf433b 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -96,7 +96,6 @@ fn write_enum(file: &mut File, type_description: &TypeDescription) { fn write_struct(file: &mut File, type_description: &TypeDescription) { let struct_name = type_description.names.rust.replace("$API", "Api"); - write_macro_attributes(file, &type_description.macro_attributes); writeln!(file, r#"pub struct {}"#, struct_name).unwrap(); @@ -123,16 +122,9 @@ fn write_struct(file: &mut File, type_description: &TypeDescription) { } fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { - writeln!(file, "#[derive(TypeAbi)]").unwrap(); - if !macro_attributes.is_empty() { - write!(file, "#[derive(").unwrap(); - } - - let attributes = macro_attributes.join("").replace(',', ", "); - write!(file, "{attributes}").unwrap(); - - if !macro_attributes.is_empty() { - writeln!(file, ")]").unwrap(); + if macro_attributes.is_empty() { + writeln!(file, "#[derive(TopEncode, TopDecode)]").unwrap(); + } else { + writeln!(file, "#[derive({})]", macro_attributes.join(", ")).unwrap(); } } - From d7a541f0dc6f2189e3c8fad73d2dc70c0c7b9140 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 09:04:44 +0200 Subject: [PATCH 13/25] tx proxy gen - fixed tests --- .../abi_tester_expected_main.abi.json | 28 +++++++++---------- .../abi_tester_expected_view.abi.json | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json b/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json index b94afe2670..999feb222f 100644 --- a/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json +++ b/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json @@ -532,7 +532,7 @@ "fields": [ { "name": "big_uint", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "integer", @@ -540,7 +540,7 @@ }, { "name": "managed_buffer", - "type": "bytes" + "type": "ManagedBuffer<$API>" } ] }, @@ -578,7 +578,7 @@ "Tests that recursive types will not send the ABI generator into an infinite loop." ], "name": "next", - "type": "Option" + "type": "Option>" }, { "docs": [ @@ -586,7 +586,7 @@ "Also, just like above, recursive types need to work even when nested into a tuple." ], "name": "tuple_madness", - "type": "tuple>" + "type": "(OnlyShowsUpAsNested02, Option>)" } ] }, @@ -640,7 +640,7 @@ }, { "name": "amount", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "frozen", @@ -648,27 +648,27 @@ }, { "name": "hash", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "name", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "attributes", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "creator", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "royalties", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "uris", - "type": "List" + "type": "ManagedVec<$API, ManagedBuffer<$API>>" } ] }, @@ -677,7 +677,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier" + "type": "TokenIdentifier<$API>" }, { "name": "token_nonce", @@ -685,7 +685,7 @@ }, { "name": "amount", - "type": "BigUint" + "type": "BigUint<$API>" } ] }, @@ -800,7 +800,7 @@ "fields": [ { "name": "something", - "type": "array0" + "type": "[u8; 0]" } ] }, diff --git a/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json b/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json index f8a30cb9a5..4a31f9ea3d 100644 --- a/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json +++ b/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json @@ -193,7 +193,7 @@ "fields": [ { "name": "big_uint", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "integer", @@ -201,7 +201,7 @@ }, { "name": "managed_buffer", - "type": "bytes" + "type": "ManagedBuffer<$API>" } ] }, @@ -239,7 +239,7 @@ "Tests that recursive types will not send the ABI generator into an infinite loop." ], "name": "next", - "type": "Option" + "type": "Option>" }, { "docs": [ @@ -247,7 +247,7 @@ "Also, just like above, recursive types need to work even when nested into a tuple." ], "name": "tuple_madness", - "type": "tuple>" + "type": "(OnlyShowsUpAsNested02, Option>)" } ] }, @@ -301,7 +301,7 @@ }, { "name": "amount", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "frozen", @@ -309,27 +309,27 @@ }, { "name": "hash", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "name", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "attributes", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "creator", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "royalties", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "uris", - "type": "List" + "type": "ManagedVec<$API, ManagedBuffer<$API>>" } ] }, @@ -338,7 +338,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier" + "type": "TokenIdentifier<$API>" }, { "name": "token_nonce", @@ -346,7 +346,7 @@ }, { "name": "amount", - "type": "BigUint" + "type": "BigUint<$API>" } ] }, @@ -461,7 +461,7 @@ "fields": [ { "name": "something", - "type": "array0" + "type": "[u8; 0]" } ] }, From 8f9fffeedde5ece6b0d4c4ebbfacba60c3f10d2c Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 10:02:49 +0200 Subject: [PATCH 14/25] tx proxy gen - fixed tests --- .../use_module_expected_main.abi.json | 34 +++++++++---------- .../use_module_expected_view.abi.json | 34 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/contracts/feature-tests/use-module/use_module_expected_main.abi.json b/contracts/feature-tests/use-module/use_module_expected_main.abi.json index 2e4694e6fb..8ce1878d1a 100644 --- a/contracts/feature-tests/use-module/use_module_expected_main.abi.json +++ b/contracts/feature-tests/use-module/use_module_expected_main.abi.json @@ -1023,7 +1023,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier" + "type": "TokenIdentifier<$API>" }, { "name": "token_nonce", @@ -1031,7 +1031,7 @@ }, { "name": "amount", - "type": "BigUint" + "type": "BigUint<$API>" } ] }, @@ -1065,11 +1065,11 @@ "fields": [ { "name": "depositor_addr", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "tokens", - "type": "EsdtTokenPayment" + "type": "EsdtTokenPayment<$API>" } ] }, @@ -1082,15 +1082,15 @@ }, { "name": "dest_address", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "function_name", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "arguments", - "type": "List" + "type": "ManagedVec<$API, ManagedBuffer<$API>>" } ] }, @@ -1099,19 +1099,19 @@ "fields": [ { "name": "proposer", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "actions", - "type": "List" + "type": "ArrayVec, 4usize>" }, { "name": "description", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "fees", - "type": "ProposalFees" + "type": "ProposalFees<$API>" } ] }, @@ -1170,11 +1170,11 @@ "fields": [ { "name": "total_amount", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "entries", - "type": "List" + "type": "ManagedVec<$API, FeeEntry<$API>>" } ] }, @@ -1183,19 +1183,19 @@ "fields": [ { "name": "up_votes", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "down_votes", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "down_veto_votes", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "abstain_votes", - "type": "BigUint" + "type": "BigUint<$API>" } ] }, diff --git a/contracts/feature-tests/use-module/use_module_expected_view.abi.json b/contracts/feature-tests/use-module/use_module_expected_view.abi.json index c84a7deac4..9fd87c32f8 100644 --- a/contracts/feature-tests/use-module/use_module_expected_view.abi.json +++ b/contracts/feature-tests/use-module/use_module_expected_view.abi.json @@ -267,7 +267,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier" + "type": "TokenIdentifier<$API>" }, { "name": "token_nonce", @@ -275,7 +275,7 @@ }, { "name": "amount", - "type": "BigUint" + "type": "BigUint<$API>" } ] }, @@ -309,11 +309,11 @@ "fields": [ { "name": "depositor_addr", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "tokens", - "type": "EsdtTokenPayment" + "type": "EsdtTokenPayment<$API>" } ] }, @@ -326,15 +326,15 @@ }, { "name": "dest_address", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "function_name", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "arguments", - "type": "List" + "type": "ManagedVec<$API, ManagedBuffer<$API>>" } ] }, @@ -343,19 +343,19 @@ "fields": [ { "name": "proposer", - "type": "Address" + "type": "ManagedAddress<$API>" }, { "name": "actions", - "type": "List" + "type": "ArrayVec, 4usize>" }, { "name": "description", - "type": "bytes" + "type": "ManagedBuffer<$API>" }, { "name": "fees", - "type": "ProposalFees" + "type": "ProposalFees<$API>" } ] }, @@ -414,11 +414,11 @@ "fields": [ { "name": "total_amount", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "entries", - "type": "List" + "type": "ManagedVec<$API, FeeEntry<$API>>" } ] }, @@ -427,19 +427,19 @@ "fields": [ { "name": "up_votes", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "down_votes", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "down_veto_votes", - "type": "BigUint" + "type": "BigUint<$API>" }, { "name": "abstain_votes", - "type": "BigUint" + "type": "BigUint<$API>" } ] }, From e06e1d13f661649736a7d991a306cd6baa411861 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 11:04:34 +0200 Subject: [PATCH 15/25] type_abi proc attribute instead of derive(TypeAbi) --- .../src/crowdfunding_esdt.rs | 2 +- .../crowdfunding-esdt/src/temp_proxy.rs | 2 +- contracts/examples/crypto-zombies/src/lib.rs | 2 +- .../examples/crypto-zombies/src/temp_proxy.rs | 2 +- .../examples/crypto-zombies/src/zombie.rs | 2 +- .../examples/digital-cash/src/deposit_info.rs | 2 +- .../feature-tests/abi-tester/src/abi_proxy.rs | 10 ++-- .../abi-tester/src/abi_test_type.rs | 8 +-- .../abi-tester/src/abi_tester.rs | 2 +- .../abi-tester/src/only_nested.rs | 40 +++++++------- .../src/types/codec_err_test_type.rs | 4 +- framework/base/src/abi/type_abi.rs | 2 +- framework/base/src/lib.rs | 2 +- .../base/src/types/flags/esdt_local_role.rs | 7 +-- .../base/src/types/flags/esdt_token_type.rs | 55 ++++--------------- .../types/managed/wrapped/esdt_token_data.rs | 7 +-- .../managed/wrapped/esdt_token_payment.rs | 5 +- framework/derive/src/lib.rs | 12 +++- framework/derive/src/type_abi_derive.rs | 18 ++++-- framework/meta/src/abi_json/type_abi_json.rs | 2 +- 20 files changed, 83 insertions(+), 103 deletions(-) diff --git a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs index e82411c0e1..f38da41061 100644 --- a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs +++ b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs @@ -3,7 +3,7 @@ use multiversx_sc::{derive_imports::*, imports::*}; pub mod temp_proxy; -#[derive(TypeAbi)] +#[type_abi] #[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] pub enum Status { FundingPeriod, diff --git a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs index 98ab96c104..b82e54eb8c 100644 --- a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs +++ b/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs @@ -8,7 +8,7 @@ use multiversx_sc::imports::*; use multiversx_sc::derive_imports::*; -#[derive(TypeAbi)] +#[type_abi] #[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] pub enum Status { FundingPeriod, diff --git a/contracts/examples/crypto-zombies/src/lib.rs b/contracts/examples/crypto-zombies/src/lib.rs index ed6b9befba..bed761384f 100644 --- a/contracts/examples/crypto-zombies/src/lib.rs +++ b/contracts/examples/crypto-zombies/src/lib.rs @@ -4,12 +4,12 @@ use multiversx_sc::imports::*; mod crypto_kitties_proxy; mod storage; +pub mod temp_proxy; mod zombie; mod zombie_attack; mod zombie_factory; mod zombie_feeding; mod zombie_helper; -pub mod temp_proxy; #[multiversx_sc::contract] pub trait CryptoZombies: diff --git a/contracts/examples/crypto-zombies/src/temp_proxy.rs b/contracts/examples/crypto-zombies/src/temp_proxy.rs index 32f130dfdc..09ae9979d1 100644 --- a/contracts/examples/crypto-zombies/src/temp_proxy.rs +++ b/contracts/examples/crypto-zombies/src/temp_proxy.rs @@ -412,7 +412,7 @@ where } use multiversx_sc::derive_imports::*; -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct Zombie where diff --git a/contracts/examples/crypto-zombies/src/zombie.rs b/contracts/examples/crypto-zombies/src/zombie.rs index 858d1b791c..bfe3fd22ad 100644 --- a/contracts/examples/crypto-zombies/src/zombie.rs +++ b/contracts/examples/crypto-zombies/src/zombie.rs @@ -1,6 +1,6 @@ use multiversx_sc::{derive_imports::*, imports::*}; -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct Zombie { pub name: ManagedBuffer, diff --git a/contracts/examples/digital-cash/src/deposit_info.rs b/contracts/examples/digital-cash/src/deposit_info.rs index 0164db2090..ce2c279409 100644 --- a/contracts/examples/digital-cash/src/deposit_info.rs +++ b/contracts/examples/digital-cash/src/deposit_info.rs @@ -1,6 +1,6 @@ use multiversx_sc::{derive_imports::*, imports::*}; -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct DepositInfo { pub depositor_address: ManagedAddress, diff --git a/contracts/feature-tests/abi-tester/src/abi_proxy.rs b/contracts/feature-tests/abi-tester/src/abi_proxy.rs index cbc0520f5a..c7c7f8650a 100644 --- a/contracts/feature-tests/abi-tester/src/abi_proxy.rs +++ b/contracts/feature-tests/abi-tester/src/abi_proxy.rs @@ -714,7 +714,7 @@ pub struct OnlyShowsUpAsNested07 { } -#[derive(TopEncode, TopDecode)] +#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, Copy)] pub enum EsdtLocalRole { None, Mint, @@ -727,7 +727,7 @@ pub enum EsdtLocalRole { Transfer, } -#[derive(TopEncode, TopDecode)] +#[derive(TopEncode, NestedEncode, Clone, PartialEq, Eq, Debug)] pub struct EsdtTokenPayment where Api: ManagedTypeApi, @@ -737,12 +737,12 @@ where pub amount: BigUint, } -#[derive(TopEncode, TopDecode)] +#[derive(Clone, TopDecode, TopEncode, NestedDecode, NestedEncode, Debug, ManagedVecItem)] pub struct EsdtTokenData where Api: ManagedTypeApi, { - pub token_type: self::EsdtTokenType, + pub token_type: EsdtTokenType, pub amount: BigUint, pub frozen: bool, pub hash: ManagedBuffer, @@ -753,7 +753,7 @@ where pub uris: ManagedVec>, } -#[derive(TopEncode, TopDecode)] +#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, ManagedVecItem)] pub enum EsdtTokenType { Fungible, NonFungible, diff --git a/contracts/feature-tests/abi-tester/src/abi_test_type.rs b/contracts/feature-tests/abi-tester/src/abi_test_type.rs index b952146aa3..ff4f76b744 100644 --- a/contracts/feature-tests/abi-tester/src/abi_test_type.rs +++ b/contracts/feature-tests/abi-tester/src/abi_test_type.rs @@ -6,7 +6,7 @@ use multiversx_sc::{ multiversx_sc::derive_imports!(); /// Its only purpose is to test that the ABI generator works fine. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct AbiTestType { /// This type should only appear here. @@ -21,7 +21,7 @@ pub struct AbiTestType { } /// Its only purpose is to test that the ABI generator works fine. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct AbiManagedType { pub big_uint: BigUint, @@ -30,14 +30,14 @@ pub struct AbiManagedType { } /// Its only purpose is to test that the ABI generator works fine. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, ManagedVecItem)] pub struct AbiManagedVecItem { pub value1: u32, pub value2: u32, } -#[derive(TypeAbi)] +#[type_abi] pub struct OnlyShowsUpInEsdtAttr { pub field: OnlyShowsUpAsNested10, } diff --git a/contracts/feature-tests/abi-tester/src/abi_tester.rs b/contracts/feature-tests/abi-tester/src/abi_tester.rs index 48976f5980..1d7226c0f9 100644 --- a/contracts/feature-tests/abi-tester/src/abi_tester.rs +++ b/contracts/feature-tests/abi-tester/src/abi_tester.rs @@ -3,7 +3,7 @@ multiversx_sc::imports!(); mod abi_enum; -// pub mod abi_proxy; +pub mod abi_proxy; mod abi_test_type; mod only_nested; diff --git a/contracts/feature-tests/abi-tester/src/only_nested.rs b/contracts/feature-tests/abi-tester/src/only_nested.rs index fe17c7e55e..5c960cc95a 100644 --- a/contracts/feature-tests/abi-tester/src/only_nested.rs +++ b/contracts/feature-tests/abi-tester/src/only_nested.rs @@ -1,105 +1,105 @@ multiversx_sc::derive_imports!(); /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpInConstructor { pub something: (), } /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested01; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested02 { pub something: [u8; 0], } /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested03(); /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested04; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested05; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested06; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested07; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested08; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested09; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNested10; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInSingleValueMapper; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInVec; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInArrayVec; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInArray; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInBox; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInBoxedSlice; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInRef; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInSlice; /// Tests that the ABI generator also fetches types that only appear as fields. -#[derive(TypeAbi)] +#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct OnlyShowsUpAsNestedInOption; diff --git a/contracts/feature-tests/basic-features/src/types/codec_err_test_type.rs b/contracts/feature-tests/basic-features/src/types/codec_err_test_type.rs index 16350f3a5a..41c1524c41 100644 --- a/contracts/feature-tests/basic-features/src/types/codec_err_test_type.rs +++ b/contracts/feature-tests/basic-features/src/types/codec_err_test_type.rs @@ -4,11 +4,11 @@ use multiversx_sc::{ NestedDecodeInput, NestedEncode, NestedEncodeOutput, TopDecode, TopDecodeInput, TopEncode, TopEncodeOutput, }, - derive::TypeAbi, + derive::type_abi, }; /// Helper type to explore encode/decode errors. -#[derive(TypeAbi)] +#[type_abi] pub struct CodecErrorTestType; impl TopEncode for CodecErrorTestType { diff --git a/framework/base/src/abi/type_abi.rs b/framework/base/src/abi/type_abi.rs index 215cb36464..94213e7705 100644 --- a/framework/base/src/abi/type_abi.rs +++ b/framework/base/src/abi/type_abi.rs @@ -29,7 +29,7 @@ pub trait TypeAbi { docs: Vec::new(), names: Self::type_names(), contents: TypeContents::NotSpecified, - macro_attributes: Vec::new() + macro_attributes: Vec::new(), }, ); } diff --git a/framework/base/src/lib.rs b/framework/base/src/lib.rs index 7910499169..aa1d477897 100644 --- a/framework/base/src/lib.rs +++ b/framework/base/src/lib.rs @@ -73,7 +73,7 @@ pub mod derive_imports { NestedDecode, NestedEncode, TopDecode, TopDecodeOrDefault, TopEncode, TopEncodeOrDefault, }, - derive::{ManagedVecItem, TypeAbi}, + derive::{type_abi, ManagedVecItem, TypeAbi}, }; } diff --git a/framework/base/src/types/flags/esdt_local_role.rs b/framework/base/src/types/flags/esdt_local_role.rs index f0f241d931..9bc5edfc68 100644 --- a/framework/base/src/types/flags/esdt_local_role.rs +++ b/framework/base/src/types/flags/esdt_local_role.rs @@ -5,7 +5,7 @@ use crate::{ use super::EsdtLocalRoleFlags; use crate as multiversx_sc; -use crate::{derive::TypeAbi, types::ManagedVecItem}; +use crate::{derive::type_abi, types::ManagedVecItem}; static ESDT_ROLE_NONE: &[u8] = &[]; static ESDT_ROLE_LOCAL_MINT: &[u8] = b"ESDTRoleLocalMint"; @@ -17,9 +17,8 @@ static ESDT_ROLE_NFT_ADD_URI: &[u8] = b"ESDTRoleNFTAddURI"; static ESDT_ROLE_NFT_UPDATE_ATTRIBUTES: &[u8] = b"ESDTRoleNFTUpdateAttributes"; static ESDT_ROLE_TRANSFER: &[u8] = b"ESDTTransferRole"; -#[derive( - TopDecode, TopEncode, NestedDecode, NestedEncode, TypeAbi, Clone, PartialEq, Eq, Debug, Copy, -)] +#[type_abi] +#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, Copy)] pub enum EsdtLocalRole { None, Mint, diff --git a/framework/base/src/types/flags/esdt_token_type.rs b/framework/base/src/types/flags/esdt_token_type.rs index 2348254455..1993fd1cfa 100644 --- a/framework/base/src/types/flags/esdt_token_type.rs +++ b/framework/base/src/types/flags/esdt_token_type.rs @@ -1,6 +1,9 @@ use multiversx_sc_derive::ManagedVecItem; -use crate::codec::*; +use crate::{ + codec, + codec::derive::{NestedDecode, NestedEncode, TopDecode, TopEncode}, +}; const ESDT_TYPE_FUNGIBLE: &[u8] = b"FungibleESDT"; const ESDT_TYPE_NON_FUNGIBLE: &[u8] = b"NonFungibleESDT"; @@ -9,10 +12,14 @@ const ESDT_TYPE_META: &[u8] = b"MetaESDT"; const ESDT_TYPE_INVALID: &[u8] = &[]; use crate as multiversx_sc; // needed by the TypeAbi generated code -use crate::derive::TypeAbi; +use crate::derive::type_abi; // Note: In the current implementation, SemiFungible is never returned -#[derive(Clone, PartialEq, Eq, Debug, TypeAbi, ManagedVecItem)] + +#[type_abi] +#[derive( + TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, ManagedVecItem, +)] pub enum EsdtTokenType { Fungible, NonFungible, @@ -80,45 +87,3 @@ impl<'a> From<&'a [u8]> for EsdtTokenType { } } } - -impl NestedEncode for EsdtTokenType { - #[inline] - fn dep_encode_or_handle_err(&self, dest: &mut O, h: H) -> Result<(), H::HandledErr> - where - O: NestedEncodeOutput, - H: EncodeErrorHandler, - { - self.as_u8().dep_encode_or_handle_err(dest, h) - } -} - -impl TopEncode for EsdtTokenType { - #[inline] - fn top_encode_or_handle_err(&self, output: O, h: H) -> Result<(), H::HandledErr> - where - O: TopEncodeOutput, - H: EncodeErrorHandler, - { - self.as_u8().top_encode_or_handle_err(output, h) - } -} - -impl NestedDecode for EsdtTokenType { - fn dep_decode_or_handle_err(input: &mut I, h: H) -> Result - where - I: NestedDecodeInput, - H: DecodeErrorHandler, - { - Ok(Self::from(u8::dep_decode_or_handle_err(input, h)?)) - } -} - -impl TopDecode for EsdtTokenType { - fn top_decode_or_handle_err(input: I, h: H) -> Result - where - I: TopDecodeInput, - H: DecodeErrorHandler, - { - Ok(Self::from(u8::top_decode_or_handle_err(input, h)?)) - } -} diff --git a/framework/base/src/types/managed/wrapped/esdt_token_data.rs b/framework/base/src/types/managed/wrapped/esdt_token_data.rs index d4b13afdbe..5bbd550299 100644 --- a/framework/base/src/types/managed/wrapped/esdt_token_data.rs +++ b/framework/base/src/types/managed/wrapped/esdt_token_data.rs @@ -12,13 +12,12 @@ use crate::{ }; use crate as multiversx_sc; // needed by the TypeAbi generated code -use crate::derive::TypeAbi; +use crate::derive::type_abi; const DECODE_ATTRIBUTE_ERROR_PREFIX: &[u8] = b"error decoding ESDT attributes: "; -#[derive( - Clone, TopDecode, TopEncode, NestedDecode, NestedEncode, TypeAbi, Debug, ManagedVecItem, -)] +#[type_abi] +#[derive(Clone, TopDecode, TopEncode, NestedDecode, NestedEncode, Debug, ManagedVecItem)] pub struct EsdtTokenData { pub token_type: EsdtTokenType, pub amount: BigUint, diff --git a/framework/base/src/types/managed/wrapped/esdt_token_payment.rs b/framework/base/src/types/managed/wrapped/esdt_token_payment.rs index 29391f5381..246b28de1d 100644 --- a/framework/base/src/types/managed/wrapped/esdt_token_payment.rs +++ b/framework/base/src/types/managed/wrapped/esdt_token_payment.rs @@ -10,12 +10,13 @@ use crate::{ derive::{NestedEncode, TopEncode}, IntoMultiValue, NestedDecode, TopDecode, }, - derive::TypeAbi, + derive::type_abi, }; use super::ManagedVec; -#[derive(TopEncode, NestedEncode, TypeAbi, Clone, PartialEq, Eq, Debug)] +#[type_abi] +#[derive(TopEncode, NestedEncode, Clone, PartialEq, Eq, Debug)] pub struct EsdtTokenPayment { pub token_identifier: TokenIdentifier, pub token_nonce: u64, diff --git a/framework/derive/src/lib.rs b/framework/derive/src/lib.rs index bdc33883fe..917ecb2159 100644 --- a/framework/derive/src/lib.rs +++ b/framework/derive/src/lib.rs @@ -48,8 +48,16 @@ pub fn proxy( #[proc_macro_derive(TypeAbi)] pub fn type_abi_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let ast: syn::DeriveInput = syn::parse(input).unwrap(); - type_abi_derive::type_abi_derive(&ast) + type_abi_derive::type_abi_derive(input).into() +} + +#[proc_macro_attribute] +pub fn type_abi( + args: proc_macro::TokenStream, + input: proc_macro::TokenStream, +) -> proc_macro::TokenStream { + assert!(args.is_empty(), "#[type_abi] attribute takes no args"); + type_abi_derive::type_abi_full(input).into() } #[proc_macro_derive(ManagedVecItem)] diff --git a/framework/derive/src/type_abi_derive.rs b/framework/derive/src/type_abi_derive.rs index cd93bdf33a..aec0b73a18 100644 --- a/framework/derive/src/type_abi_derive.rs +++ b/framework/derive/src/type_abi_derive.rs @@ -1,7 +1,6 @@ use crate::parse::attributes::extract_macro_attributes; use super::parse::attributes::extract_doc; -use proc_macro::TokenStream; use quote::{quote, ToTokens}; pub struct ExplicitDiscriminant { @@ -45,7 +44,8 @@ fn fields_snippets(fields: &syn::Fields) -> Vec { } } -pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { +pub fn type_abi_derive(input: proc_macro::TokenStream) -> proc_macro2::TokenStream { + let ast: syn::DeriveInput = syn::parse(input).unwrap(); let type_docs = extract_doc(ast.attrs.as_slice()); let macro_attributes = extract_macro_attributes(ast.attrs.as_slice()); @@ -123,7 +123,7 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { let name_str = name.to_string(); let (impl_generics, ty_generics, where_clause) = &ast.generics.split_for_impl(); let name_rust = extract_rust_type(ty_generics, name_str.clone()); - let type_abi_impl = quote! { + quote! { impl #impl_generics multiversx_sc::abi::TypeAbi for #name #ty_generics #where_clause { fn type_name() -> multiversx_sc::abi::TypeName { #name_str.into() @@ -135,8 +135,16 @@ pub fn type_abi_derive(ast: &syn::DeriveInput) -> TokenStream { #type_description_impl } - }; - type_abi_impl.into() + } +} + +pub fn type_abi_full(input: proc_macro::TokenStream) -> proc_macro2::TokenStream { + let input_conv = proc_macro2::TokenStream::from(input.clone()); + let derive_code = type_abi_derive(input); + quote! { + #input_conv + #derive_code + } } pub fn get_discriminant( diff --git a/framework/meta/src/abi_json/type_abi_json.rs b/framework/meta/src/abi_json/type_abi_json.rs index dac3f7c029..4f6bbb8fbe 100644 --- a/framework/meta/src/abi_json/type_abi_json.rs +++ b/framework/meta/src/abi_json/type_abi_json.rs @@ -87,7 +87,7 @@ impl TypeDescriptionJson { ), _ => TypeContents::NotSpecified, }, - macro_attributes: Vec::new() + macro_attributes: Vec::new(), } } } From 25912266cb030536fea6895e8282266c5d7a7d62 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 11:04:53 +0200 Subject: [PATCH 16/25] multisig - re-generated proxy --- contracts/examples/multisig/sc-config.toml | 1 + contracts/examples/multisig/src/multisig.rs | 2 +- .../src/{proxy.rs => multisig_proxy.rs} | 50 +++++++++++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) rename contracts/examples/multisig/src/{proxy.rs => multisig_proxy.rs} (94%) diff --git a/contracts/examples/multisig/sc-config.toml b/contracts/examples/multisig/sc-config.toml index ca6a294c4f..00417afac7 100644 --- a/contracts/examples/multisig/sc-config.toml +++ b/contracts/examples/multisig/sc-config.toml @@ -1,4 +1,5 @@ [settings] +proxy-paths = ["src/multisig_proxy.rs"] main = "main" [contracts.main] diff --git a/contracts/examples/multisig/src/multisig.rs b/contracts/examples/multisig/src/multisig.rs index da8c81d21f..75c13cb5dd 100644 --- a/contracts/examples/multisig/src/multisig.rs +++ b/contracts/examples/multisig/src/multisig.rs @@ -4,8 +4,8 @@ pub mod action; pub mod multisig_events; pub mod multisig_perform; pub mod multisig_propose; +// pub mod multisig_proxy; pub mod multisig_state; -pub mod proxy; pub mod user_role; use action::ActionFullInfo; diff --git a/contracts/examples/multisig/src/proxy.rs b/contracts/examples/multisig/src/multisig_proxy.rs similarity index 94% rename from contracts/examples/multisig/src/proxy.rs rename to contracts/examples/multisig/src/multisig_proxy.rs index 73b99ea08c..b0d42e16ef 100644 --- a/contracts/examples/multisig/src/proxy.rs +++ b/contracts/examples/multisig/src/multisig_proxy.rs @@ -4,8 +4,7 @@ #![allow(clippy::all)] -use multiversx_sc::imports::*; -use crate as multisig; +use multiversx_sc::proxy_imports::*; pub struct MultisigProxy; @@ -104,7 +103,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker>>, + OriginalResultMarker>>, > { self.wrapped_tx .raw_call() @@ -154,7 +153,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker, + OriginalResultMarker, > { self.wrapped_tx .raw_call() @@ -356,7 +355,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker>, + OriginalResultMarker>, > { self.wrapped_tx .raw_call() @@ -722,3 +721,44 @@ where } } +#[derive(TopEncode, TopDecode)] +pub struct ActionFullInfo +where + Api: ManagedTypeApi, +{ + pub action_id: usize, + pub action_data: Action, + pub signers: ManagedVec>, +} + +#[derive(TopEncode, TopDecode)] +pub enum Action { + Nothing, + AddBoardMember, + AddProposer, + RemoveUser, + ChangeQuorum, + SendTransferExecute, + SendAsyncCall, + SCDeployFromSource, + SCUpgradeFromSource, +} + +#[derive(TopEncode, TopDecode)] +pub struct CallActionData +where + Api: ManagedTypeApi, +{ + pub to: ManagedAddress, + pub egld_amount: BigUint, + pub endpoint_name: ManagedBuffer, + pub arguments: ManagedVec>, +} + +#[derive(TopEncode, TopDecode)] +pub enum UserRole { + None, + Proposer, + BoardMember, +} + From 0734745696c31019703e15b1f8d25bc95cb319c9 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 14:09:33 +0200 Subject: [PATCH 17/25] type abi - type name rust in struct field description --- framework/base/src/abi/type_description.rs | 6 +++--- framework/derive/src/type_abi_derive.rs | 2 +- framework/meta/src/abi_json/type_abi_json.rs | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/framework/base/src/abi/type_description.rs b/framework/base/src/abi/type_description.rs index 011b07d00c..0d2aead60b 100644 --- a/framework/base/src/abi/type_description.rs +++ b/framework/base/src/abi/type_description.rs @@ -70,7 +70,7 @@ impl TypeContents { TypeContents::Struct(struct_fields) => { for struct_field in struct_fields { names.push(struct_field.name.clone()); - names.push(struct_field.field_type.clone()); + // names.push(struct_field.field_type.clone()); } }, TypeContents::ExplicitEnum(_explicit_enum_variants) => {}, @@ -112,12 +112,12 @@ impl EnumVariantDescription { pub struct StructFieldDescription { pub docs: Vec, pub name: String, - pub field_type: String, + pub field_type: TypeNames, } impl StructFieldDescription { /// Used in code generation. - pub fn new(docs: &[&str], name: &str, field_type: String) -> Self { + pub fn new(docs: &[&str], name: &str, field_type: TypeNames) -> Self { Self { docs: docs.iter().map(|s| s.to_string()).collect(), name: name.to_string(), diff --git a/framework/derive/src/type_abi_derive.rs b/framework/derive/src/type_abi_derive.rs index aec0b73a18..56bd71d600 100644 --- a/framework/derive/src/type_abi_derive.rs +++ b/framework/derive/src/type_abi_derive.rs @@ -20,7 +20,7 @@ fn field_snippet(index: usize, field: &syn::Field) -> proc_macro2::TokenStream { field_descriptions.push(multiversx_sc::abi::StructFieldDescription::new( &[ #(#field_docs),* ], #field_name_str, - <#field_ty>::type_name_rust(), + <#field_ty>::type_names(), )); <#field_ty>::provide_type_descriptions(accumulator); } diff --git a/framework/meta/src/abi_json/type_abi_json.rs b/framework/meta/src/abi_json/type_abi_json.rs index 4f6bbb8fbe..f26cc7086d 100644 --- a/framework/meta/src/abi_json/type_abi_json.rs +++ b/framework/meta/src/abi_json/type_abi_json.rs @@ -109,7 +109,7 @@ impl From<&StructFieldDescription> for StructFieldDescriptionJson { StructFieldDescriptionJson { docs: abi.docs.iter().map(|d| d.to_string()).collect(), name: abi.name.to_string(), - field_type: abi.field_type.clone(), + field_type: abi.field_type.abi.clone(), } } } @@ -119,7 +119,10 @@ impl StructFieldDescriptionJson { StructFieldDescription { docs: self.docs.clone(), name: self.name.clone(), - field_type: self.field_type.clone(), + field_type: TypeNames { + abi: self.field_type.clone(), + rust: "".into(), + }, } } } From ba291bfdc24769f91de38ac6579caeb4438f9c85 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 18:09:22 +0200 Subject: [PATCH 18/25] tx proxy gen - handle enum with tuple and struct variants --- .../abi_tester_expected_main.abi.json | 28 ++-- .../abi_tester_expected_view.abi.json | 28 ++-- .../feature-tests/abi-tester/src/abi_proxy.rs | 16 ++- .../use_module_expected_main.abi.json | 34 ++--- .../use_module_expected_view.abi.json | 34 ++--- framework/base/src/abi/type_description.rs | 21 --- .../meta/src/cmd/contract/generate_proxy.rs | 1 + .../contract/generate_proxy/proxy_gen_main.rs | 4 +- .../generate_proxy/proxy_gen_struct_enum.rs | 122 ++++++++++++++++++ .../generate_proxy/proxy_template_gen.rs | 60 --------- 10 files changed, 198 insertions(+), 150 deletions(-) create mode 100644 framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs diff --git a/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json b/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json index 999feb222f..b94afe2670 100644 --- a/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json +++ b/contracts/feature-tests/abi-tester/abi_tester_expected_main.abi.json @@ -532,7 +532,7 @@ "fields": [ { "name": "big_uint", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "integer", @@ -540,7 +540,7 @@ }, { "name": "managed_buffer", - "type": "ManagedBuffer<$API>" + "type": "bytes" } ] }, @@ -578,7 +578,7 @@ "Tests that recursive types will not send the ABI generator into an infinite loop." ], "name": "next", - "type": "Option>" + "type": "Option" }, { "docs": [ @@ -586,7 +586,7 @@ "Also, just like above, recursive types need to work even when nested into a tuple." ], "name": "tuple_madness", - "type": "(OnlyShowsUpAsNested02, Option>)" + "type": "tuple>" } ] }, @@ -640,7 +640,7 @@ }, { "name": "amount", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "frozen", @@ -648,27 +648,27 @@ }, { "name": "hash", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "name", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "attributes", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "creator", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "royalties", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "uris", - "type": "ManagedVec<$API, ManagedBuffer<$API>>" + "type": "List" } ] }, @@ -677,7 +677,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier<$API>" + "type": "TokenIdentifier" }, { "name": "token_nonce", @@ -685,7 +685,7 @@ }, { "name": "amount", - "type": "BigUint<$API>" + "type": "BigUint" } ] }, @@ -800,7 +800,7 @@ "fields": [ { "name": "something", - "type": "[u8; 0]" + "type": "array0" } ] }, diff --git a/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json b/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json index 4a31f9ea3d..f8a30cb9a5 100644 --- a/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json +++ b/contracts/feature-tests/abi-tester/abi_tester_expected_view.abi.json @@ -193,7 +193,7 @@ "fields": [ { "name": "big_uint", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "integer", @@ -201,7 +201,7 @@ }, { "name": "managed_buffer", - "type": "ManagedBuffer<$API>" + "type": "bytes" } ] }, @@ -239,7 +239,7 @@ "Tests that recursive types will not send the ABI generator into an infinite loop." ], "name": "next", - "type": "Option>" + "type": "Option" }, { "docs": [ @@ -247,7 +247,7 @@ "Also, just like above, recursive types need to work even when nested into a tuple." ], "name": "tuple_madness", - "type": "(OnlyShowsUpAsNested02, Option>)" + "type": "tuple>" } ] }, @@ -301,7 +301,7 @@ }, { "name": "amount", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "frozen", @@ -309,27 +309,27 @@ }, { "name": "hash", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "name", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "attributes", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "creator", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "royalties", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "uris", - "type": "ManagedVec<$API, ManagedBuffer<$API>>" + "type": "List" } ] }, @@ -338,7 +338,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier<$API>" + "type": "TokenIdentifier" }, { "name": "token_nonce", @@ -346,7 +346,7 @@ }, { "name": "amount", - "type": "BigUint<$API>" + "type": "BigUint" } ] }, @@ -461,7 +461,7 @@ "fields": [ { "name": "something", - "type": "[u8; 0]" + "type": "array0" } ] }, diff --git a/contracts/feature-tests/abi-tester/src/abi_proxy.rs b/contracts/feature-tests/abi-tester/src/abi_proxy.rs index c7c7f8650a..5fdab1395f 100644 --- a/contracts/feature-tests/abi-tester/src/abi_proxy.rs +++ b/contracts/feature-tests/abi-tester/src/abi_proxy.rs @@ -664,9 +664,12 @@ pub struct OnlyShowsUpAsNested02 #[derive(TopEncode, TopDecode)] pub enum AbiEnum { Nothing, - Something, - SomethingMore, - SomeStruct, + Something(i32), + SomethingMore(u8, OnlyShowsUpAsNested08), + SomeStruct { + a: u16, + b: OnlyShowsUpAsNested09, + }, } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] @@ -838,8 +841,11 @@ pub enum ExplicitDiscriminant { pub enum ExplicitDiscriminantMixed { Zero, Unit, - Tuple, + Tuple(u16), Five, - Struct, + Struct { + a: u8, + b: u16, + }, } diff --git a/contracts/feature-tests/use-module/use_module_expected_main.abi.json b/contracts/feature-tests/use-module/use_module_expected_main.abi.json index 8ce1878d1a..2e4694e6fb 100644 --- a/contracts/feature-tests/use-module/use_module_expected_main.abi.json +++ b/contracts/feature-tests/use-module/use_module_expected_main.abi.json @@ -1023,7 +1023,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier<$API>" + "type": "TokenIdentifier" }, { "name": "token_nonce", @@ -1031,7 +1031,7 @@ }, { "name": "amount", - "type": "BigUint<$API>" + "type": "BigUint" } ] }, @@ -1065,11 +1065,11 @@ "fields": [ { "name": "depositor_addr", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "tokens", - "type": "EsdtTokenPayment<$API>" + "type": "EsdtTokenPayment" } ] }, @@ -1082,15 +1082,15 @@ }, { "name": "dest_address", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "function_name", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "arguments", - "type": "ManagedVec<$API, ManagedBuffer<$API>>" + "type": "List" } ] }, @@ -1099,19 +1099,19 @@ "fields": [ { "name": "proposer", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "actions", - "type": "ArrayVec, 4usize>" + "type": "List" }, { "name": "description", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "fees", - "type": "ProposalFees<$API>" + "type": "ProposalFees" } ] }, @@ -1170,11 +1170,11 @@ "fields": [ { "name": "total_amount", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "entries", - "type": "ManagedVec<$API, FeeEntry<$API>>" + "type": "List" } ] }, @@ -1183,19 +1183,19 @@ "fields": [ { "name": "up_votes", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "down_votes", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "down_veto_votes", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "abstain_votes", - "type": "BigUint<$API>" + "type": "BigUint" } ] }, diff --git a/contracts/feature-tests/use-module/use_module_expected_view.abi.json b/contracts/feature-tests/use-module/use_module_expected_view.abi.json index 9fd87c32f8..c84a7deac4 100644 --- a/contracts/feature-tests/use-module/use_module_expected_view.abi.json +++ b/contracts/feature-tests/use-module/use_module_expected_view.abi.json @@ -267,7 +267,7 @@ "fields": [ { "name": "token_identifier", - "type": "TokenIdentifier<$API>" + "type": "TokenIdentifier" }, { "name": "token_nonce", @@ -275,7 +275,7 @@ }, { "name": "amount", - "type": "BigUint<$API>" + "type": "BigUint" } ] }, @@ -309,11 +309,11 @@ "fields": [ { "name": "depositor_addr", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "tokens", - "type": "EsdtTokenPayment<$API>" + "type": "EsdtTokenPayment" } ] }, @@ -326,15 +326,15 @@ }, { "name": "dest_address", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "function_name", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "arguments", - "type": "ManagedVec<$API, ManagedBuffer<$API>>" + "type": "List" } ] }, @@ -343,19 +343,19 @@ "fields": [ { "name": "proposer", - "type": "ManagedAddress<$API>" + "type": "Address" }, { "name": "actions", - "type": "ArrayVec, 4usize>" + "type": "List" }, { "name": "description", - "type": "ManagedBuffer<$API>" + "type": "bytes" }, { "name": "fees", - "type": "ProposalFees<$API>" + "type": "ProposalFees" } ] }, @@ -414,11 +414,11 @@ "fields": [ { "name": "total_amount", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "entries", - "type": "ManagedVec<$API, FeeEntry<$API>>" + "type": "List" } ] }, @@ -427,19 +427,19 @@ "fields": [ { "name": "up_votes", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "down_votes", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "down_veto_votes", - "type": "BigUint<$API>" + "type": "BigUint" }, { "name": "abstain_votes", - "type": "BigUint<$API>" + "type": "BigUint" } ] }, diff --git a/framework/base/src/abi/type_description.rs b/framework/base/src/abi/type_description.rs index 0d2aead60b..f7e78ccef7 100644 --- a/framework/base/src/abi/type_description.rs +++ b/framework/base/src/abi/type_description.rs @@ -58,27 +58,6 @@ impl TypeContents { pub fn is_specified(&self) -> bool { !matches!(*self, TypeContents::NotSpecified) } - - pub fn extract_names(&self) -> Vec { - let mut names = Vec::new(); - match &self { - TypeContents::Enum(enum_variants) => { - for enum_variant in enum_variants { - names.push(enum_variant.name.clone()); - } - }, - TypeContents::Struct(struct_fields) => { - for struct_field in struct_fields { - names.push(struct_field.name.clone()); - // names.push(struct_field.field_type.clone()); - } - }, - TypeContents::ExplicitEnum(_explicit_enum_variants) => {}, - TypeContents::NotSpecified => {}, - } - - names - } } #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/framework/meta/src/cmd/contract/generate_proxy.rs b/framework/meta/src/cmd/contract/generate_proxy.rs index d8f689c428..4538ae77d4 100644 --- a/framework/meta/src/cmd/contract/generate_proxy.rs +++ b/framework/meta/src/cmd/contract/generate_proxy.rs @@ -3,3 +3,4 @@ pub mod proxy_gen_main; mod proxy_naming; pub mod proxy_sc_functions_gen; pub mod proxy_template_gen; +pub mod proxy_gen_struct_enum; diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs index 6362738c52..a55fa334f5 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs @@ -5,10 +5,10 @@ use multiversx_sc::abi::ContractAbi; use super::{ super::meta_config::MetaConfig, proxy_crate_gen::create_file, + proxy_gen_struct_enum::write_types, proxy_sc_functions_gen::write_content, proxy_template_gen::{ - write_header, write_impl_for_tx_proxy, write_struct_template, - write_struct_tx_proxy_methods, write_types, + write_header, write_impl_for_tx_proxy, write_struct_template, write_struct_tx_proxy_methods, }, }; diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs new file mode 100644 index 0000000000..b20a5cced2 --- /dev/null +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs @@ -0,0 +1,122 @@ +use std::{fs::File, io::Write}; + +use multiversx_sc::abi::{ + EnumVariantDescription, StructFieldDescription, TypeContents, TypeDescription, + TypeDescriptionContainerImpl, +}; + +use crate::cmd::contract::generate_snippets::snippet_gen_common::write_newline; + +const ZERO: &str = "0"; + +pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) { + for (_, type_description) in &types.0 { + match &type_description.contents { + TypeContents::Enum(enum_variants) => write_enum(file, enum_variants, type_description), + TypeContents::Struct(struct_fields) => { + write_struct(file, struct_fields, type_description) + }, + TypeContents::NotSpecified => {}, + TypeContents::ExplicitEnum(_) => {}, + } + } +} + +fn write_struct( + file: &mut File, + struct_fields: &Vec, + type_description: &TypeDescription, +) { + let struct_name = type_description.names.rust.replace("$API", "Api"); + write_macro_attributes(file, &type_description.macro_attributes); + writeln!(file, r#"pub struct {struct_name}"#).unwrap(); + + if struct_name.contains("") { + writeln!( + file, + r#"where + Api: ManagedTypeApi,"# + ) + .unwrap(); + } + + writeln!(file, r#"{{"#).unwrap(); + + for field in struct_fields { + writeln!( + file, + " pub {}: {},", + field.name, + field.field_type.rust.replace("$API", "Api") + ) + .unwrap(); + } + + writeln!(file, "}}").unwrap(); + write_newline(file); +} + +fn write_enum( + file: &mut File, + enum_variants: &Vec, + type_description: &TypeDescription, +) { + write_macro_attributes(file, &type_description.macro_attributes); + writeln!( + file, + r#"pub enum {} {{"#, + type_description.names.rust.replace("$API", "Api") + ) + .unwrap(); + + for variant in enum_variants { + write!(file, " {}", variant.name).unwrap(); + if variant.fields.is_empty() { + writeln!(file, ",").unwrap(); + continue; + } + + if variant.fields[0].name == ZERO { + write_tuple_in_variant(file, &variant.fields); + } else { + write_struct_in_variant(file, &variant.fields); + } + } + writeln!(file, "}}").unwrap(); + write_newline(file); +} + +fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { + if macro_attributes.is_empty() { + writeln!(file, "#[derive(TopEncode, TopDecode)]").unwrap(); + } else { + writeln!(file, "#[derive({})]", macro_attributes.join(", ")).unwrap(); + } +} + +fn write_struct_in_variant(file: &mut File, fields: &Vec) { + writeln!(file, " {{").unwrap(); + + for field in fields { + writeln!( + file, + " {}: {},", + field.name, + field.field_type.rust.replace("$API", "Api") + ) + .unwrap(); + } + + writeln!(file, " }},").unwrap(); +} + +fn write_tuple_in_variant(file: &mut File, fields: &Vec) { + write!(file, "(").unwrap(); + write!(file, "{}", fields[0].field_type.rust.replace("$API", "Api")).unwrap(); + + for field in &fields[1..] { + write!(file, ", {}", field.field_type.rust.replace("$API", "Api")).unwrap(); + } + + writeln!(file, "),").unwrap(); +} diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs index 699ecf433b..71b673e3a5 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_template_gen.rs @@ -1,7 +1,5 @@ use std::{fs::File, io::Write}; -use multiversx_sc::abi::{TypeContents, TypeDescription, TypeDescriptionContainerImpl}; - use crate::cmd::contract::generate_snippets::snippet_gen_common::write_newline; use super::proxy_naming::{proxy_methods_type_name, proxy_type_name}; @@ -22,17 +20,6 @@ pub(crate) fn write_header(file: &mut File) { write_newline(file); } -pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) { - for (_, type_description) in &types.0 { - match &type_description.contents { - TypeContents::Enum(_) => write_enum(file, type_description), - TypeContents::Struct(_) => write_struct(file, type_description), - TypeContents::NotSpecified => {}, - TypeContents::ExplicitEnum(_) => {}, - } - } -} - pub(crate) fn write_struct_template(file: &mut File, name: &str) { let proxy_type_name = proxy_type_name(name); writeln!(file, "pub struct {proxy_type_name};").unwrap(); @@ -81,50 +68,3 @@ where write_newline(file); } - -fn write_enum(file: &mut File, type_description: &TypeDescription) { - write_macro_attributes(file, &type_description.macro_attributes); - writeln!(file, r#"pub enum {} {{"#, type_description.names.abi).unwrap(); - - for content in type_description.contents.extract_names() { - writeln!(file, " {content},").unwrap(); - } - - writeln!(file, "}}").unwrap(); - write_newline(file); -} - -fn write_struct(file: &mut File, type_description: &TypeDescription) { - let struct_name = type_description.names.rust.replace("$API", "Api"); - write_macro_attributes(file, &type_description.macro_attributes); - writeln!(file, r#"pub struct {}"#, struct_name).unwrap(); - - if struct_name.contains("") { - writeln!( - file, - r#"where - Api: ManagedTypeApi,"# - ) - .unwrap(); - } - - writeln!(file, r#"{{"#).unwrap(); - - for content in type_description.contents.extract_names().chunks_exact(2) { - let variable_name = &content[0]; - let variable_type = &content[1].replace("$API", "Api"); - - writeln!(file, " pub {variable_name}: {variable_type},").unwrap(); - } - - writeln!(file, "}}").unwrap(); - write_newline(file); -} - -fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { - if macro_attributes.is_empty() { - writeln!(file, "#[derive(TopEncode, TopDecode)]").unwrap(); - } else { - writeln!(file, "#[derive({})]", macro_attributes.join(", ")).unwrap(); - } -} From 82133dff989ec081559a299ffa846e0919f89193 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 18:21:45 +0200 Subject: [PATCH 19/25] fix clippy --- .../src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs index b20a5cced2..2932437a5b 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs @@ -94,7 +94,7 @@ fn write_macro_attributes(file: &mut File, macro_attributes: &[String]) { } } -fn write_struct_in_variant(file: &mut File, fields: &Vec) { +fn write_struct_in_variant(file: &mut File, fields: &[StructFieldDescription]) { writeln!(file, " {{").unwrap(); for field in fields { @@ -110,7 +110,7 @@ fn write_struct_in_variant(file: &mut File, fields: &Vec writeln!(file, " }},").unwrap(); } -fn write_tuple_in_variant(file: &mut File, fields: &Vec) { +fn write_tuple_in_variant(file: &mut File, fields: &[StructFieldDescription]) { write!(file, "(").unwrap(); write!(file, "{}", fields[0].field_type.rust.replace("$API", "Api")).unwrap(); From 4b64a37b7e3dd102b6cd537e5a2d105b5aeee50b Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 21:39:40 +0200 Subject: [PATCH 20/25] tx proxy gen - setup and call sc-meta proxy --- contracts/examples/adder/src/adder_proxy.rs | 36 +- .../examples/crowdfunding-esdt/sc-config.toml | 2 + .../src/crowdfunding_esdt.rs | 2 +- ...mp_proxy.rs => crowdfunding_esdt_proxy.rs} | 19 +- .../examples/crypto-zombies/sc-config.toml | 2 + ...{temp_proxy.rs => crypto_zombies_proxy.rs} | 5 +- contracts/examples/crypto-zombies/src/lib.rs | 2 +- .../examples/crypto-zombies/wasm/src/lib.rs | 5 +- .../examples/digital-cash/sc-config.toml | 2 + .../examples/digital-cash/src/deposit_info.rs | 3 +- .../examples/digital-cash/src/digital_cash.rs | 1 + .../digital-cash/src/digital_cash_proxy.rs | 391 ++++++++++++++++++ 12 files changed, 443 insertions(+), 27 deletions(-) create mode 100644 contracts/examples/crowdfunding-esdt/sc-config.toml rename contracts/examples/crowdfunding-esdt/src/{temp_proxy.rs => crowdfunding_esdt_proxy.rs} (98%) create mode 100644 contracts/examples/crypto-zombies/sc-config.toml rename contracts/examples/crypto-zombies/src/{temp_proxy.rs => crypto_zombies_proxy.rs} (99%) create mode 100644 contracts/examples/digital-cash/sc-config.toml create mode 100644 contracts/examples/digital-cash/src/digital_cash_proxy.rs diff --git a/contracts/examples/adder/src/adder_proxy.rs b/contracts/examples/adder/src/adder_proxy.rs index c1b5195101..72e85655f8 100644 --- a/contracts/examples/adder/src/adder_proxy.rs +++ b/contracts/examples/adder/src/adder_proxy.rs @@ -4,7 +4,7 @@ #![allow(clippy::all)] -use multiversx_sc::imports::*; +use multiversx_sc::proxy_imports::*; pub struct AdderProxy; @@ -39,15 +39,26 @@ where From: TxFrom, Gas: TxGas, { - pub fn init>>( + pub fn init< + Arg0: CodecInto>, + >( self, initial_value: Arg0, - ) -> Tx, OriginalResultMarker<()>> { + ) -> Tx< + Env, + From, + (), + (), + Gas, + DeployCall, + OriginalResultMarker<()>, + > { self.wrapped_tx .raw_deploy() .argument(&initial_value) .original_result() } + } impl AdderProxyMethods where @@ -66,7 +77,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker>, + OriginalResultMarker>, > { self.wrapped_tx .raw_call() @@ -74,15 +85,26 @@ where .original_result() } - /// Add desired amount to the storage variable. - pub fn add>>( + /// Add desired amount to the storage variable. + pub fn add< + Arg0: CodecInto>, + >( self, value: Arg0, - ) -> Tx, OriginalResultMarker<()>> { + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { self.wrapped_tx .raw_call() .function_name("add") .argument(&value) .original_result() } + } diff --git a/contracts/examples/crowdfunding-esdt/sc-config.toml b/contracts/examples/crowdfunding-esdt/sc-config.toml new file mode 100644 index 0000000000..6539909c96 --- /dev/null +++ b/contracts/examples/crowdfunding-esdt/sc-config.toml @@ -0,0 +1,2 @@ +[settings] +proxy-paths = ["src/crowdfunding_esdt_proxy.rs"] diff --git a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs index f38da41061..abe8420d82 100644 --- a/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs +++ b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt.rs @@ -1,7 +1,7 @@ #![no_std] use multiversx_sc::{derive_imports::*, imports::*}; -pub mod temp_proxy; +pub mod crowdfunding_esdt_proxy; #[type_abi] #[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] diff --git a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt_proxy.rs similarity index 98% rename from contracts/examples/crowdfunding-esdt/src/temp_proxy.rs rename to contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt_proxy.rs index b82e54eb8c..fbbcec61d4 100644 --- a/contracts/examples/crowdfunding-esdt/src/temp_proxy.rs +++ b/contracts/examples/crowdfunding-esdt/src/crowdfunding_esdt_proxy.rs @@ -4,17 +4,7 @@ #![allow(clippy::all)] -use multiversx_sc::imports::*; - -use multiversx_sc::derive_imports::*; - -#[type_abi] -#[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] -pub enum Status { - FundingPeriod, - Successful, - Failed, -} +use multiversx_sc::proxy_imports::*; pub struct CrowdfundingProxy; @@ -225,3 +215,10 @@ where } } +#[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Copy, Debug)] +pub enum Status { + FundingPeriod, + Successful, + Failed, +} + diff --git a/contracts/examples/crypto-zombies/sc-config.toml b/contracts/examples/crypto-zombies/sc-config.toml new file mode 100644 index 0000000000..2a3130ea0d --- /dev/null +++ b/contracts/examples/crypto-zombies/sc-config.toml @@ -0,0 +1,2 @@ +[settings] +proxy-paths = ["src/crypto_zombies_proxy.rs"] \ No newline at end of file diff --git a/contracts/examples/crypto-zombies/src/temp_proxy.rs b/contracts/examples/crypto-zombies/src/crypto_zombies_proxy.rs similarity index 99% rename from contracts/examples/crypto-zombies/src/temp_proxy.rs rename to contracts/examples/crypto-zombies/src/crypto_zombies_proxy.rs index 09ae9979d1..ea1a1ef4a6 100644 --- a/contracts/examples/crypto-zombies/src/temp_proxy.rs +++ b/contracts/examples/crypto-zombies/src/crypto_zombies_proxy.rs @@ -4,7 +4,7 @@ #![allow(clippy::all)] -use multiversx_sc::imports::*; +use multiversx_sc::proxy_imports::*; pub struct CryptoZombiesProxy; @@ -410,9 +410,6 @@ where } } -use multiversx_sc::derive_imports::*; - -#[type_abi] #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct Zombie where diff --git a/contracts/examples/crypto-zombies/src/lib.rs b/contracts/examples/crypto-zombies/src/lib.rs index bed761384f..d767bd61ff 100644 --- a/contracts/examples/crypto-zombies/src/lib.rs +++ b/contracts/examples/crypto-zombies/src/lib.rs @@ -3,8 +3,8 @@ use multiversx_sc::imports::*; mod crypto_kitties_proxy; +pub mod crypto_zombies_proxy; mod storage; -pub mod temp_proxy; mod zombie; mod zombie_attack; mod zombie_factory; diff --git a/contracts/examples/crypto-zombies/wasm/src/lib.rs b/contracts/examples/crypto-zombies/wasm/src/lib.rs index 44f5f426c8..ffc350bc7d 100644 --- a/contracts/examples/crypto-zombies/wasm/src/lib.rs +++ b/contracts/examples/crypto-zombies/wasm/src/lib.rs @@ -5,9 +5,10 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 18 +// Upgrade: 1 +// Endpoints: 17 // Async Callback: 1 -// Total number of exported functions: 20 +// Total number of exported functions: 19 #![no_std] #![allow(internal_features)] diff --git a/contracts/examples/digital-cash/sc-config.toml b/contracts/examples/digital-cash/sc-config.toml new file mode 100644 index 0000000000..e33ce56689 --- /dev/null +++ b/contracts/examples/digital-cash/sc-config.toml @@ -0,0 +1,2 @@ +[settings] +proxy-paths = ["src/digital_cash_proxy.rs"] \ No newline at end of file diff --git a/contracts/examples/digital-cash/src/deposit_info.rs b/contracts/examples/digital-cash/src/deposit_info.rs index ce2c279409..daef136feb 100644 --- a/contracts/examples/digital-cash/src/deposit_info.rs +++ b/contracts/examples/digital-cash/src/deposit_info.rs @@ -25,7 +25,8 @@ where } } -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[type_abi] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct Fee { pub num_token_to_transfer: usize, pub value: EgldOrEsdtTokenPayment, diff --git a/contracts/examples/digital-cash/src/digital_cash.rs b/contracts/examples/digital-cash/src/digital_cash.rs index b46c2b7331..052faca2ef 100644 --- a/contracts/examples/digital-cash/src/digital_cash.rs +++ b/contracts/examples/digital-cash/src/digital_cash.rs @@ -5,6 +5,7 @@ use multiversx_sc::imports::*; mod constants; mod deposit_info; +pub mod digital_cash_proxy; mod helpers; mod pay_fee_and_fund; mod signature_operations; diff --git a/contracts/examples/digital-cash/src/digital_cash_proxy.rs b/contracts/examples/digital-cash/src/digital_cash_proxy.rs new file mode 100644 index 0000000000..41459dea9f --- /dev/null +++ b/contracts/examples/digital-cash/src/digital_cash_proxy.rs @@ -0,0 +1,391 @@ +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +pub struct DigitalCashProxy; + +impl TxProxyTrait for DigitalCashProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = DigitalCashProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + DigitalCashProxyMethods { wrapped_tx: tx } + } +} + +pub struct DigitalCashProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +impl DigitalCashProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init< + Arg0: CodecInto>, + Arg1: CodecInto>, + >( + self, + fee: Arg0, + token: Arg1, + ) -> Tx< + Env, + From, + (), + (), + Gas, + DeployCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_deploy() + .argument(&fee) + .argument(&token) + .original_result() + } + +} +impl DigitalCashProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn whitelist_fee_token< + Arg0: CodecInto>, + Arg1: CodecInto>, + >( + self, + fee: Arg0, + token: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("whitelistFeeToken") + .argument(&fee) + .argument(&token) + .original_result() + } + + pub fn blacklist_fee_token< + Arg0: CodecInto>, + >( + self, + token: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("blacklistFeeToken") + .argument(&token) + .original_result() + } + + pub fn claim_fees( + self, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("claimFees") + .original_result() + } + + pub fn get_amount< + Arg0: CodecInto>, + Arg1: CodecInto>, + Arg2: CodecInto, + >( + self, + address: Arg0, + token: Arg1, + nonce: Arg2, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("getAmount") + .argument(&address) + .argument(&token) + .argument(&nonce) + .original_result() + } + + pub fn pay_fee_and_fund_esdt< + Arg0: CodecInto>, + Arg1: CodecInto, + >( + self, + address: Arg0, + valability: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("payFeeAndFundESDT") + .argument(&address) + .argument(&valability) + .original_result() + } + + pub fn pay_fee_and_fund_egld< + Arg0: CodecInto>, + Arg1: CodecInto, + >( + self, + address: Arg0, + valability: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("payFeeAndFundEGLD") + .argument(&address) + .argument(&valability) + .original_result() + } + + pub fn fund< + Arg0: CodecInto>, + Arg1: CodecInto, + >( + self, + address: Arg0, + valability: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("fund") + .argument(&address) + .argument(&valability) + .original_result() + } + + pub fn deposit_fees< + Arg0: CodecInto>, + >( + self, + address: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("depositFees") + .argument(&address) + .original_result() + } + + pub fn withdraw< + Arg0: CodecInto>, + >( + self, + address: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("withdraw") + .argument(&address) + .original_result() + } + + pub fn claim< + Arg0: CodecInto>, + Arg1: CodecInto>, + >( + self, + address: Arg0, + signature: Arg1, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("claim") + .argument(&address) + .argument(&signature) + .original_result() + } + + pub fn forward< + Arg0: CodecInto>, + Arg1: CodecInto>, + Arg2: CodecInto>, + >( + self, + address: Arg0, + forward_address: Arg1, + signature: Arg2, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker<()>, + > { + self.wrapped_tx + .raw_call() + .function_name("forward") + .argument(&address) + .argument(&forward_address) + .argument(&signature) + .original_result() + } + + pub fn deposit< + Arg0: CodecInto>, + >( + self, + donor: Arg0, + ) -> Tx< + Env, + From, + To, + (), + Gas, + FunctionCall, + OriginalResultMarker>, + > { + self.wrapped_tx + .raw_call() + .function_name("deposit") + .argument(&donor) + .original_result() + } + +} +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] +pub struct DepositInfo +where + Api: ManagedTypeApi, +{ + pub depositor_address: ManagedAddress, + pub esdt_funds: ManagedVec>, + pub egld_funds: BigUint, + pub valability: u64, + pub expiration_round: u64, + pub fees: Fee, +} + +#[derive(TopEncode, NestedEncode, Clone, PartialEq, Eq, Debug)] +pub struct EsdtTokenPayment +where + Api: ManagedTypeApi, +{ + pub token_identifier: TokenIdentifier, + pub token_nonce: u64, + pub amount: BigUint, +} + +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] +pub struct Fee +where + Api: ManagedTypeApi, +{ + pub num_token_to_transfer: usize, + pub value: EgldOrEsdtTokenPayment, +} + +#[derive(TopEncode, TopDecode)] +pub struct EgldOrEsdtTokenPayment +where + Api: ManagedTypeApi, +{ + pub token_identifier: EgldOrEsdtTokenIdentifier, + pub token_nonce: u64, + pub amount: BigUint, +} + From 8e1e6684c1a21c620d096e66b783797806d3a956 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 22:47:41 +0200 Subject: [PATCH 21/25] tx proxy gen - fixed multisig --- contracts/examples/multisig/src/action.rs | 9 +++-- contracts/examples/multisig/src/multisig.rs | 2 +- .../examples/multisig/src/multisig_proxy.rs | 38 +++++++++++++------ .../generate_proxy/proxy_gen_struct_enum.rs | 29 +++++++------- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/contracts/examples/multisig/src/action.rs b/contracts/examples/multisig/src/action.rs index d36af70f90..c26c83259a 100644 --- a/contracts/examples/multisig/src/action.rs +++ b/contracts/examples/multisig/src/action.rs @@ -5,7 +5,8 @@ use multiversx_sc::{ use multiversx_sc::derive_imports::*; -#[derive(NestedEncode, NestedDecode, TypeAbi, Clone)] +#[type_abi] +#[derive(NestedEncode, NestedDecode, Clone)] pub struct CallActionData { pub to: ManagedAddress, pub egld_amount: BigUint, @@ -13,7 +14,8 @@ pub struct CallActionData { pub arguments: ManagedVec>, } -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi, Clone)] +#[type_abi] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, Clone)] pub enum Action { Nothing, AddBoardMember(ManagedAddress), @@ -47,7 +49,8 @@ impl Action { } /// Not used internally, just to retrieve results via endpoint. -#[derive(TopEncode, TypeAbi)] +#[type_abi] +#[derive(TopEncode)] pub struct ActionFullInfo { pub action_id: usize, pub action_data: Action, diff --git a/contracts/examples/multisig/src/multisig.rs b/contracts/examples/multisig/src/multisig.rs index 75c13cb5dd..96d3d5cdfa 100644 --- a/contracts/examples/multisig/src/multisig.rs +++ b/contracts/examples/multisig/src/multisig.rs @@ -4,7 +4,7 @@ pub mod action; pub mod multisig_events; pub mod multisig_perform; pub mod multisig_propose; -// pub mod multisig_proxy; +pub mod multisig_proxy; pub mod multisig_state; pub mod user_role; diff --git a/contracts/examples/multisig/src/multisig_proxy.rs b/contracts/examples/multisig/src/multisig_proxy.rs index b0d42e16ef..330637de69 100644 --- a/contracts/examples/multisig/src/multisig_proxy.rs +++ b/contracts/examples/multisig/src/multisig_proxy.rs @@ -721,7 +721,7 @@ where } } -#[derive(TopEncode, TopDecode)] +#[derive(TopEncode)] pub struct ActionFullInfo where Api: ManagedTypeApi, @@ -731,20 +731,34 @@ where pub signers: ManagedVec>, } -#[derive(TopEncode, TopDecode)] -pub enum Action { +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, Clone)] +pub enum Action +where + Api: ManagedTypeApi, +{ Nothing, - AddBoardMember, - AddProposer, - RemoveUser, - ChangeQuorum, - SendTransferExecute, - SendAsyncCall, - SCDeployFromSource, - SCUpgradeFromSource, + AddBoardMember(ManagedAddress), + AddProposer(ManagedAddress), + RemoveUser(ManagedAddress), + ChangeQuorum(usize), + SendTransferExecute(CallActionData), + SendAsyncCall(CallActionData), + SCDeployFromSource { + amount: BigUint, + source: ManagedAddress, + code_metadata: CodeMetadata, + arguments: ManagedVec>, + }, + SCUpgradeFromSource { + sc_address: ManagedAddress, + amount: BigUint, + source: ManagedAddress, + code_metadata: CodeMetadata, + arguments: ManagedVec>, + }, } -#[derive(TopEncode, TopDecode)] +#[derive(NestedEncode, NestedDecode, Clone)] pub struct CallActionData where Api: ManagedTypeApi, diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs index 2932437a5b..dabf9744c1 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs @@ -22,25 +22,32 @@ pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) } } -fn write_struct( - file: &mut File, - struct_fields: &Vec, - type_description: &TypeDescription, -) { +fn start_write_type(file: &mut File, type_type: &str, type_description: &TypeDescription,) { let struct_name = type_description.names.rust.replace("$API", "Api"); write_macro_attributes(file, &type_description.macro_attributes); - writeln!(file, r#"pub struct {struct_name}"#).unwrap(); + write!(file, r#"pub {type_type} {struct_name}"#).unwrap(); if struct_name.contains("") { writeln!( file, - r#"where + r#" +where Api: ManagedTypeApi,"# ) .unwrap(); + } else { + write!(file, " ").unwrap(); } writeln!(file, r#"{{"#).unwrap(); +} + +fn write_struct( + file: &mut File, + struct_fields: &Vec, + type_description: &TypeDescription, +) { + start_write_type(file, "struct", type_description); for field in struct_fields { writeln!( @@ -61,13 +68,7 @@ fn write_enum( enum_variants: &Vec, type_description: &TypeDescription, ) { - write_macro_attributes(file, &type_description.macro_attributes); - writeln!( - file, - r#"pub enum {} {{"#, - type_description.names.rust.replace("$API", "Api") - ) - .unwrap(); + start_write_type(file, "enum", type_description); for variant in enum_variants { write!(file, " {}", variant.name).unwrap(); From a101ad3b0b100dbae46c2191eec131c2641f1669 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 23:03:25 +0200 Subject: [PATCH 22/25] tx proxy gen - blacklist of types from framework --- .../digital-cash/src/digital_cash_proxy.rs | 20 ------------------- .../generate_proxy/proxy_gen_struct_enum.rs | 17 +++++++++++++++- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/contracts/examples/digital-cash/src/digital_cash_proxy.rs b/contracts/examples/digital-cash/src/digital_cash_proxy.rs index 41459dea9f..75dc624b92 100644 --- a/contracts/examples/digital-cash/src/digital_cash_proxy.rs +++ b/contracts/examples/digital-cash/src/digital_cash_proxy.rs @@ -360,16 +360,6 @@ where pub fees: Fee, } -#[derive(TopEncode, NestedEncode, Clone, PartialEq, Eq, Debug)] -pub struct EsdtTokenPayment -where - Api: ManagedTypeApi, -{ - pub token_identifier: TokenIdentifier, - pub token_nonce: u64, - pub amount: BigUint, -} - #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] pub struct Fee where @@ -379,13 +369,3 @@ where pub value: EgldOrEsdtTokenPayment, } -#[derive(TopEncode, TopDecode)] -pub struct EgldOrEsdtTokenPayment -where - Api: ManagedTypeApi, -{ - pub token_identifier: EgldOrEsdtTokenIdentifier, - pub token_nonce: u64, - pub amount: BigUint, -} - diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs index dabf9744c1..2179ce4a42 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_gen_struct_enum.rs @@ -9,8 +9,23 @@ use crate::cmd::contract::generate_snippets::snippet_gen_common::write_newline; const ZERO: &str = "0"; +/// Types defined in the framework don't need to be generated again in the proxy. +const TYPES_FROM_FRAMEWORK: &[&str] = &[ + "EsdtTokenPayment<$API>", + "EgldOrEsdtTokenPayment<$API>", + "EsdtTokenData<$API>", + "EgldOrEsdtTokenIdentifier<$API>", + "EgldOrEsdtTokenPayment<$API>", + "EgldOrMultiEsdtPayment<$API>", + "EsdtTokenData<$API>", +]; + pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) { for (_, type_description) in &types.0 { + if TYPES_FROM_FRAMEWORK.contains(&type_description.names.rust.as_str()) { + continue; + } + match &type_description.contents { TypeContents::Enum(enum_variants) => write_enum(file, enum_variants, type_description), TypeContents::Struct(struct_fields) => { @@ -22,7 +37,7 @@ pub(crate) fn write_types(file: &mut File, types: &TypeDescriptionContainerImpl) } } -fn start_write_type(file: &mut File, type_type: &str, type_description: &TypeDescription,) { +fn start_write_type(file: &mut File, type_type: &str, type_description: &TypeDescription) { let struct_name = type_description.names.rust.replace("$API", "Api"); write_macro_attributes(file, &type_description.macro_attributes); write!(file, r#"pub {type_type} {struct_name}"#).unwrap(); From 318070e868f65952de4e60ba1bd81574844879f6 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 21 Mar 2024 23:07:56 +0200 Subject: [PATCH 23/25] tx proxy gen - fix abi-tester --- .../feature-tests/abi-tester/src/abi_proxy.rs | 95 +++++-------------- 1 file changed, 23 insertions(+), 72 deletions(-) diff --git a/contracts/feature-tests/abi-tester/src/abi_proxy.rs b/contracts/feature-tests/abi-tester/src/abi_proxy.rs index 5fdab1395f..fe87bd79a6 100644 --- a/contracts/feature-tests/abi-tester/src/abi_proxy.rs +++ b/contracts/feature-tests/abi-tester/src/abi_proxy.rs @@ -637,27 +637,23 @@ where } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpInConstructor -{ +pub struct OnlyShowsUpInConstructor { pub something: (), } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct AbiTestType -{ +pub struct AbiTestType { pub nested: OnlyShowsUpAsNested01, pub next: Option>, pub tuple_madness: (OnlyShowsUpAsNested02, Option>), } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested01 -{ +pub struct OnlyShowsUpAsNested01 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested02 -{ +pub struct OnlyShowsUpAsNested02 { pub something: [u8; 0], } @@ -673,13 +669,11 @@ pub enum AbiEnum { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested08 -{ +pub struct OnlyShowsUpAsNested08 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested09 -{ +pub struct OnlyShowsUpAsNested09 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] @@ -693,28 +687,23 @@ where } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested03 -{ +pub struct OnlyShowsUpAsNested03 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested04 -{ +pub struct OnlyShowsUpAsNested04 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested05 -{ +pub struct OnlyShowsUpAsNested05 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested06 -{ +pub struct OnlyShowsUpAsNested06 { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested07 -{ +pub struct OnlyShowsUpAsNested07 { } #[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, Copy)] @@ -730,32 +719,6 @@ pub enum EsdtLocalRole { Transfer, } -#[derive(TopEncode, NestedEncode, Clone, PartialEq, Eq, Debug)] -pub struct EsdtTokenPayment -where - Api: ManagedTypeApi, -{ - pub token_identifier: TokenIdentifier, - pub token_nonce: u64, - pub amount: BigUint, -} - -#[derive(Clone, TopDecode, TopEncode, NestedDecode, NestedEncode, Debug, ManagedVecItem)] -pub struct EsdtTokenData -where - Api: ManagedTypeApi, -{ - pub token_type: EsdtTokenType, - pub amount: BigUint, - pub frozen: bool, - pub hash: ManagedBuffer, - pub name: ManagedBuffer, - pub attributes: ManagedBuffer, - pub creator: ManagedAddress, - pub royalties: BigUint, - pub uris: ManagedVec>, -} - #[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, ManagedVecItem)] pub enum EsdtTokenType { Fungible, @@ -766,66 +729,54 @@ pub enum EsdtTokenType { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInSingleValueMapper -{ +pub struct OnlyShowsUpAsNestedInSingleValueMapper { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInVec -{ +pub struct OnlyShowsUpAsNestedInVec { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInArrayVec -{ +pub struct OnlyShowsUpAsNestedInArrayVec { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, ManagedVecItem)] -pub struct AbiManagedVecItem -{ +pub struct AbiManagedVecItem { pub value1: u32, pub value2: u32, } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInArray -{ +pub struct OnlyShowsUpAsNestedInArray { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInBox -{ +pub struct OnlyShowsUpAsNestedInBox { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInBoxedSlice -{ +pub struct OnlyShowsUpAsNestedInBoxedSlice { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInRef -{ +pub struct OnlyShowsUpAsNestedInRef { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInSlice -{ +pub struct OnlyShowsUpAsNestedInSlice { } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNestedInOption -{ +pub struct OnlyShowsUpAsNestedInOption { } #[derive(TopEncode, TopDecode)] -pub struct OnlyShowsUpInEsdtAttr -{ +pub struct OnlyShowsUpInEsdtAttr { pub field: OnlyShowsUpAsNested10, } #[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)] -pub struct OnlyShowsUpAsNested10 -{ +pub struct OnlyShowsUpAsNested10 { } #[derive(TopEncode, TopDecode)] From 87fd1731933e4e3e1c6f2322d2eec8899cea7a8f Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 23:29:08 +0200 Subject: [PATCH 24/25] tx proxy gen - fixed test --- contracts/examples/crypto-zombies/sc-config.toml | 2 +- contracts/examples/crypto-zombies/src/lib.rs | 2 +- .../src/{crypto_zombies_proxy.rs => proxy_crypto_zombies.rs} | 0 framework/meta/tests/template_test.rs | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename contracts/examples/crypto-zombies/src/{crypto_zombies_proxy.rs => proxy_crypto_zombies.rs} (100%) diff --git a/contracts/examples/crypto-zombies/sc-config.toml b/contracts/examples/crypto-zombies/sc-config.toml index 2a3130ea0d..d43702bdfa 100644 --- a/contracts/examples/crypto-zombies/sc-config.toml +++ b/contracts/examples/crypto-zombies/sc-config.toml @@ -1,2 +1,2 @@ [settings] -proxy-paths = ["src/crypto_zombies_proxy.rs"] \ No newline at end of file +proxy-paths = ["src/proxy_crypto_zombies.rs"] \ No newline at end of file diff --git a/contracts/examples/crypto-zombies/src/lib.rs b/contracts/examples/crypto-zombies/src/lib.rs index d767bd61ff..05364f6f31 100644 --- a/contracts/examples/crypto-zombies/src/lib.rs +++ b/contracts/examples/crypto-zombies/src/lib.rs @@ -3,7 +3,7 @@ use multiversx_sc::imports::*; mod crypto_kitties_proxy; -pub mod crypto_zombies_proxy; +pub mod proxy_crypto_zombies; mod storage; mod zombie; mod zombie_attack; diff --git a/contracts/examples/crypto-zombies/src/crypto_zombies_proxy.rs b/contracts/examples/crypto-zombies/src/proxy_crypto_zombies.rs similarity index 100% rename from contracts/examples/crypto-zombies/src/crypto_zombies_proxy.rs rename to contracts/examples/crypto-zombies/src/proxy_crypto_zombies.rs diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 335fcb240b..950a6079d7 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -38,7 +38,7 @@ fn template_current_adder() { } #[test] -#[cfg_attr(not(feature = "template-test-current"), ignore)] +// #[cfg_attr(not(feature = "template-test-current"), ignore)] fn template_current_crypto_zombies() { template_test_current("crypto-zombies", "examples", "new-crypto-zombies"); } From 10e8d93dcf4910c1993a2f943e229accd4c85fed Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Thu, 21 Mar 2024 23:37:47 +0200 Subject: [PATCH 25/25] tx proxy gen - revert template test --- framework/meta/tests/template_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 950a6079d7..335fcb240b 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -38,7 +38,7 @@ fn template_current_adder() { } #[test] -// #[cfg_attr(not(feature = "template-test-current"), ignore)] +#[cfg_attr(not(feature = "template-test-current"), ignore)] fn template_current_crypto_zombies() { template_test_current("crypto-zombies", "examples", "new-crypto-zombies"); }