From e626ba6a2cf1b8e1df9f559a7f6564d20fcdc18c Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Wed, 27 Mar 2024 18:39:18 +0100 Subject: [PATCH 1/3] proxy pause sc migration to new proxy and unified syntax --- .../proxy-pause/src/pause_sc_proxy.rs | 99 +++++++++++++++++++ .../examples/proxy-pause/src/proxy_pause.rs | 26 ++--- 2 files changed, 107 insertions(+), 18 deletions(-) create mode 100644 contracts/examples/proxy-pause/src/pause_sc_proxy.rs diff --git a/contracts/examples/proxy-pause/src/pause_sc_proxy.rs b/contracts/examples/proxy-pause/src/pause_sc_proxy.rs new file mode 100644 index 0000000000..0984e09ea1 --- /dev/null +++ b/contracts/examples/proxy-pause/src/pause_sc_proxy.rs @@ -0,0 +1,99 @@ +// 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 PausableProxy; + +impl TxProxyTrait for PausableProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = PausableProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + PausableProxyMethods { wrapped_tx: tx } + } +} + +pub struct PausableProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl PausableProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> TxProxyDeploy { + self.wrapped_tx + .raw_deploy() + .original_result() + } +} + +#[rustfmt::skip] +impl PausableProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn upgrade( + self, + ) -> TxProxyUpgrade { + self.wrapped_tx + .raw_upgrade() + .original_result() + } +} + +#[rustfmt::skip] +impl PausableProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn pause( + self, + ) -> TxProxyCall { + self.wrapped_tx + .raw_call() + .function_name("pause") + .original_result() + } + + pub fn unpause( + self, + ) -> TxProxyCall { + self.wrapped_tx + .raw_call() + .function_name("unpause") + .original_result() + } +} diff --git a/contracts/examples/proxy-pause/src/proxy_pause.rs b/contracts/examples/proxy-pause/src/proxy_pause.rs index 01dbfbf449..aa5f07e7d6 100644 --- a/contracts/examples/proxy-pause/src/proxy_pause.rs +++ b/contracts/examples/proxy-pause/src/proxy_pause.rs @@ -1,17 +1,7 @@ #![no_std] use multiversx_sc::imports::*; - -mod pause_proxy { - #[multiversx_sc::proxy] - pub trait Pausable { - #[endpoint] - fn pause(&self); - - #[endpoint] - fn unpause(&self); - } -} +pub mod pause_sc_proxy; #[multiversx_sc::contract] pub trait PauseProxy { @@ -46,23 +36,26 @@ pub trait PauseProxy { fn for_each_contract(&self, f: F) where - F: Fn(pause_proxy::ProxyTo), + F: Fn(pause_sc_proxy::PausableProxyMethods, (), &ManagedAddress, ()>), { for contract_address in self.contracts().iter() { - f(self.pausable_contract().contract(contract_address)); + f(self + .tx() + .to(&contract_address) + .typed(pause_sc_proxy::PausableProxy)); } } #[endpoint] fn pause(&self) { self.require_owner(); - self.for_each_contract(|mut contract| contract.pause().execute_on_dest_context()); + self.for_each_contract(|contract| contract.pause().sync_call()); } #[endpoint] fn unpause(&self) { self.require_owner(); - self.for_each_contract(|mut contract| contract.unpause().execute_on_dest_context()); + self.for_each_contract(|contract| contract.unpause().sync_call()); } fn require_owner(&self) { @@ -79,7 +72,4 @@ pub trait PauseProxy { #[view] #[storage_mapper("contracts")] fn contracts(&self) -> SetMapper; - - #[proxy] - fn pausable_contract(&self) -> pause_proxy::Proxy; } From 2665c3a37f88be4abca57abdc48bad8fdd9fedfc Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Thu, 28 Mar 2024 17:05:49 +0100 Subject: [PATCH 2/3] removed init and upgrade from proxy --- .../proxy-pause/src/pause_sc_proxy.rs | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/contracts/examples/proxy-pause/src/pause_sc_proxy.rs b/contracts/examples/proxy-pause/src/pause_sc_proxy.rs index 0984e09ea1..addb769ed0 100644 --- a/contracts/examples/proxy-pause/src/pause_sc_proxy.rs +++ b/contracts/examples/proxy-pause/src/pause_sc_proxy.rs @@ -35,41 +35,6 @@ where wrapped_tx: Tx, } -#[rustfmt::skip] -impl PausableProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - Gas: TxGas, -{ - pub fn init( - self, - ) -> TxProxyDeploy { - self.wrapped_tx - .raw_deploy() - .original_result() - } -} - -#[rustfmt::skip] -impl PausableProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn upgrade( - self, - ) -> TxProxyUpgrade { - self.wrapped_tx - .raw_upgrade() - .original_result() - } -} - #[rustfmt::skip] impl PausableProxyMethods where From e3f758a2d55565e8f305f9133416a145f6a41040 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 29 Mar 2024 09:54:24 +0100 Subject: [PATCH 3/3] removed generated tag and allows --- contracts/examples/proxy-pause/src/pause_sc_proxy.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/contracts/examples/proxy-pause/src/pause_sc_proxy.rs b/contracts/examples/proxy-pause/src/pause_sc_proxy.rs index addb769ed0..441b9b17c5 100644 --- a/contracts/examples/proxy-pause/src/pause_sc_proxy.rs +++ b/contracts/examples/proxy-pause/src/pause_sc_proxy.rs @@ -1,12 +1,3 @@ -// 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 PausableProxy;