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

Result handlers renamed #1503

Merged
merged 1 commit into from
Mar 26, 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
4 changes: 2 additions & 2 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use basic_interact_state::State;
use clap::Parser;
use multiversx_sc_snippets::{
env_logger,
multiversx_sc::types::{Address, ReturnsNewAddress, ReturnsSimilar},
multiversx_sc::types::{Address, ReturnsNewAddress, ReturnsResultConv},
multiversx_sc_scenario::{
api::StaticApi,
bech32,
Expand Down Expand Up @@ -197,7 +197,7 @@ impl AdderInteract {
.to(self.state.adder().to_address())
.typed(adder_proxy::AdderProxy)
.sum()
.returns(ReturnsSimilar::<BigUint>::new())
.returns(ReturnsResultConv::<BigUint>::new())
.prepare_async()
.run()
.await;
Expand Down
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
@@ -1,5 +1,5 @@
use adder::*;
use multiversx_sc::types::{AddressExpr, ScExpr, WithResultNewAddress, WithResultSimilar};
use multiversx_sc::types::{AddressExpr, ScExpr, WithNewAddress, WithResultConv};
use multiversx_sc_scenario::{api::StaticApi, num_bigint::BigUint, scenario_model::*, *};

const ADDER_PATH_EXPR: &str = "mxsc:output/adder.mxsc.json";
Expand Down Expand Up @@ -30,15 +30,15 @@ fn adder_blackbox_chained() {
.typed(adder_proxy::AdderProxy)
.init(5u32)
.code(MxscExpr("output/adder.mxsc.json"))
.with_result(WithResultNewAddress::new(|new_address| {
.with_result(WithNewAddress::new(|new_address| {
assert_eq!(new_address.to_address(), adder_contract.to_address());
}))
})
.chain_query(|tx| {
tx.to(ScExpr("adder"))
.typed(adder_proxy::AdderProxy)
.sum()
.with_result(WithResultSimilar::new(|value: BigUint| {
.with_result(WithResultConv::new(|value: BigUint| {
assert_eq!(value, BigUint::from(5u32));
}))
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use adder::*;
use multiversx_sc::{
storage::mappers::SingleValue,
types::{AddressExpr, ReturnsSimilar, WithResultNewAddress},
types::{AddressExpr, ReturnsResultConv, WithNewAddress},
};
use multiversx_sc_scenario::{api::StaticApi, num_bigint::BigUint, scenario_model::*, *};

Expand Down Expand Up @@ -38,7 +38,7 @@ fn adder_blackbox_legacy_proxy() {
.typed(adder_proxy::AdderProxy)
.init(5u32)
.code(CODE_EXPR)
.with_result(WithResultNewAddress::new(|new_address| {
.with_result(WithNewAddress::new(|new_address| {
assert_eq!(new_address.to_address(), adder_contract.to_address());
}))
.run();
Expand All @@ -53,7 +53,7 @@ fn adder_blackbox_legacy_proxy() {
let value = world
.query()
.call(adder_contract.sum())
.returns(ReturnsSimilar::<SingleValue<BigUint>>::new())
.returns(ReturnsResultConv::<SingleValue<BigUint>>::new())
.run();
assert_eq!(value.into(), BigUint::from(5u32));

Expand Down
6 changes: 3 additions & 3 deletions contracts/examples/adder/tests/adder_blackbox_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use adder::*;
use multiversx_sc::types::{AddressExpr, ReturnsSimilar, ScExpr, WithResultNewAddress};
use multiversx_sc::types::{AddressExpr, ReturnsResultConv, ScExpr, WithNewAddress};
use multiversx_sc_scenario::{api::StaticApi, num_bigint::BigUint, scenario_model::*, *};

const ADDER_PATH_EXPR: &str = "mxsc:output/adder.mxsc.json";
Expand Down Expand Up @@ -36,7 +36,7 @@ fn adder_blackbox() {
.typed(adder_proxy::AdderProxy)
.init(5u32)
.code(CODE_EXPR)
.with_result(WithResultNewAddress::new(|new_address| {
.with_result(WithNewAddress::new(|new_address| {
assert_eq!(new_address.to_address(), adder_contract.to_address());
}))
.run();
Expand All @@ -46,7 +46,7 @@ fn adder_blackbox() {
.to(SC_ADDER)
.typed(adder_proxy::AdderProxy)
.sum()
.returns(ReturnsSimilar::<BigUint>::new())
.returns(ReturnsResultConv::<BigUint>::new())
.run();
assert_eq!(value, BigUint::from(5u32));

Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/multisig/tests/multisig_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use multiversx_sc::{
test_util::top_encode_to_vec_u8_or_panic,
},
storage::mappers::SingleValue,
types::{Address, AddressExpr, CodeMetadata, FunctionCall, ReturnsExact},
types::{Address, AddressExpr, CodeMetadata, FunctionCall, ReturnsResult},
};
use multiversx_sc_scenario::{
api::StaticApi,
Expand Down Expand Up @@ -131,7 +131,7 @@ impl MultisigTestState {
self.multisig_contract
.propose_add_board_member(board_member_address),
)
.returns(ReturnsExact)
.returns(ReturnsResult)
.run()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait ForwarderRawDeployUpgrade {
.arguments_raw(args.to_arg_buffer())
.with_gas_limit(self.blockchain().get_gas_left())
.returns(ReturnsNewAddress)
.returns(ReturnsRaw)
.returns(ReturnsRawResult)
.sync_call()
.into()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait ForwarderRawSync: super::forwarder_raw_common::ForwarderRawCommon {
.function_name(endpoint_name)
.argument(&args)
.with_gas_limit(half_gas)
.returns(ReturnsRaw)
.returns(ReturnsRawResult)
.sync_call();

self.execute_on_dest_context_result(result);
Expand Down
4 changes: 2 additions & 2 deletions framework/base/src/contract_base/wrappers/send_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
},
codec,
esdt::ESDTSystemSmartContractProxy,
proxy_imports::{ReturnsRaw, ToSelf},
proxy_imports::{ReturnsRawResult, ToSelf},
types::{
BigUint, ContractCall, ContractCallNoPayment, EgldOrEsdtTokenIdentifier, EsdtTokenPayment,
ManagedAddress, ManagedArgBuffer, ManagedBuffer, ManagedType, ManagedVec, TokenIdentifier,
Expand Down Expand Up @@ -390,7 +390,7 @@ where
.raw_call()
.function_name(endpoint_name)
.arguments_raw(arg_buffer)
.returns(ReturnsRaw)
.returns(ReturnsRawResult)
.sync_call()
}

Expand Down
18 changes: 18 additions & 0 deletions framework/base/src/types/interaction/tx_result_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
mod returns_bt;
mod returns_new_address;
mod returns_raw_result;
mod returns_result;
mod returns_result_conv;
mod with_new_address;
mod with_raw_result;
mod with_result;
mod with_result_conv;

pub use returns_bt::*;
pub use returns_new_address::*;
pub use returns_raw_result::*;
pub use returns_result::*;
pub use returns_result_conv::*;
pub use with_new_address::*;
pub use with_result_conv::*;

use super::TxEnv;

pub trait TxResultHandler<Env>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{
contract_base::BlockchainWrapper,
types::{BackTransfers, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv},
types::{
BackTransfers, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem, RHListItemExec, TxEnv,
},
};

use super::{RHListItem, RHListItemExec};

/// Indicates that back-transfers will be returned.
pub struct ReturnsBackTransfers;

impl<Env, Original> RHListItem<Env, Original> for ReturnsBackTransfers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::types::{DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv};

use super::{RHListItem, RHListItemExec};
use crate::types::{
DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem, RHListItemExec, TxEnv,
};

/// Indicates that the newly deployed address will be returned after a deploy.
pub struct ReturnsNewAddress;

impl<Env, Original> RHListItem<Env, Original> for ReturnsNewAddress
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use crate::{
proxy_imports::SyncCallRawResult,
types::{DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv},
use crate::types::{
DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem, RHListItemExec,
SyncCallRawResult, TxEnv,
};

use super::{RHListItem, RHListItemExec};
/// Indicates that the raw result data will be returned.
pub struct ReturnsRawResult;

pub struct ReturnsRaw;

impl<Env, Original> RHListItem<Env, Original> for ReturnsRaw
impl<Env, Original> RHListItem<Env, Original> for ReturnsRawResult
where
Env: TxEnv,
{
type Returns = ManagedVec<Env::Api, ManagedBuffer<Env::Api>>;
}

impl<Env, Original> RHListItemExec<SyncCallRawResult<Env::Api>, Env, Original> for ReturnsRaw
impl<Env, Original> RHListItemExec<SyncCallRawResult<Env::Api>, Env, Original> for ReturnsRawResult
where
Env: TxEnv,
{
Expand All @@ -23,7 +22,7 @@ where
}
}

impl<Env, Original> RHListItemExec<DeployRawResult<Env::Api>, Env, Original> for ReturnsRaw
impl<Env, Original> RHListItemExec<DeployRawResult<Env::Api>, Env, Original> for ReturnsRawResult
where
Env: TxEnv,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ use multiversx_sc_codec::TopDecodeMulti;

use crate::{
proxy_imports::SyncCallRawResult,
types::{interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, TxEnv},
types::{
interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, RHListItem,
RHListItemExec, TxEnv,
},
};

use super::{RHListItem, RHListItemExec};
/// Indicates that result will be returned.
///
/// Value will be decoded according to the type defined in the smart contract.
pub struct ReturnsResult;

pub struct ReturnsExact;

impl<Env, Original> RHListItem<Env, Original> for ReturnsExact
impl<Env, Original> RHListItem<Env, Original> for ReturnsResult
where
Env: TxEnv,
{
type Returns = Original;
}

impl<Env, Original> RHListItemExec<SyncCallRawResult<Env::Api>, Env, Original> for ReturnsExact
impl<Env, Original> RHListItemExec<SyncCallRawResult<Env::Api>, Env, Original> for ReturnsResult
where
Env: TxEnv,
Original: TopDecodeMulti,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@ use core::marker::PhantomData;
use multiversx_sc_codec::{CodecFrom, TopEncodeMulti};

use crate::types::{
interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, SyncCallRawResult,
TxEnv,
interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, RHListItem,
RHListItemExec, SyncCallRawResult, TxEnv,
};

use super::{RHListItem, RHListItemExec};

pub struct ReturnsSimilar<T> {
/// Indicates that result will be returned.
///
/// Value will be converted to type `T`, which should be compatible with the original type.
pub struct ReturnsResultConv<T> {
_phantom: PhantomData<T>,
}

impl<T> Default for ReturnsSimilar<T> {
impl<T> Default for ReturnsResultConv<T> {
fn default() -> Self {
Self {
_phantom: Default::default(),
}
}
}

impl<T> ReturnsSimilar<T> {
impl<T> ReturnsResultConv<T> {
pub fn new() -> Self {
Self::default()
}
}

impl<Env, Original, T> RHListItem<Env, Original> for ReturnsSimilar<T>
impl<Env, Original, T> RHListItem<Env, Original> for ReturnsResultConv<T>
where
Env: TxEnv,
Original: TopEncodeMulti,
Expand All @@ -37,7 +38,7 @@ where
}

impl<Env, Original, T> RHListItemExec<SyncCallRawResult<Env::Api>, Env, Original>
for ReturnsSimilar<T>
for ReturnsResultConv<T>
where
Env: TxEnv,
Original: TopEncodeMulti,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use core::marker::PhantomData;

use crate::types::{DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv};
use crate::types::{
DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem, RHListItemExec, TxEnv,
};

use super::{RHListItem, RHListItemExec};

pub struct WithResultNewAddress<Env, F>
/// Defines a lambda function to be called on the newly deployed address, after a deploy.
pub struct WithNewAddress<Env, F>
where
Env: TxEnv,
F: FnOnce(&ManagedAddress<Env::Api>),
Expand All @@ -13,20 +14,20 @@ where
pub f: F,
}

impl<Env, F> WithResultNewAddress<Env, F>
impl<Env, F> WithNewAddress<Env, F>
where
Env: TxEnv,
F: FnOnce(&ManagedAddress<Env::Api>),
{
pub fn new(f: F) -> Self {
WithResultNewAddress {
WithNewAddress {
_phantom: PhantomData,
f,
}
}
}

impl<Env, F, Original> RHListItem<Env, Original> for WithResultNewAddress<Env, F>
impl<Env, F, Original> RHListItem<Env, Original> for WithNewAddress<Env, F>
where
Env: TxEnv,
F: FnOnce(&ManagedAddress<Env::Api>),
Expand All @@ -35,7 +36,7 @@ where
}

impl<Env, F, Original> RHListItemExec<DeployRawResult<Env::Api>, Env, Original>
for WithResultNewAddress<Env, F>
for WithNewAddress<Env, F>
where
Env: TxEnv,
F: FnOnce(&ManagedAddress<Env::Api>),
Expand Down
Loading
Loading