Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task1 + task2 #1212

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions framework/base/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ macro_rules! sc_format {

/// Equivalent to the `?` operator for SCResult.
#[deprecated(
since = "0.16.0",
note = "The `?` operator can now be used on `SCResult`, please use it instead."
since = "0.16.0",
note = "The `?` operator can now be used on `SCResult`, please use it instead."
)]
#[macro_export]
macro_rules! sc_try {
Expand Down Expand Up @@ -190,8 +190,8 @@ macro_rules! sc_try {
/// # }
/// ```
#[deprecated(
since = "0.26.0",
note = "Replace with the `#[only_owner]` attribute that can be placed on an endpoint. That one is more compact and shows up in the ABI."
since = "0.26.0",
note = "Replace with the `#[only_owner]` attribute that can be placed on an endpoint. That one is more compact and shows up in the ABI."
)]
#[macro_export]
macro_rules! only_owner {
Expand All @@ -209,3 +209,47 @@ macro_rules! non_zero_usize {
NonZeroUsize::new($input).unwrap_or_else(|| sc_panic!($error_msg))
};
}

#[macro_export]
macro_rules! endpoints_proxy {
($endpoint_name:ident, $address:ident)
=> {
multiversx_sc::types::ContractCallNoPayment::new(
$address,
stringify!($endpoint_name),
);
};
}

#[macro_export]
macro_rules! constructors_proxy {
($opt_address:ident)
=> {
multiversx_sc::types::new_contract_deploy(
$opt_address,
);
};
}

#[macro_export]
macro_rules! extract_opt_address {
($address:expr) => {
{
core::mem::replace(
&mut $address.address,
multiversx_sc::types::ManagedOption::none(),
)
}
};
}

#[macro_export]
macro_rules! extract_address {
($address:expr)
=> {
{
multiversx_sc::extract_opt_address!($address)
.unwrap_or_sc_panic(multiversx_sc::err_msg::RECIPIENT_ADDRESS_NOT_SET)
}
};
}
18 changes: 18 additions & 0 deletions framework/meta/src/cli_args/cli_args_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ pub enum ContractCliAction {
about = "Generates a snippets project, based on the contract ABI."
)]
GenerateSnippets(GenerateSnippetsArgs),

#[command(
name = "proxy",
about = "Generates a proxy in trait"
)]
GenerateProxies,

#[command(
name = "proxy-struct",
about = "Generates a proxy in struct"
)]
GenerateProxiesStruct
}

impl CliArgsToRaw for ContractCliAction {
Expand Down Expand Up @@ -97,6 +109,12 @@ impl CliArgsToRaw for ContractCliAction {
raw.push("snippets".to_string());
raw.append(&mut args.to_raw());
},
ContractCliAction::GenerateProxies => {
raw.push("proxy".to_string());
},
ContractCliAction::GenerateProxiesStruct => {
raw.push("proxy-struct".to_string());
}
}
raw
}
Expand Down
4 changes: 4 additions & 0 deletions framework/meta/src/cmd/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod generate_proxy_trait;
mod generate_proxy_struct;
mod generate_snippets;
mod meta_abi;
mod meta_config;
Expand Down Expand Up @@ -31,6 +33,8 @@ pub fn cli_main<AbiObj: ContractAbiProvider>() {
ContractCliAction::GenerateSnippets(gs_args) => {
meta_config_opt.generate_rust_snippets(&gs_args)
},
ContractCliAction::GenerateProxies => meta_config_opt.generate_rust_proxies(),
ContractCliAction::GenerateProxiesStruct => meta_config_opt.generate_rust_proxies_struct()
}
}

Expand Down
3 changes: 3 additions & 0 deletions framework/meta/src/cmd/contract/generate_proxy_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod proxy_struct_gen_main;
pub mod proxy_struct_template_gen;
pub mod proxy_struct_sc_functions_gen;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::fs::File;

use multiversx_sc::abi::ContractAbi;

use crate::cmd::contract::generate_proxy_trait::proxy_trait_crate_gen::create_and_get_lib_file;

