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

Fix proxy #1518

Merged
merged 13 commits into from
Apr 2, 2024
115 changes: 72 additions & 43 deletions contracts/feature-tests/abi-tester/src/abi_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;
Expand Down Expand Up @@ -57,6 +60,32 @@ where
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> AbiTesterProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
/// Upgrade constructor.
pub fn upgrade<
Arg0: CodecInto<i32>,
Arg1: CodecInto<OnlyShowsUpInConstructor>,
>(
self,
_constructor_arg_1: Arg0,
_constructor_arg_2: Arg1,
) -> TxProxyUpgrade<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_upgrade()
.argument(&_constructor_arg_1)
.argument(&_constructor_arg_2)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> AbiTesterProxyMethods<Env, From, To, Gas>
where
Expand Down Expand Up @@ -403,7 +432,8 @@ pub struct AbiTestType {
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested01 {}
pub struct OnlyShowsUpAsNested01 {
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested02 {
Expand All @@ -415,14 +445,19 @@ pub enum AbiEnum {
Nothing,
Something(i32),
SomethingMore(u8, OnlyShowsUpAsNested08),
SomeStruct { a: u16, b: OnlyShowsUpAsNested09 },
SomeStruct {
a: u16,
b: OnlyShowsUpAsNested09,
},
}

#[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)]
pub struct AbiManagedType<Api>
Expand All @@ -435,52 +470,36 @@ 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 {}

#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, Copy)]
pub enum EsdtLocalRole {
None,
Mint,
Burn,
NftCreate,
NftAddQuantity,
NftBurn,
NftAddUri,
NftUpdateAttributes,
Transfer,
}

#[derive(
TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, ManagedVecItem,
)]
pub enum EsdtTokenType {
Fungible,
NonFungible,
SemiFungible,
Meta,
Invalid,
pub struct OnlyShowsUpAsNested07 {
}

#[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 {
Expand All @@ -489,30 +508,37 @@ pub struct AbiManagedVecItem {
}

#[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 field: OnlyShowsUpAsNested10,
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested10 {}
pub struct OnlyShowsUpAsNested10 {
}

#[derive(TopEncode, TopDecode)]
pub enum ExplicitDiscriminant {
Expand All @@ -529,5 +555,8 @@ pub enum ExplicitDiscriminantMixed {
Unit,
Tuple(u16),
Five,
Struct { a: u8, b: u16 },
Struct {
a: u8,
b: u16,
},
}
20 changes: 1 addition & 19 deletions framework/derive/src/type_abi_derive.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::parse::attributes::extract_macro_attributes;

use super::parse::attributes::extract_doc;
use quote::{quote, ToTokens};
use quote::quote;

pub struct ExplicitDiscriminant {
pub variant_index: usize,
Expand Down Expand Up @@ -122,17 +122,11 @@ pub fn type_abi_derive(input: proc_macro::TokenStream) -> proc_macro2::TokenStre
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());
quote! {
impl #impl_generics multiversx_sc::abi::TypeAbi for #name #ty_generics #where_clause {
fn type_name() -> multiversx_sc::abi::TypeName {
#name_str.into()
}

fn type_name_rust() -> multiversx_sc::abi::TypeName {
#name_rust.into()
}

#type_description_impl
}
}
Expand Down Expand Up @@ -189,15 +183,3 @@ 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>");
output_name
}
3 changes: 1 addition & 2 deletions framework/meta/src/cmd/contract/generate_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod proxy_crate_gen;
pub mod proxy_gen_main;
pub mod proxy_gen_struct_enum;
mod proxy_generator;
mod proxy_naming;
pub mod proxy_sc_functions_gen;
pub mod proxy_template_gen;
31 changes: 6 additions & 25 deletions framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
use std::fs::File;

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_tx_proxy_methods,
write_tx_proxy_type_def,
},
super::meta_config::MetaConfig, proxy_crate_gen::create_file, proxy_generator::ProxyGenerator,
};

const OUTPUT_PROXY_PATH: &str = "/output/proxy.rs";

impl MetaConfig {
pub fn generate_proxy(&self) {
write_proxy_with_explicit_path(OUTPUT_PROXY_PATH, &self.original_contract_abi);
write_proxy_with_explicit_path(OUTPUT_PROXY_PATH, self);
for path in &self.sc_config.proxy_paths {
write_proxy_with_explicit_path(path, &self.original_contract_abi);
write_proxy_with_explicit_path(path, self);
}
}
}

fn write_proxy_with_explicit_path(path: &str, abi: &ContractAbi) {
fn write_proxy_with_explicit_path(path: &str, meta_config: &MetaConfig) {
let file = create_file(path);
write_proxy_to_file(file, abi);
}

fn write_proxy_to_file(mut file: File, abi: &ContractAbi) {
write_header(&mut file);
write_tx_proxy_type_def(&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.clone());
write_types(&mut file, &abi.type_descriptions);
let proxy_generator = ProxyGenerator::new(meta_config);
proxy_generator.write_proxy_to_file(file);
}
Loading
Loading