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

proxy pause sc migration to new proxy and unified syntax #1515

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
99 changes: 99 additions & 0 deletions contracts/examples/proxy-pause/src/pause_sc_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.
mihaicalinluca marked this conversation as resolved.
Show resolved Hide resolved

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

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

use multiversx_sc::proxy_imports::*;

pub struct PausableProxy;

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

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

pub struct PausableProxyMethods<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> PausableProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
mihaicalinluca marked this conversation as resolved.
Show resolved Hide resolved
self,
) -> TxProxyDeploy<Env, From, Gas, ()> {
self.wrapped_tx
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> PausableProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn upgrade(
self,
) -> TxProxyUpgrade<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_upgrade()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> PausableProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn pause(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("pause")
.original_result()
}

pub fn unpause(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("unpause")
.original_result()
}
}
26 changes: 8 additions & 18 deletions contracts/examples/proxy-pause/src/proxy_pause.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -46,23 +36,26 @@ pub trait PauseProxy {

fn for_each_contract<F>(&self, f: F)
where
F: Fn(pause_proxy::ProxyTo<Self::Api>),
F: Fn(pause_sc_proxy::PausableProxyMethods<TxScEnv<Self::Api>, (), &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) {
Expand All @@ -79,7 +72,4 @@ pub trait PauseProxy {
#[view]
#[storage_mapper("contracts")]
fn contracts(&self) -> SetMapper<ManagedAddress>;

#[proxy]
fn pausable_contract(&self) -> pause_proxy::Proxy<Self::Api>;
}
Loading