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

contracts migration to new proxies and unified syntax #1522

Merged
merged 19 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e8c3c3f
migration to unified syntax
mihaicalinluca Mar 27, 2024
e626ba6
proxy pause sc migration to new proxy and unified syntax
mihaicalinluca Mar 27, 2024
c924c49
encode error from basic features migration to new proxy and unified s…
mihaicalinluca Mar 27, 2024
c4627e7
parent child migration and new proxy
mihaicalinluca Mar 28, 2024
1852432
promises-features migration to new proxy
mihaicalinluca Mar 28, 2024
c4ae976
fix after review
mihaicalinluca Mar 28, 2024
ccaa7ab
proxy test first new proxy and migration to unified
mihaicalinluca Mar 28, 2024
9ecb3ec
new proxy and migration for recursive caller
mihaicalinluca Mar 28, 2024
3bb6cec
proxy test first fix
andrei-marinica Mar 28, 2024
9fd7383
removed init and upgrade from builtin proxy functions
mihaicalinluca Mar 28, 2024
5604d75
Merge pull request #1519 from multiversx/proxy-test-first
mihaicalinluca Mar 28, 2024
81aae14
Merge pull request #1514 from multiversx/builtin-func-sc
mihaicalinluca Mar 28, 2024
2665c3a
removed init and upgrade from proxy
mihaicalinluca Mar 28, 2024
25fd2ae
removed encode error proxy
mihaicalinluca Mar 28, 2024
a320dca
fix after review
mihaicalinluca Mar 28, 2024
d02b4a4
Merge pull request #1516 from multiversx/encode-error-basic-features
mihaicalinluca Mar 28, 2024
e3f758a
removed generated tag and allows
mihaicalinluca Mar 29, 2024
30e0665
Merge pull request #1515 from multiversx/proxy-pause-sc
mihaicalinluca Mar 29, 2024
3ee9e95
Merge pull request #1517 from multiversx/composability-migration
mihaicalinluca Mar 29, 2024
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
55 changes: 55 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,55 @@
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, 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>;
}
25 changes: 2 additions & 23 deletions contracts/feature-tests/basic-features/src/codec_err_test.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
multiversx_sc::imports!();
use crate::types::CodecErrorTestType;

mod encode_err_proxy {
multiversx_sc::imports!();
use crate::types::CodecErrorTestType;

#[multiversx_sc::proxy]
pub trait EncodeErrorProxy {
#[init]
fn init(&self, error_arg: CodecErrorTestType);

#[endpoint]
fn encode_error_method(&self, error_arg: CodecErrorTestType);
}
}

/// Test various serialization errors.
#[multiversx_sc::module]
pub trait CodecErrorTest {
Expand Down Expand Up @@ -62,24 +48,17 @@ pub trait CodecErrorTest {
fn codec_err_event_data(&self) {
self.event_err_data(CodecErrorTestType);
}

#[proxy]
fn encode_err_proxy(&self) -> encode_err_proxy::Proxy<Self::Api>;

/// Never actually calls any deploy/upgrade, so it is appropriate in this contract.
/// It just covers contract init serialization errors.
#[endpoint]
fn codec_err_contract_init(&self) {
let _ = self.encode_err_proxy().init(CodecErrorTestType);
let _ = self.tx().raw_deploy().argument(&CodecErrorTestType);
}

/// Never actually calls any async/sync call, so it is appropriate in this contract.
/// It just covers contract call serialization errors.
#[endpoint]
fn codec_err_contract_call(&self) {
let _ = self
.encode_err_proxy()
.contract(ManagedAddress::zero())
.encode_error_method(CodecErrorTestType);
let _ = self.tx().raw_call().argument(&CodecErrorTestType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ multiversx_sc::imports!();
/// Test contract for investigating async calls.
#[multiversx_sc::contract]
pub trait BuiltinFuncFeatures {
#[proxy]
fn builtin_func_proxy(&self, to: ManagedAddress) -> builtin_func_proxy::Proxy<Self::Api>;

#[init]
fn init(&self) {}

#[endpoint]
fn call_set_user_name(&self, address: ManagedAddress, name: ManagedBuffer) {
self.builtin_func_proxy(address)
.set_user_name(&name)
self.tx()
.to(&address)
.typed(builtin_func_proxy::UserBuiltinProxy)
.set_user_name(name)
.async_call()
.call_and_exit()
}

#[endpoint]
fn call_delete_user_name(&self, address: ManagedAddress) {
self.builtin_func_proxy(address)
self.tx()
.to(&address)
.typed(builtin_func_proxy::UserBuiltinProxy)
.delete_user_name()
.async_call()
.call_and_exit();
.call_and_exit()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
multiversx_sc::imports!();
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

#[multiversx_sc::derive::proxy]
pub trait UserBuiltin {
#[endpoint(SetUserName)]
fn set_user_name(&self, name: &ManagedBuffer);
////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example where there should be no prefix, but I'll fix it myself later today.

////////////////////////////////////////////////////

#[endpoint(DeleteUserName)]
fn delete_user_name(&self);
#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct UserBuiltinProxy;

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

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

pub struct UserBuiltinProxyMethods<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, To, Gas> UserBuiltinProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn set_user_name<
Arg0: CodecInto<ManagedBuffer<Env::Api>>,
>(
self,
name: Arg0,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("SetUserName")
.argument(&name)
.original_result()
}

pub fn delete_user_name(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("DeleteUserName")
.original_result()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
proxy-paths = ["../parent/src/child_proxy.rs"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 ChildProxy;

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

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

pub struct ChildProxyMethods<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> ChildProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
self,
) -> TxProxyDeploy<Env, From, Gas, ()> {
self.wrapped_tx
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> ChildProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
}

#[rustfmt::skip]
impl<Env, From, To, Gas> ChildProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn issue_wrapped_egld<
Arg0: CodecInto<ManagedBuffer<Env::Api>>,
Arg1: CodecInto<ManagedBuffer<Env::Api>>,
Arg2: CodecInto<BigUint<Env::Api>>,
>(
self,
token_display_name: Arg0,
token_ticker: Arg1,
initial_supply: Arg2,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("issueWrappedEgld")
.argument(&token_display_name)
.argument(&token_ticker)
.argument(&initial_supply)
.original_result()
}

pub fn wrapped_egld_token_identifier(
self,
) -> TxProxyCall<Env, From, To, Gas, TokenIdentifier<Env::Api>> {
self.wrapped_tx
.raw_call()
.function_name("getWrappedEgldTokenIdentifier")
.original_result()
}
}
Loading
Loading