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 test first migration to unified and new proxy #1519

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 MessageMeProxy;

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

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

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

#[rustfmt::skip]
impl<Env, From, To, Gas> MessageMeProxyMethods<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> MessageMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn message_me<
Arg0: CodecInto<i64>,
Arg1: CodecInto<BigUint<Env::Api>>,
Arg2: CodecInto<Vec<u8>>,
Arg3: CodecInto<ManagedAddress<Env::Api>>,
>(
self,
arg1: Arg0,
arg2: Arg1,
arg3: Arg2,
arg4: Arg3,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("messageMe")
.argument(&arg1)
.argument(&arg2)
.argument(&arg3)
.argument(&arg4)
.original_result()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 PayMeProxy;

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

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

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

pub fn pay_me_with_result<
Arg0: CodecInto<i64>,
>(
self,
arg1: Arg0,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("payMeWithResult")
.argument(&arg1)
.original_result()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,14 @@ multiversx_sc::imports!();

use hex_literal::hex;

pub mod message_me_proxy;
pub mod pay_me_proxy;

static HARDCODED_ADDRESS: [u8; 32] =
hex!("fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe");

mod pay_me_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait PayMe {
#[payable("EGLD")]
#[endpoint(payMe)]
fn pay_me(&self, arg1: i64);

#[payable("EGLD")]
#[endpoint(payMeWithResult)]
fn pay_me_with_result(&self, arg1: i64);
}
}

mod message_me_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait MessageMe {
#[init]
#[payable("EGLD")]
fn init(&self, init_arg: i32) -> i32;

#[endpoint(messageMe)]
fn message_me(&self, arg1: i64, arg2: &BigUint, arg3: Vec<u8>, arg4: &ManagedAddress);
}
}

#[multiversx_sc::contract]
pub trait ProxyTestFirst {
#[proxy]
fn pay_me_proxy(&self) -> pay_me_proxy::Proxy<Self::Api>;

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

#[storage_get("other_contract")]
fn get_other_contract(&self) -> ManagedAddress;

Expand All @@ -62,11 +30,18 @@ pub trait ProxyTestFirst {
#[endpoint(deploySecondContract)]
fn deploy_second_contract(&self, code: ManagedBuffer) -> i32 {
let payment = self.call_value().egld_value();

let (address, init_result) = self
.message_me_proxy()
.tx()
.typed(message_me_proxy::MessageMeProxy)
.init(123)
.with_egld_transfer(payment.clone_value())
.deploy_contract::<i32>(&code, CodeMetadata::UPGRADEABLE);
.code(code)
.code_metadata(CodeMetadata::UPGRADEABLE)
.returns(ReturnsNewAddress)
.returns(ReturnsResult)
.egld(payment)
.sync_call();

self.set_other_contract(&address);
init_result + 1
}
Expand All @@ -90,33 +65,36 @@ pub trait ProxyTestFirst {
fn forward_to_other_contract(&self) {
let payment = self.call_value().egld_value();
let other_contract = self.get_other_contract();
self.pay_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(pay_me_proxy::PayMeProxy)
.pay_me(0x56)
.with_egld_transfer(payment.clone_value())
.egld(payment)
.async_call()
.call_and_exit()
.call_and_exit();
}

#[payable("EGLD")]
#[endpoint(forwardToOtherContractWithCallback)]
fn forward_to_other_contract_with_callback(&self) {
let payment = self.call_value().egld_value();
let other_contract = self.get_other_contract();
self.pay_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(pay_me_proxy::PayMeProxy)
.pay_me_with_result(0x56)
.with_egld_transfer(payment.clone_value())
.egld(payment)
.async_call()
.with_callback(self.callbacks().pay_callback())
.call_and_exit()
.call_and_exit();
}

#[endpoint(messageOtherContract)]
fn message_other_contract(&self) {
let other_contract = self.get_other_contract();
self.message_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(message_me_proxy::MessageMeProxy)
.message_me(
0x01,
&BigUint::from(2u32),
Expand All @@ -130,8 +108,9 @@ pub trait ProxyTestFirst {
#[endpoint(messageOtherContractWithCallback)]
fn message_other_contract_with_callback(&self) {
let other_contract = self.get_other_contract();
self.message_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(message_me_proxy::MessageMeProxy)
.message_me(
0x01,
&BigUint::from(2u32),
Expand Down
Loading