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

New tx proxy generator #1472

Merged
merged 17 commits into from
Mar 14, 2024
Merged
87 changes: 0 additions & 87 deletions contracts/examples/adder/proxies_struct_interactor_main.rs

This file was deleted.

1 change: 0 additions & 1 deletion contracts/examples/adder/src/adder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use multiversx_sc::imports::*;

pub mod temp_proxy;
pub mod temp_proxy_v2;

/// One of the simplest smart contracts possible,
/// it holds a single variable in storage, which anyone can increment.
Expand Down
80 changes: 46 additions & 34 deletions contracts/examples/adder/src/temp_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,73 +1,85 @@
#![allow(clippy::all)]
////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

use multiversx_sc::api::VMApi;
#![allow(clippy::all)]

multiversx_sc::imports!();
use multiversx_sc::imports::*;

pub struct TxProxy;
pub struct AdderProxy;

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

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

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

impl<Env> TxProxyMethods<Env>
impl<Env, From, Gas> AdderProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init<Arg0: multiversx_sc::codec::CodecInto<BigUint<Env::Api>>>(
pub fn init<Arg0: CodecInto<BigUint<Env::Api>>>(
self,
initial_value: Arg0,
) -> multiversx_sc::types::Tx<Env, (), (), (), (), DeployCall<Env, ()>, OriginalResultMarker<()>>
{
Tx::new_with_env(self.env)
) -> Tx<Env, From, (), (), Gas, DeployCall<Env, ()>, OriginalResultMarker<()>> {
self.wrapped_tx
.raw_deploy()
.argument(&initial_value)
.original_result()
}

}
impl<Env, From, To, Gas> AdderProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn sum(
self,
) -> multiversx_sc::types::Tx<
) -> Tx<
Env,
From,
To,
(),
(),
(),
(),
Gas,
FunctionCall<Env::Api>,
OriginalResultMarker<SingleValueMapper<Env::Api, multiversx_sc::types::BigUint<Env::Api>>>,
OriginalResultMarker<multiversx_sc::types::BigUint<Env::Api>>,
> {
Tx::new_with_env(self.env)
self.wrapped_tx
.raw_call()
.function_name("getSum")
.original_result()
}

//Add desired amount to the storage variable.
pub fn add<Arg0: multiversx_sc::codec::CodecInto<BigUint<Env::Api>>>(
/// Add desired amount to the storage variable.
pub fn add<Arg0: CodecInto<BigUint<Env::Api>>>(
self,
value: Arg0,
) -> multiversx_sc::types::Tx<
Env,
(),
(),
(),
(),
FunctionCall<Env::Api>,
OriginalResultMarker<()>,
> {
Tx::new_with_env(self.env)
) -> Tx<Env, From, To, (), Gas, FunctionCall<Env::Api>, OriginalResultMarker<()>> {
self.wrapped_tx
.raw_call()
.function_name("add")
.argument(&value)
Expand Down
103 changes: 0 additions & 103 deletions contracts/examples/adder/src/temp_proxy_v2.rs

This file was deleted.

6 changes: 3 additions & 3 deletions contracts/examples/adder/tests/adder_blackbox_chained_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn adder_blackbox_chained() {
)
.chain_deploy(|tx| {
tx.from(AddressExpr("owner"))
.typed_v2(temp_proxy_v2::TxProxy)
.typed(temp_proxy::AdderProxy)
.init(5u32)
.code(MxscExpr("output/adder.mxsc.json"))
.with_result(WithResultNewAddress::new(|new_address| {
Expand All @@ -36,7 +36,7 @@ fn adder_blackbox_chained() {
})
.chain_query(|tx| {
tx.to(ScExpr("adder"))
.typed_v2(temp_proxy_v2::TxProxy)
.typed(temp_proxy::AdderProxy)
.sum()
.with_result(WithResultSimilar::new(|value: BigUint| {
assert_eq!(value, BigUint::from(5u32));
Expand All @@ -45,7 +45,7 @@ fn adder_blackbox_chained() {
.chain_call(|tx| {
tx.from(AddressExpr("owner"))
.to(ScExpr("adder"))
.typed_v2(temp_proxy_v2::TxProxy)
.typed(temp_proxy::AdderProxy)
.add(3u32)
.with_result(WithRawTxResponse(|response| {
assert!(response.tx_error.is_success());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn adder_blackbox_legacy_proxy() {
world
.tx()
.from(OWNER)
.typed_v2(temp_proxy_v2::TxProxy)
.typed(temp_proxy::AdderProxy)
.init(5u32)
.code(CODE_EXPR)
.with_result(WithResultNewAddress::new(|new_address| {
Expand Down
Loading
Loading