Skip to content

Commit

Permalink
Merge pull request #1628 from multiversx/proxy-config-variant
Browse files Browse the repository at this point in the history
sc-config proxy - add variant
  • Loading branch information
andrei-marinica authored May 15, 2024
2 parents 25acc26 + 62658b6 commit 0a20676
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 45 deletions.
13 changes: 11 additions & 2 deletions contracts/feature-tests/multi-contract-features/multicontract.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ features = []

[contracts.multi-contract-main.profile]
# these are just the defaults, checking that parsing works fine
codegen-units = 1
codegen-units = 1
opt-level = "z"
lto = true
debug = false
Expand All @@ -31,9 +31,18 @@ add-unlabelled = false
add-labels = ["mcs-external-view"]

[contracts.multi-contract-example-feature]
add-unlabelled = true # optional here, since the default is true
add-unlabelled = true # optional here, since the default is true
features = ["example_feature"]

[contracts.multi-contract-alt-impl]
add-unlabelled = false
add-labels = ["alt-impl"]

[[proxy]]
variant = "multi_contract_example_feature"
path = "src/multi_contract_example_feature_proxy.rs"


[[proxy]]
variant = "multi_contract_alt_impl"
path = "src/multi_contract_alt_impl_proxy.rs"
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

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

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

use multiversx_sc::proxy_imports::*;

pub struct MultiContractFeaturesProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for MultiContractFeaturesProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = MultiContractFeaturesProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
MultiContractFeaturesProxyMethods { wrapped_tx: tx }
}
}

pub struct MultiContractFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> MultiContractFeaturesProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn alternative_init(
self,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, &'static str> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> MultiContractFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn alternative_sample_value(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, &'static str> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("sample_value")
.original_result()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

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

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

use multiversx_sc::proxy_imports::*;

pub struct MultiContractFeaturesProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for MultiContractFeaturesProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = MultiContractFeaturesProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
MultiContractFeaturesProxyMethods { wrapped_tx: tx }
}
}

pub struct MultiContractFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> MultiContractFeaturesProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn default_init<
Arg0: ProxyArg<BigUint<Env::Api>>,
>(
self,
sample_value: Arg0,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.argument(&sample_value)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> MultiContractFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn sample_value(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, BigUint<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("sample_value")
.original_result()
}

pub fn example_feature_message(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, &'static str> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("example_feature_message")
.original_result()
}
}
26 changes: 24 additions & 2 deletions framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use multiversx_sc::abi::ContractAbi;

use crate::cmd::contract::sc_config::ProxyConfigSerde;

use super::{
Expand All @@ -14,8 +16,28 @@ impl MetaConfig {
}
}

fn write_proxy_with_explicit_path(proxy_config: &ProxyConfigSerde, meta_config: &mut MetaConfig) {
fn write_proxy_with_explicit_path(proxy_config: &ProxyConfigSerde, meta_config: &MetaConfig) {
let contract_abi = extract_contract_abi(proxy_config, meta_config);
let mut file = create_file(&proxy_config.path);
let mut proxy_generator = ProxyGenerator::new(meta_config, &mut file, proxy_config);
let mut proxy_generator =
ProxyGenerator::new(meta_config, &mut file, proxy_config, contract_abi);
proxy_generator.write_proxy_to_file();
}

fn extract_contract_abi<'a>(
proxy_config: &'a ProxyConfigSerde,
meta_config: &'a MetaConfig,
) -> &'a ContractAbi {
if proxy_config.variant.is_some() {
let variant = proxy_config.variant.as_ref().unwrap();
for contract_variant in &meta_config.sc_config.contracts {
if variant == &contract_variant.public_name_snake_case() {
return &contract_variant.abi;
}
}

panic!("No variant with name \"{}\" in multicontract", variant);
}

&meta_config.original_contract_abi
}
Loading

0 comments on commit 0a20676

Please sign in to comment.