use super::{
proxy_struct_sc_functions_gen::write_content,
proxy_struct_template_gen::{write_imports, write_struct_template},
super::meta_config::MetaConfig,
};

static PROXIES_SOURCE_FILE_NAME: &str = "proxies_struct_interactor_main.rs";

impl MetaConfig {
pub fn generate_rust_proxies_struct(&self) {
let file = create_and_get_lib_file(PROXIES_SOURCE_FILE_NAME);
write_proxies_struct_to_file(
file,
&self.original_contract_abi,
);
}
}

fn write_proxies_struct_to_file(
mut file: File,
abi: &ContractAbi,
) {
write_imports(&mut file);
write_struct_template(&mut file);
write_content(&mut file, abi);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use std::{fs::File, io::Write};

use multiversx_sc::abi::{ContractAbi, EndpointAbi, InputAbi, OutputAbis};

use crate::cmd::contract::generate_snippets::snippet_gen_common::write_newline;
use crate::cmd::contract::generate_snippets::snippet_sc_functions_gen::map_output_types_to_rust_types;
use crate::cmd::contract::generate_snippets::snippet_type_map::{handle_abi_type, RustTypeString};

pub(crate) fn write_content(
file: &mut File,
abi: &ContractAbi,
)
{
for constructor_abi in &abi.constructors {
write_endpoint(file, constructor_abi, "ContractDeploy");
write_constructor_content_macro(file);
write_constructor_contract_deploy(file, &constructor_abi.inputs);
writeln!(file, "\t\t___contract_deploy___").unwrap();
writeln!(file, "\t}}").unwrap();
write_newline(file);
}

for endpoint_abi in &abi.endpoints {
write_endpoint(file, endpoint_abi, "ContractCallNoPayment");
write_endpoint_content_macro(file, endpoint_abi.name);

Check failure on line 25 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Rust tests

mismatched types

Check failure on line 25 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Clippy linter check

[clippy] reported by reviewdog 🐶 error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:25:44 | 25 | write_endpoint_content_macro(file, endpoint_abi.name); | ---------------------------- ^^^^^^^^^^^^^^^^^ expected `&str`, found `String` | | | arguments to this function are incorrect | note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:63:4 | 63 | fn write_endpoint_content_macro(file: &mut File, name: &str) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ---------- help: consider borrowing here | 25 | write_endpoint_content_macro(file, &endpoint_abi.name); | + Raw Output: framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:25:44:e:error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:25:44 | 25 | write_endpoint_content_macro(file, endpoint_abi.name); | ---------------------------- ^^^^^^^^^^^^^^^^^ expected `&str`, found `String` | | | arguments to this function are incorrect | note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:63:4 | 63 | fn write_endpoint_content_macro(file: &mut File, name: &str) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ---------- help: consider borrowing here | 25 | write_endpoint_content_macro(file, &endpoint_abi.name); | + __END__

Check failure on line 25 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

mismatched types

Check failure on line 25 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

mismatched types

Check failure on line 25 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Wasm tests

mismatched types
write_contract_call(file, &endpoint_abi.inputs);
writeln!(file, "\t\t___contract_call___").unwrap();
writeln!(file, "\t}}").unwrap();
write_newline(file);
}

writeln!(file, "}}").unwrap();
}

fn write_constructor_contract_deploy(file: &mut File, inputs: &[InputAbi]) {
if inputs.is_empty() {
return;
}

for input in inputs.iter() {
write_constructor_contract_call(file, &input.arg_name);

Check failure on line 41 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Rust tests

mismatched types

Check failure on line 41 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Clippy linter check

[clippy] reported by reviewdog 🐶 error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:41:47 | 41 | write_constructor_contract_call(file, &input.arg_name); | ------------------------------- ^^^^^^^^^^^^^^^ expected `&&str`, found `&String` | | | arguments to this function are incorrect | = note: expected reference `&&str` found reference `&std::string::String` note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:59:4 | 59 | fn write_constructor_contract_call(file: &mut File, arg_name: &&str) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------------- Raw Output: framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:41:47:e:error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:41:47 | 41 | write_constructor_contract_call(file, &input.arg_name); | ------------------------------- ^^^^^^^^^^^^^^^ expected `&&str`, found `&String` | | | arguments to this function are incorrect | = note: expected reference `&&str` found reference `&std::string::String` note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:59:4 | 59 | fn write_constructor_contract_call(file: &mut File, arg_name: &&str) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------------- __END__

Check failure on line 41 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

mismatched types

Check failure on line 41 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

mismatched types

Check failure on line 41 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Wasm tests

mismatched types
}
}

fn write_contract_call(file: &mut File, inputs: &[InputAbi]) {
if inputs.is_empty() {
return;
}

for input in inputs.iter() {
write_contract_call_input(file, &input.arg_name);

Check failure on line 51 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Rust tests

mismatched types

Check failure on line 51 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Clippy linter check

[clippy] reported by reviewdog 🐶 error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:51:41 | 51 | write_contract_call_input(file, &input.arg_name); | ------------------------- ^^^^^^^^^^^^^^^ expected `&&str`, found `&String` | | | arguments to this function are incorrect | = note: expected reference `&&str` found reference `&std::string::String` note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:55:4 | 55 | fn write_contract_call_input(file: &mut File, arg_name: &&str) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ --------------- Raw Output: framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:51:41:e:error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:51:41 | 51 | write_contract_call_input(file, &input.arg_name); | ------------------------- ^^^^^^^^^^^^^^^ expected `&&str`, found `&String` | | | arguments to this function are incorrect | = note: expected reference `&&str` found reference `&std::string::String` note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:55:4 | 55 | fn write_contract_call_input(file: &mut File, arg_name: &&str) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ --------------- __END__

Check failure on line 51 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

mismatched types

Check failure on line 51 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

mismatched types

Check failure on line 51 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Wasm tests

mismatched types
}
}

fn write_contract_call_input(file: &mut File, arg_name: &&str) {
writeln!(file, "\t\tContractCall::proxy_arg(&mut ___contract_call___, &{arg_name});").unwrap();
}

fn write_constructor_contract_call(file: &mut File, arg_name: &&str) {
writeln!(file, "\t\t___contract_deploy___.push_endpoint_arg(&{arg_name});").unwrap();
}

fn write_endpoint_content_macro(file: &mut File, name: &str) {
writeln!(file, "\t\tlet ___address___ = multiversx_sc::extract_address!(self);").unwrap();
writeln!(file, "\t\tlet mut ___contract_call___ = multiversx_sc::endpoints_proxy!({name}, ___address___);").unwrap();
}

fn write_constructor_content_macro(file: &mut File) {
writeln!(file, "\t\tlet ___opt_address___ = multiversx_sc::extract_opt_address!(self);").unwrap();
writeln!(file, "\t\tlet mut ___contract_deploy___ = multiversx_sc::constructors_proxy!(___opt_address___);").unwrap();
}

fn write_endpoint(file: &mut File, endpoint_abi: &EndpointAbi, interaction_deploy: &str) {
write_info_endpoint(file, endpoint_abi.docs);

Check failure on line 74 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Rust tests

mismatched types

Check failure on line 74 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Clippy linter check

[clippy] reported by reviewdog 🐶 error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:74:31 | 74 | write_info_endpoint(file, endpoint_abi.docs); | ------------------- ^^^^^^^^^^^^^^^^^ expected `&[&str]`, found `Vec<String>` | | | arguments to this function are incorrect | = note: expected reference `&[&str]` found struct `std::vec::Vec<std::string::String>` note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:108:4 | 108 | fn write_info_endpoint(file: &mut File, abi_docs: &[&str]) { | ^^^^^^^^^^^^^^^^^^^ ----------------- Raw Output: framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:74:31:e:error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:74:31 | 74 | write_info_endpoint(file, endpoint_abi.docs); | ------------------- ^^^^^^^^^^^^^^^^^ expected `&[&str]`, found `Vec<String>` | | | arguments to this function are incorrect | = note: expected reference `&[&str]` found struct `std::vec::Vec<std::string::String>` note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:108:4 | 108 | fn write_info_endpoint(file: &mut File, abi_docs: &[&str]) { | ^^^^^^^^^^^^^^^^^^^ ----------------- __END__

Check failure on line 74 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

mismatched types

Check failure on line 74 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

mismatched types

Check failure on line 74 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Wasm tests

mismatched types
write_endpoint_fn(file, endpoint_abi.rust_method_name);

Check failure on line 75 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Rust tests

mismatched types

Check failure on line 75 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Clippy linter check

[clippy] reported by reviewdog 🐶 error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:75:29 | 75 | write_endpoint_fn(file, endpoint_abi.rust_method_name); | ----------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `String` | | | arguments to this function are incorrect | note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:104:4 | 104 | fn write_endpoint_fn(file: &mut File, rust_method_name: &str) { | ^^^^^^^^^^^^^^^^^ ---------------------- help: consider borrowing here | 75 | write_endpoint_fn(file, &endpoint_abi.rust_method_name); | + Raw Output: framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:75:29:e:error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:75:29 | 75 | write_endpoint_fn(file, endpoint_abi.rust_method_name); | ----------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `String` | | | arguments to this function are incorrect | note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs:104:4 | 104 | fn write_endpoint_fn(file: &mut File, rust_method_name: &str) { | ^^^^^^^^^^^^^^^^^ ---------------------- help: consider borrowing here | 75 | write_endpoint_fn(file, &endpoint_abi.rust_method_name); | + __END__

Check failure on line 75 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

mismatched types

Check failure on line 75 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

mismatched types

Check failure on line 75 in framework/meta/src/cmd/contract/generate_proxy_struct/proxy_struct_sc_functions_gen.rs

View workflow job for this annotation

GitHub Actions / Wasm tests

mismatched types
write_generic_args(file, &endpoint_abi.inputs);
write_parameters(file, &endpoint_abi.inputs, interaction_deploy);
write_output(file, &endpoint_abi.outputs);
}

fn write_output(file: &mut File, outputs: &OutputAbis) {
let output_type = map_output_types_to_rust_types(outputs);

let output_type_print = output_type.replace("<StaticApi>", "<A>");
write!(file, "{output_type_print}", ).unwrap();
writeln!(file, "> {{").unwrap();
}

fn write_parameters(file: &mut File, inputs: &[InputAbi], interaction_deploy: &str) {
writeln!(file, "(").unwrap();
writeln!(file, "\t\t&mut self,").unwrap();

for (index, input) in inputs.iter().enumerate() {
write_parameter_arg(file, index, &input.arg_name);
}

write!(file, "\t) -> {interaction_deploy}<A, ").unwrap();
}

fn write_parameter_arg(file: &mut File, index: usize, arg_name: &str) {
writeln!(file, "\t\t{arg_name}: Arg{index},").unwrap()
}

fn write_endpoint_fn(file: &mut File, rust_method_name: &str) {
write!(file, "\tfn {rust_method_name}").unwrap();
}

fn write_info_endpoint(file: &mut File, abi_docs: &[&str]) {
if !abi_docs.is_empty() {
write!(file, "\t//").unwrap();
}

for &abi_doc in abi_docs {
writeln!(file, "{abi_doc} ").unwrap();
}
}

fn write_generic_args(file: &mut File, inputs: &[InputAbi]) {
if inputs.is_empty() {
return;
}

writeln!(file, "<").unwrap();

for (index, input) in inputs.iter().enumerate() {
write_argument(file, index, input.type_name.to_string());
}

write!(file, "\t>").unwrap();
}

fn write_argument(file: &mut File, index: usize, type_name: String) {
let mut type_string = RustTypeString::default();
handle_abi_type(&mut type_string, type_name);
let type_string_str = type_string.get_type_name().to_string();

let type_print = type_string_str.replace("<StaticApi>", "<A>");

writeln!(file, "\t\tArg{index}: multiversx_sc::codec::CodecInto<{}>,", type_print).unwrap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::{fs::File, io::Write};

use crate::cmd::contract::generate_snippets::snippet_gen_common::write_newline;

pub(crate) fn write_imports(file: &mut File) {
writeln!(
file,
r#"#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
multiversx_sc::imports!();"#
)
.unwrap();

write_newline(file);
}

pub(crate) fn write_struct_template(file: &mut File) {
write!(
file,
"pub struct Proxy<A>
where
A: multiversx_sc::api::VMApi + 'static,
{{
pub address: ManagedOption<A, ManagedAddress<A>>,
}}

impl<A> Proxy<A>
where
A: multiversx_sc::api::VMApi + 'static,
{{").unwrap();
}
4 changes: 4 additions & 0 deletions framework/meta/src/cmd/contract/generate_proxy_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod proxy_trait_crate_gen;
pub mod proxy_trait_gen_main;
pub mod proxy_trait_template_gen;
pub mod proxy_trait_sc_functions_gen;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::fs::File;

#[must_use]
pub(crate) fn create_and_get_lib_file(proxies_file_name: &str) -> File {
let lib_path = format!("../{proxies_file_name}");
match File::options().create_new(true).write(true).open(&lib_path) {
Ok(f) => f,
Err(_) => panic!("{lib_path} file already exists, --overwrite option for proxies was not provided"),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::fs::File;

use multiversx_sc::abi::ContractAbi;

use super::{
proxy_trait_crate_gen::create_and_get_lib_file,
proxy_trait_sc_functions_gen::write_state_struct_impl,
proxy_trait_template_gen::write_proxy_imports,
super::meta_config::MetaConfig,
};

static PROXIES_SOURCE_FILE_NAME: &str = "proxies_trait_interactor_main.rs";

impl MetaConfig {
pub fn generate_rust_proxies(&self) {
let file = create_and_get_lib_file(PROXIES_SOURCE_FILE_NAME);
write_proxies_to_file(
file,
&self.original_contract_abi,
);
}
}

fn write_proxies_to_file(
mut file: File,
abi: &ContractAbi,
) {
write_proxy_imports(&mut file, abi.name);

Check failure on line 28 in framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs

View workflow job for this annotation

GitHub Actions / Rust tests

mismatched types

Check failure on line 28 in framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs

View workflow job for this annotation

GitHub Actions / Clippy linter check

[clippy] reported by reviewdog 🐶 error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs:28:36 | 28 | write_proxy_imports(&mut file, abi.name); | ------------------- ^^^^^^^^ expected `&str`, found `String` | | | arguments to this function are incorrect | note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_template_gen.rs:3:15 | 3 | pub(crate) fn write_proxy_imports(file: &mut File, abi_name: &str) { | ^^^^^^^^^^^^^^^^^^^ -------------- help: consider borrowing here | 28 | write_proxy_imports(&mut file, &abi.name); | + Raw Output: framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs:28:36:e:error[E0308]: mismatched types --> framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs:28:36 | 28 | write_proxy_imports(&mut file, abi.name); | ------------------- ^^^^^^^^ expected `&str`, found `String` | | | arguments to this function are incorrect | note: function defined here --> framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_template_gen.rs:3:15 | 3 | pub(crate) fn write_proxy_imports(file: &mut File, abi_name: &str) { | ^^^^^^^^^^^^^^^^^^^ -------------- help: consider borrowing here | 28 | write_proxy_imports(&mut file, &abi.name); | + __END__

Check failure on line 28 in framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs

View workflow job for this annotation

GitHub Actions / Template tool test - released templates

mismatched types

Check failure on line 28 in framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs

View workflow job for this annotation

GitHub Actions / Template tool test - current (unreleased) templates

mismatched types

Check failure on line 28 in framework/meta/src/cmd/contract/generate_proxy_trait/proxy_trait_gen_main.rs

View workflow job for this annotation

GitHub Actions / Wasm tests

mismatched types
write_state_struct_impl(&mut file, abi);
}
Loading
Loading