diff --git a/framework/base/src/types/interaction/tx_call_deploy.rs b/framework/base/src/types/interaction/tx_call_deploy.rs index de2e943563..c5f948ea32 100644 --- a/framework/base/src/types/interaction/tx_call_deploy.rs +++ b/framework/base/src/types/interaction/tx_call_deploy.rs @@ -9,87 +9,16 @@ use crate::{ use super::{ contract_call_exec::decode_result, Code, ConsNoRet, ConsRet, DeployCall, FromSource, - OriginalResultMarker, RHList, RHListItem, Tx, TxCodeValue, TxEmptyResultHandler, TxEnv, - TxFromSourceValue, TxGas, TxPaymentEgldOnly, TxResultHandler, TxScEnv, + OriginalResultMarker, RHList, RHListExec, RHListItem, Tx, TxCodeValue, TxEmptyResultHandler, + TxEnv, TxFromSourceValue, TxGas, TxPaymentEgldOnly, TxResultHandler, TxScEnv, }; -pub trait RHListItemDeploy: RHListItem +pub struct DeployRawResult where - Env: TxEnv, -{ - fn item_deploy_result( - self, - new_address: &ManagedAddress, - raw_results: &ManagedVec>, - ) -> Self::Returns; -} - -pub trait RHListDeploy: RHList -where - Env: TxEnv, -{ - fn list_deploy_result( - self, - new_address: &ManagedAddress, - raw_results: &ManagedVec>, - ) -> Self::ListReturns; -} - -impl RHListDeploy for () -where - Env: TxEnv, -{ - fn list_deploy_result( - self, - _new_address: &ManagedAddress, - _raw_results: &ManagedVec>, - ) -> Self::ListReturns { - } -} - -impl RHListDeploy for OriginalResultMarker -where - Env: TxEnv, -{ - fn list_deploy_result( - self, - _new_address: &ManagedAddress, - _raw_results: &ManagedVec>, - ) -> Self::ListReturns { - } -} - -impl RHListDeploy for ConsRet -where - Env: TxEnv, - Head: RHListItemDeploy, - Tail: RHListDeploy, -{ - fn list_deploy_result( - self, - new_address: &ManagedAddress, - raw_results: &ManagedVec>, - ) -> Self::ListReturns { - let head_result = self.head.item_deploy_result(new_address, raw_results); - let tail_result = self.tail.list_deploy_result(new_address, raw_results); - (head_result, tail_result) - } -} - -impl RHListDeploy for ConsNoRet -where - Env: TxEnv, - Head: RHListItemDeploy, - Tail: RHListDeploy, + Api: CallTypeApi, { - fn list_deploy_result( - self, - new_address: &ManagedAddress, - raw_results: &ManagedVec>, - ) -> Self::ListReturns { - self.head.item_deploy_result(new_address, raw_results); - self.tail.list_deploy_result(new_address, raw_results) - } + pub new_address: ManagedAddress, + pub raw_results: ManagedVec>, } impl @@ -165,14 +94,18 @@ where Payment: TxPaymentEgldOnly>, Gas: TxGas>, CodeValue: TxCodeValue>, - RH: RHListDeploy>, + RH: RHListExec, TxScEnv>, RH::ListReturns: NestedTupleFlatten, { /// Synchronously deploys a contract. pub fn sync_call(self) -> ::Unpacked { let (new_address, raw_results, result_handler) = self.execute_deploy_raw(); - let tuple_result = result_handler.list_deploy_result(&new_address, &raw_results); + let deploy_raw_result = DeployRawResult { + new_address, + raw_results, + }; + let tuple_result = result_handler.list_process_result(&deploy_raw_result); tuple_result.flatten_unpack() } } @@ -192,14 +125,18 @@ where Payment: TxPaymentEgldOnly>, Gas: TxGas>, FromSourceValue: TxFromSourceValue>, - RH: RHListDeploy>, + RH: RHListExec, TxScEnv>, RH::ListReturns: NestedTupleFlatten, { /// Synchronously deploys a contract from source. pub fn sync_call(self) -> ::Unpacked { let (new_address, raw_results, result_handler) = self.execute_deploy_from_source_raw(); - let tuple_result = result_handler.list_deploy_result(&new_address, &raw_results); + let deploy_raw_result = DeployRawResult { + new_address, + raw_results, + }; + let tuple_result = result_handler.list_process_result(&deploy_raw_result); tuple_result.flatten_unpack() } } diff --git a/framework/base/src/types/interaction/tx_call_sync.rs b/framework/base/src/types/interaction/tx_call_sync.rs index 61c73a7b0c..9e45d09875 100644 --- a/framework/base/src/types/interaction/tx_call_sync.rs +++ b/framework/base/src/types/interaction/tx_call_sync.rs @@ -9,81 +9,13 @@ use crate::{ use super::{ contract_call_exec::decode_result, BackTransfers, ConsNoRet, ConsRet, OriginalResultMarker, - RHList, RHListItem, Tx, TxDataFunctionCall, TxEnv, TxGas, TxPayment, TxScEnv, TxToSpecified, + RHList, RHListExec, RHListItem, Tx, TxDataFunctionCall, TxEnv, TxGas, TxPayment, TxScEnv, + TxToSpecified, }; -pub trait RHListItemSync: RHListItem +pub struct SyncCallRawResult(pub ManagedVec>) where - Env: TxEnv, -{ - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns; -} - -pub trait RHListSync: RHList -where - Env: TxEnv, -{ - fn list_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::ListReturns; -} - -impl RHListSync for () -where - Env: TxEnv, -{ - fn list_sync_call_result( - self, - _raw_results: &ManagedVec>, - ) -> Self::ListReturns { - } -} - -impl RHListSync for OriginalResultMarker -where - Env: TxEnv, -{ - fn list_sync_call_result( - self, - _raw_results: &ManagedVec>, - ) -> Self::ListReturns { - } -} - -impl RHListSync for ConsRet -where - Env: TxEnv, - Head: RHListItemSync, - Tail: RHListSync, -{ - fn list_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::ListReturns { - let head_result = self.head.item_sync_call_result(raw_results); - let tail_result = self.tail.list_sync_call_result(raw_results); - (head_result, tail_result) - } -} - -impl RHListSync for ConsNoRet -where - Env: TxEnv, - Head: RHListItemSync, - Tail: RHListSync, -{ - fn list_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::ListReturns { - self.head.item_sync_call_result(raw_results); - self.tail.list_sync_call_result(raw_results) - } -} + Api: CallTypeApi; impl Tx, (), To, Payment, Gas, FC, RH> where @@ -92,7 +24,7 @@ where Payment: TxPayment>, Gas: TxGas>, FC: TxDataFunctionCall>, - RH: RHListSync>, + RH: RHListExec, TxScEnv>, RH::ListReturns: NestedTupleFlatten, { fn execute_sync_call_raw(self) -> (ManagedVec>, RH) { @@ -121,8 +53,8 @@ where pub fn sync_call(self) -> ::Unpacked { let (raw_result, result_handler) = self.execute_sync_call_raw(); - - let tuple_result = result_handler.list_sync_call_result(&raw_result); + let sync_raw_result = SyncCallRawResult(raw_result); + let tuple_result = result_handler.list_process_result(&sync_raw_result); tuple_result.flatten_unpack() } } diff --git a/framework/base/src/types/interaction/tx_rh_list.rs b/framework/base/src/types/interaction/tx_rh_list.rs index 2cf4743ef2..4e0bb4327c 100644 --- a/framework/base/src/types/interaction/tx_rh_list.rs +++ b/framework/base/src/types/interaction/tx_rh_list.rs @@ -4,6 +4,7 @@ mod returns_new_address; mod returns_raw; mod returns_similar; mod tx_rh_list_cons; +mod tx_rh_list_exec; mod tx_rh_list_item; mod with_result_exact; mod with_result_new_address; @@ -16,6 +17,7 @@ pub use returns_new_address::*; pub use returns_raw::*; pub use returns_similar::*; pub use tx_rh_list_cons::*; +pub use tx_rh_list_exec::*; pub use tx_rh_list_item::*; pub use with_result_new_address::*; pub use with_result_similar::*; diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_bt.rs b/framework/base/src/types/interaction/tx_rh_list/returns_bt.rs index 1f1be042e5..ceda028bcd 100644 --- a/framework/base/src/types/interaction/tx_rh_list/returns_bt.rs +++ b/framework/base/src/types/interaction/tx_rh_list/returns_bt.rs @@ -1,12 +1,9 @@ use crate::{ contract_base::BlockchainWrapper, - types::{ - interaction::tx_call_deploy::RHListItemDeploy, BackTransfers, ManagedAddress, - ManagedBuffer, ManagedVec, RHListItemSync, TxEnv, - }, + types::{BackTransfers, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv}, }; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct ReturnsBackTransfers; @@ -17,27 +14,11 @@ where type Returns = BackTransfers; } -impl RHListItemSync for ReturnsBackTransfers +impl RHListItemExec for ReturnsBackTransfers where Env: TxEnv, { - fn item_sync_call_result( - self, - _raw_results: &ManagedVec>, - ) -> Self::Returns { - BlockchainWrapper::::new().get_back_transfers() - } -} - -impl RHListItemDeploy for ReturnsBackTransfers -where - Env: TxEnv, -{ - fn item_deploy_result( - self, - _new_address: &ManagedAddress, - _raw_results: &ManagedVec>, - ) -> Self::Returns { + fn item_process_result(self, _raw_result: &RawResult) -> Self::Returns { BlockchainWrapper::::new().get_back_transfers() } } diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_exact.rs b/framework/base/src/types/interaction/tx_rh_list/returns_exact.rs index edbc82144d..87a25f0fb2 100644 --- a/framework/base/src/types/interaction/tx_rh_list/returns_exact.rs +++ b/framework/base/src/types/interaction/tx_rh_list/returns_exact.rs @@ -1,11 +1,11 @@ use multiversx_sc_codec::TopDecodeMulti; -use crate::types::{ - interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, RHListItemSync, - TxEnv, +use crate::{ + proxy_imports::SyncCallRawResult, + types::{interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, TxEnv}, }; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct ReturnsExact; @@ -16,15 +16,12 @@ where type Returns = Original; } -impl RHListItemSync for ReturnsExact +impl RHListItemExec, Env, Original> for ReturnsExact where Env: TxEnv, Original: TopDecodeMulti, { - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns { - decode_result::(raw_results.clone()) + fn item_process_result(self, raw_result: &SyncCallRawResult) -> Original { + decode_result::(raw_result.0.clone()) } } diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_new_address.rs b/framework/base/src/types/interaction/tx_rh_list/returns_new_address.rs index c9c271e2dd..2b1b9ccad4 100644 --- a/framework/base/src/types/interaction/tx_rh_list/returns_new_address.rs +++ b/framework/base/src/types/interaction/tx_rh_list/returns_new_address.rs @@ -1,8 +1,6 @@ -use crate::types::{ - interaction::tx_call_deploy::RHListItemDeploy, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv, -}; +use crate::types::{DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv}; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct ReturnsNewAddress; @@ -13,15 +11,11 @@ where type Returns = ManagedAddress; } -impl RHListItemDeploy for ReturnsNewAddress +impl RHListItemExec, Env, Original> for ReturnsNewAddress where Env: TxEnv, { - fn item_deploy_result( - self, - new_address: &ManagedAddress, - _raw_results: &ManagedVec>, - ) -> Self::Returns { - new_address.clone() + fn item_process_result(self, raw_result: &DeployRawResult) -> Self::Returns { + raw_result.new_address.clone() } } diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_raw.rs b/framework/base/src/types/interaction/tx_rh_list/returns_raw.rs index 5f709c04a6..d1b501d77c 100644 --- a/framework/base/src/types/interaction/tx_rh_list/returns_raw.rs +++ b/framework/base/src/types/interaction/tx_rh_list/returns_raw.rs @@ -1,9 +1,9 @@ -use crate::types::{ - interaction::tx_call_deploy::RHListItemDeploy, ManagedAddress, ManagedBuffer, ManagedVec, - RHListItemSync, TxEnv, +use crate::{ + proxy_imports::SyncCallRawResult, + types::{DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv}, }; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct ReturnsRaw; @@ -14,27 +14,20 @@ where type Returns = ManagedVec>; } -impl RHListItemSync for ReturnsRaw +impl RHListItemExec, Env, Original> for ReturnsRaw where Env: TxEnv, { - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns { - raw_results.clone() + fn item_process_result(self, raw_result: &SyncCallRawResult) -> Self::Returns { + raw_result.0.clone() } } -impl RHListItemDeploy for ReturnsRaw +impl RHListItemExec, Env, Original> for ReturnsRaw where Env: TxEnv, { - fn item_deploy_result( - self, - _new_address: &ManagedAddress, - raw_results: &ManagedVec>, - ) -> Self::Returns { - raw_results.clone() + fn item_process_result(self, raw_result: &DeployRawResult) -> Self::Returns { + raw_result.raw_results.clone() } } diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_similar.rs b/framework/base/src/types/interaction/tx_rh_list/returns_similar.rs index 1233a9bae0..adfb2f3bdb 100644 --- a/framework/base/src/types/interaction/tx_rh_list/returns_similar.rs +++ b/framework/base/src/types/interaction/tx_rh_list/returns_similar.rs @@ -3,11 +3,11 @@ use core::marker::PhantomData; use multiversx_sc_codec::{CodecFrom, TopEncodeMulti}; use crate::types::{ - interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, RHListItemSync, + interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, SyncCallRawResult, TxEnv, }; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct ReturnsSimilar { _phantom: PhantomData, @@ -36,16 +36,14 @@ where type Returns = T; } -impl RHListItemSync for ReturnsSimilar +impl RHListItemExec, Env, Original> + for ReturnsSimilar where Env: TxEnv, Original: TopEncodeMulti, T: CodecFrom, { - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns { - decode_result::(raw_results.clone()) + fn item_process_result(self, raw_result: &SyncCallRawResult) -> Self::Returns { + decode_result::(raw_result.0.clone()) } } diff --git a/framework/base/src/types/interaction/tx_rh_list/tx_rh_list_exec.rs b/framework/base/src/types/interaction/tx_rh_list/tx_rh_list_exec.rs new file mode 100644 index 0000000000..cc39d08561 --- /dev/null +++ b/framework/base/src/types/interaction/tx_rh_list/tx_rh_list_exec.rs @@ -0,0 +1,68 @@ +use crate::{proxy_imports::OriginalResultMarker, types::TxEnv}; + +use super::{ConsNoRet, ConsRet, RHList, RHListItem}; + +/// Indicates how result processing will undergo for one specific result handler. +/// +/// Note that the `ResultType` needs to be the first generic type in the definition, +/// so we can add new implementations of the same result handlers for new raw result types in subsequent crates. +pub trait RHListItemExec: RHListItem +where + Env: TxEnv, +{ + fn item_process_result(self, raw_result: &RawResult) -> Self::Returns; +} + +impl RHListItemExec for () +where + Env: TxEnv, +{ + fn item_process_result(self, _raw_result: &RawResult) -> Self::Returns {} +} + +/// Indicates how result processing will undergo for an ensemble of result handlers. +pub trait RHListExec: RHList +where + Env: TxEnv, +{ + fn list_process_result(self, raw_result: &RawResult) -> Self::ListReturns; +} + +impl RHListExec for () +where + Env: TxEnv, +{ + fn list_process_result(self, _raw_result: &RawResult) -> Self::ListReturns {} +} + +impl RHListExec for OriginalResultMarker +where + Env: TxEnv, +{ + fn list_process_result(self, _raw_result: &RawResult) -> Self::ListReturns {} +} + +impl RHListExec for ConsRet +where + Env: TxEnv, + Head: RHListItemExec, + Tail: RHListExec, +{ + fn list_process_result(self, raw_result: &RawResult) -> Self::ListReturns { + let head_result = self.head.item_process_result(raw_result); + let tail_result = self.tail.list_process_result(raw_result); + (head_result, tail_result) + } +} + +impl RHListExec for ConsNoRet +where + Env: TxEnv, + Head: RHListItemExec, + Tail: RHListExec, +{ + fn list_process_result(self, raw_result: &RawResult) -> Self::ListReturns { + self.head.item_process_result(raw_result); + self.tail.list_process_result(raw_result) + } +} diff --git a/framework/base/src/types/interaction/tx_rh_list/with_result_exact.rs b/framework/base/src/types/interaction/tx_rh_list/with_result_exact.rs index f3319c5a07..d3045dca25 100644 --- a/framework/base/src/types/interaction/tx_rh_list/with_result_exact.rs +++ b/framework/base/src/types/interaction/tx_rh_list/with_result_exact.rs @@ -3,11 +3,11 @@ use core::marker::PhantomData; use multiversx_sc_codec::TopDecodeMulti; use crate::types::{ - interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, RHListItemSync, + interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, SyncCallRawResult, TxEnv, }; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct WithResultExact where @@ -37,17 +37,15 @@ where type Returns = (); } -impl RHListItemSync for WithResultExact +impl RHListItemExec, Env, Original> + for WithResultExact where Env: TxEnv, Original: TopDecodeMulti, F: FnOnce(Original), { - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns { - let t = decode_result::(raw_results.clone()); + fn item_process_result(self, raw_result: &SyncCallRawResult) -> Self::Returns { + let t = decode_result::(raw_result.0.clone()); (self.f)(t) } } diff --git a/framework/base/src/types/interaction/tx_rh_list/with_result_new_address.rs b/framework/base/src/types/interaction/tx_rh_list/with_result_new_address.rs index 64b2894f1f..5dad91eef6 100644 --- a/framework/base/src/types/interaction/tx_rh_list/with_result_new_address.rs +++ b/framework/base/src/types/interaction/tx_rh_list/with_result_new_address.rs @@ -1,10 +1,8 @@ use core::marker::PhantomData; -use crate::types::{ - interaction::tx_call_deploy::RHListItemDeploy, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv, -}; +use crate::types::{DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, TxEnv}; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct WithResultNewAddress where @@ -36,16 +34,13 @@ where type Returns = (); } -impl RHListItemDeploy for WithResultNewAddress +impl RHListItemExec, Env, Original> + for WithResultNewAddress where Env: TxEnv, F: FnOnce(&ManagedAddress), { - fn item_deploy_result( - self, - new_address: &ManagedAddress, - _raw_results: &ManagedVec>, - ) -> Self::Returns { - (self.f)(new_address); + fn item_process_result(self, raw_result: &DeployRawResult) -> Self::Returns { + (self.f)(&raw_result.new_address); } } diff --git a/framework/base/src/types/interaction/tx_rh_list/with_result_raw.rs b/framework/base/src/types/interaction/tx_rh_list/with_result_raw.rs index 8f288604be..35b4053d2a 100644 --- a/framework/base/src/types/interaction/tx_rh_list/with_result_raw.rs +++ b/framework/base/src/types/interaction/tx_rh_list/with_result_raw.rs @@ -1,8 +1,8 @@ use core::marker::PhantomData; -use crate::types::{ManagedBuffer, ManagedVec, RHListItemSync, TxEnv}; +use crate::types::{ManagedBuffer, ManagedVec, SyncCallRawResult, TxEnv}; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct WithResultRaw where @@ -34,15 +34,13 @@ where type Returns = (); } -impl RHListItemSync for WithResultRaw +impl RHListItemExec, Env, Original> + for WithResultRaw where Env: TxEnv, F: FnOnce(&ManagedVec>), { - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns { - (self.f)(raw_results) + fn item_process_result(self, raw_result: &SyncCallRawResult) -> Self::Returns { + (self.f)(&raw_result.0) } } diff --git a/framework/base/src/types/interaction/tx_rh_list/with_result_similar.rs b/framework/base/src/types/interaction/tx_rh_list/with_result_similar.rs index c9fd9173b2..d2af475447 100644 --- a/framework/base/src/types/interaction/tx_rh_list/with_result_similar.rs +++ b/framework/base/src/types/interaction/tx_rh_list/with_result_similar.rs @@ -3,11 +3,11 @@ use core::marker::PhantomData; use multiversx_sc_codec::{CodecFrom, TopEncodeMulti}; use crate::types::{ - interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, RHListItemSync, + interaction::contract_call_exec::decode_result, ManagedBuffer, ManagedVec, SyncCallRawResult, TxEnv, }; -use super::RHListItem; +use super::{RHListItem, RHListItemExec}; pub struct WithResultSimilar where @@ -39,18 +39,16 @@ where type Returns = (); } -impl RHListItemSync for WithResultSimilar +impl RHListItemExec, Env, Original> + for WithResultSimilar where Env: TxEnv, Original: TopEncodeMulti, T: CodecFrom, F: FnOnce(T), { - fn item_sync_call_result( - self, - raw_results: &ManagedVec>, - ) -> Self::Returns { - let t = decode_result::(raw_results.clone()); + fn item_process_result(self, raw_result: &SyncCallRawResult) -> Self::Returns { + let t = decode_result::(raw_result.0.clone()); (self.f)(t) } } diff --git a/framework/base/src/types/interaction/tx_to/tx_to_self.rs b/framework/base/src/types/interaction/tx_to/tx_to_self.rs index a4adfaa429..87e068ae6f 100644 --- a/framework/base/src/types/interaction/tx_to/tx_to_self.rs +++ b/framework/base/src/types/interaction/tx_to/tx_to_self.rs @@ -31,7 +31,8 @@ where where F: FnOnce(&ManagedAddress) -> R, { - let sc_address_handle: Api::ManagedBufferHandle = use_raw_handle(const_handles::ADDRESS_CALLER); + let sc_address_handle: Api::ManagedBufferHandle = + use_raw_handle(const_handles::ADDRESS_CALLER); Api::blockchain_api_impl().load_sc_address_managed(sc_address_handle.clone()); f(&ManagedAddress::from_handle(sc_address_handle)) } diff --git a/framework/scenario/src/facade/world_tx.rs b/framework/scenario/src/facade/world_tx.rs index 92f842cf55..4a6fd86317 100644 --- a/framework/scenario/src/facade/world_tx.rs +++ b/framework/scenario/src/facade/world_tx.rs @@ -6,14 +6,11 @@ mod scenario_env_deploy; mod scenario_env_exec; mod scenario_env_query; pub mod scenario_env_util; -mod scenario_rh_list; -mod scenario_rh_list_item; +mod scenario_rh_impl; mod with_tx_raw_response; pub use expr::*; pub use scenario_env::*; pub use scenario_env_exec::ScenarioEnvExec; pub use scenario_env_query::ScenarioEnvQuery; -pub use scenario_rh_list::*; -pub use scenario_rh_list_item::*; pub use with_tx_raw_response::WithRawTxResponse; diff --git a/framework/scenario/src/facade/world_tx/scenario_env_deploy.rs b/framework/scenario/src/facade/world_tx/scenario_env_deploy.rs index d9317a094c..fadd24d78d 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_deploy.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_deploy.rs @@ -4,7 +4,7 @@ use multiversx_chain_scenario_format::serde_raw::ValueSubTree; use multiversx_sc::{ tuple_util::NestedTupleFlatten, types::{ - AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, RHListSync, + AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, RHListExec, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, @@ -16,7 +16,7 @@ use crate::{ ScenarioEnvExec, ScenarioTxEnv, ScenarioTxRun, ScenarioWorld, }; -use super::{scenario_env_util::*, RHListScenario, ScenarioTxEnvData}; +use super::{scenario_env_util::*, ScenarioTxEnvData}; impl<'w, From, Payment, Gas, CodeValue, RH> ScenarioTxRun for Tx< @@ -33,7 +33,7 @@ where Payment: TxPayment>, Gas: TxGas>, CodeValue: TxCodeValue>, - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { type Returns = ::Unpacked; @@ -53,7 +53,7 @@ impl ScenarioWorld { Payment: TxPayment, Gas: TxGas, CodeValue: TxCodeValue, - RH: RHListScenario, + RH: RHListExec, F: FnOnce( TxBaseWithEnv, ) -> Tx< diff --git a/framework/scenario/src/facade/world_tx/scenario_env_exec.rs b/framework/scenario/src/facade/world_tx/scenario_env_exec.rs index 3758673006..e19c515c0b 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_exec.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_exec.rs @@ -4,7 +4,7 @@ use multiversx_chain_scenario_format::serde_raw::ValueSubTree; use multiversx_sc::{ tuple_util::NestedTupleFlatten, types::{ - AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, RHListSync, + AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, RHListExec, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, @@ -16,7 +16,7 @@ use crate::{ ScenarioTxEnv, ScenarioTxRun, ScenarioWorld, }; -use super::{scenario_env_util::*, RHListScenario, ScenarioTxEnvData}; +use super::{scenario_env_util::*, ScenarioTxEnvData}; /// Environment for executing transactions. pub struct ScenarioEnvExec<'w> { @@ -49,7 +49,7 @@ where To: TxToSpecified>, Payment: TxPayment>, Gas: TxGas>, - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { type Returns = ::Unpacked; @@ -81,7 +81,7 @@ impl ScenarioWorld { To: TxToSpecified, Payment: TxPayment, Gas: TxGas, - RH: RHListScenario, + RH: RHListExec, F: FnOnce( TxBaseWithEnv, ) diff --git a/framework/scenario/src/facade/world_tx/scenario_env_query.rs b/framework/scenario/src/facade/world_tx/scenario_env_query.rs index e7d73ec729..993b4d9636 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_query.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_query.rs @@ -3,14 +3,14 @@ use std::path::PathBuf; use multiversx_sc::{ tuple_util::NestedTupleFlatten, types::{ - AnnotatedValue, FunctionCall, ManagedAddress, Tx, TxBaseWithEnv, TxEnv, TxFromSpecified, - TxGas, TxPayment, TxToSpecified, + AnnotatedValue, FunctionCall, ManagedAddress, RHListExec, Tx, TxBaseWithEnv, TxEnv, + TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, }; use crate::{ - api::StaticApi, scenario_model::TxResponse, RHListScenario, ScenarioTxEnv, ScenarioTxEnvData, - ScenarioTxRun, ScenarioWorld, + api::StaticApi, scenario_model::TxResponse, ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, + ScenarioWorld, }; use super::scenario_env_util::*; @@ -42,7 +42,7 @@ impl<'w, To, RH> ScenarioTxRun for Tx, (), To, (), (), FunctionCall, RH> where To: TxToSpecified>, - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { type Returns = ::Unpacked; @@ -64,7 +64,7 @@ impl ScenarioWorld { pub fn chain_query(&mut self, f: F) -> &mut Self where To: TxToSpecified, - RH: RHListScenario, + RH: RHListExec, F: FnOnce( TxBaseWithEnv, ) -> Tx, RH>, diff --git a/framework/scenario/src/facade/world_tx/scenario_env_util.rs b/framework/scenario/src/facade/world_tx/scenario_env_util.rs index 2e75fa3c5d..eca9bc84ed 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_util.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_util.rs @@ -2,7 +2,7 @@ use multiversx_chain_scenario_format::serde_raw::ValueSubTree; use multiversx_sc::{ tuple_util::NestedTupleFlatten, types::{ - AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, RHListSync, + AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, RHListExec, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, @@ -14,7 +14,7 @@ use crate::{ AddressValue, BigUintValue, BytesValue, ScCallStep, ScDeployStep, ScQueryStep, TransferStep, TxResponse, }, - RHListScenario, ScenarioEnvExec, ScenarioWorld, + ScenarioEnvExec, ScenarioWorld, }; pub fn address_annotated(env: &Env, from: Addr) -> AddressValue @@ -148,10 +148,10 @@ pub fn process_result( ) -> ::Unpacked where Env: TxEnv, - RH: RHListScenario, + RH: RHListExec, RH::ListReturns: NestedTupleFlatten, { let response = response.expect("step did not return result"); - let tuple_result = result_handler.item_scenario_result(&response); + let tuple_result = result_handler.list_process_result(&response); tuple_result.flatten_unpack() } diff --git a/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs b/framework/scenario/src/facade/world_tx/scenario_rh_impl.rs similarity index 57% rename from framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs rename to framework/scenario/src/facade/world_tx/scenario_rh_impl.rs index 36440e0313..b0161b52b8 100644 --- a/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs +++ b/framework/scenario/src/facade/world_tx/scenario_rh_impl.rs @@ -1,8 +1,8 @@ use multiversx_sc::{ codec::{CodecFrom, TopDecodeMulti, TopEncodeMulti}, types::{ - ManagedAddress, RHList, RHListItem, ReturnsExact, ReturnsNewAddress, ReturnsSimilar, TxEnv, - WithResultNewAddress, WithResultSimilar, + ManagedAddress, RHList, RHListItem, RHListItemExec, ReturnsExact, ReturnsNewAddress, + ReturnsSimilar, TxEnv, WithResultNewAddress, WithResultSimilar, }, }; @@ -13,19 +13,12 @@ use crate::{ use super::ScenarioTxEnvData; -pub trait RHListItemScenario: RHListItem -where - Env: TxEnv, -{ - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns; -} - -impl RHListItemScenario for ReturnsExact +impl RHListItemExec for ReturnsExact where Env: TxEnv, Original: TopDecodeMulti, { - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { + fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns { let response = TypedResponse::::from_raw(tx_response); response .result @@ -33,13 +26,13 @@ where } } -impl RHListItemScenario for ReturnsSimilar +impl RHListItemExec for ReturnsSimilar where Env: TxEnv, Original: TopEncodeMulti, T: CodecFrom, { - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { + fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns { let response = TypedResponse::::from_raw(tx_response); response .result @@ -47,14 +40,14 @@ where } } -impl RHListItemScenario for WithResultSimilar +impl RHListItemExec for WithResultSimilar where Env: TxEnv, Original: TopEncodeMulti, T: CodecFrom, F: FnOnce(T), { - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { + fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns { let response = TypedResponse::::from_raw(tx_response); let value = response .result @@ -63,11 +56,11 @@ where } } -impl RHListItemScenario for ReturnsNewAddress +impl RHListItemExec for ReturnsNewAddress where Env: TxEnv, { - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { + fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns { let new_address = tx_response .new_deployed_address .clone() @@ -77,12 +70,12 @@ where } } -impl RHListItemScenario for WithResultNewAddress +impl RHListItemExec for WithResultNewAddress where Env: TxEnv, F: FnOnce(&ManagedAddress), { - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { + fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns { let new_address = tx_response .new_deployed_address .clone() diff --git a/framework/scenario/src/facade/world_tx/scenario_rh_list.rs b/framework/scenario/src/facade/world_tx/scenario_rh_list.rs deleted file mode 100644 index 4273b83fe7..0000000000 --- a/framework/scenario/src/facade/world_tx/scenario_rh_list.rs +++ /dev/null @@ -1,51 +0,0 @@ -use multiversx_sc::types::{ConsNoRet, ConsRet, OriginalResultMarker, RHList, RHListItem, TxEnv}; - -use crate::scenario_model::TxResponse; - -use super::RHListItemScenario; - -pub trait RHListScenario: RHList -where - Env: TxEnv, -{ - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::ListReturns; -} - -impl RHListScenario for () -where - Env: TxEnv, -{ - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::ListReturns {} -} - -impl RHListScenario for OriginalResultMarker -where - Env: TxEnv, -{ - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::ListReturns {} -} - -impl RHListScenario for ConsRet -where - Env: TxEnv, - Head: RHListItemScenario, - Tail: RHListScenario, -{ - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::ListReturns { - let head_result = self.head.item_scenario_result(tx_response); - let tail_result = self.tail.item_scenario_result(tx_response); - (head_result, tail_result) - } -} - -impl RHListScenario for ConsNoRet -where - Env: TxEnv, - Head: RHListItemScenario, - Tail: RHListScenario, -{ - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::ListReturns { - self.head.item_scenario_result(tx_response); - self.tail.item_scenario_result(tx_response) - } -} diff --git a/framework/scenario/src/facade/world_tx/with_tx_raw_response.rs b/framework/scenario/src/facade/world_tx/with_tx_raw_response.rs index 51f603a47b..512338aab8 100644 --- a/framework/scenario/src/facade/world_tx/with_tx_raw_response.rs +++ b/framework/scenario/src/facade/world_tx/with_tx_raw_response.rs @@ -2,12 +2,12 @@ use core::marker::PhantomData; use multiversx_sc::{ codec::TopDecodeMulti, - types::{RHListItem, TxEnv}, + types::{RHListItem, RHListItemExec, TxEnv}, }; use crate::scenario_model::TxResponse; -use super::{RHListItemScenario, ScenarioTxEnvData}; +use super::ScenarioTxEnvData; /// Wraps a closure that handles a `TxResponse` object. pub struct WithRawTxResponse(pub F) @@ -22,13 +22,13 @@ where type Returns = (); } -impl RHListItemScenario for WithRawTxResponse +impl RHListItemExec for WithRawTxResponse where Env: TxEnv, Original: TopDecodeMulti, F: FnOnce(&TxResponse), { - fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { - (self.0)(tx_response) + fn item_process_result(self, raw_result: &TxResponse) -> Self::Returns { + (self.0)(raw_result) } } diff --git a/framework/snippets/src/itx/interactor_env_deploy.rs b/framework/snippets/src/itx/interactor_env_deploy.rs index ea11ecc338..d907db498e 100644 --- a/framework/snippets/src/itx/interactor_env_deploy.rs +++ b/framework/snippets/src/itx/interactor_env_deploy.rs @@ -6,14 +6,13 @@ use multiversx_sc_scenario::{ tuple_util::NestedTupleFlatten, types::{ AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, - RHListSync, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, + RHListExec, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, }, scenario_env_util::*, scenario_model::{AddressValue, BytesValue, ScCallStep, ScDeployStep, TxResponse}, - RHListScenario, ScenarioEnvExec, ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, - ScenarioWorld, + ScenarioEnvExec, ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, }; use crate::{Interactor, InteractorPrepareAsync}; @@ -22,7 +21,7 @@ use super::InteractorEnvExec; pub struct InteractorDeployStep<'w, RH> where - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { world: &'w mut Interactor, @@ -45,7 +44,7 @@ where Payment: TxPayment>, Gas: TxGas>, CodeValue: TxCodeValue>, - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { type Exec = InteractorDeployStep<'w, RH>; @@ -63,7 +62,7 @@ where impl<'w, RH> InteractorDeployStep<'w, RH> where - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { pub async fn run(self) -> ::Unpacked { @@ -80,7 +79,7 @@ impl Interactor { Payment: TxPayment, Gas: TxGas, CodeValue: TxCodeValue, - RH: RHListScenario, + RH: RHListExec, F: FnOnce( TxBaseWithEnv, ) -> Tx< @@ -111,7 +110,7 @@ impl Interactor { Payment: TxPayment, Gas: TxGas, CodeValue: TxCodeValue, - RH: RHListScenario, + RH: RHListExec, RH::ListReturns: NestedTupleFlatten, F: FnOnce( TxBaseWithEnv, diff --git a/framework/snippets/src/itx/interactor_env_exec.rs b/framework/snippets/src/itx/interactor_env_exec.rs index dc5269e6e9..bc2d9d20da 100644 --- a/framework/snippets/src/itx/interactor_env_exec.rs +++ b/framework/snippets/src/itx/interactor_env_exec.rs @@ -6,13 +6,13 @@ use multiversx_sc_scenario::{ tuple_util::NestedTupleFlatten, types::{ AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, - RHListSync, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, + RHListExec, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, }, scenario_env_util::*, scenario_model::{AddressValue, BytesValue, ScCallStep, ScDeployStep, TxResponse}, - RHListScenario, ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, + ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, }; use crate::{Interactor, InteractorPrepareAsync}; @@ -43,7 +43,7 @@ impl<'w> ScenarioTxEnv for InteractorEnvExec<'w> { pub struct InteractorCallStep<'w, RH> where - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { world: &'w mut Interactor, @@ -58,7 +58,7 @@ where To: TxToSpecified>, Payment: TxPayment>, Gas: TxGas>, - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { type Exec = InteractorCallStep<'w, RH>; @@ -82,7 +82,7 @@ where impl<'w, RH> InteractorCallStep<'w, RH> where - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { pub async fn run(self) -> ::Unpacked { @@ -105,7 +105,7 @@ impl Interactor { To: TxToSpecified, Payment: TxPayment, Gas: TxGas, - RH: RHListScenario, + RH: RHListExec, F: FnOnce( TxBaseWithEnv, ) diff --git a/framework/snippets/src/itx/interactor_env_query.rs b/framework/snippets/src/itx/interactor_env_query.rs index 20e61e571f..1628215992 100644 --- a/framework/snippets/src/itx/interactor_env_query.rs +++ b/framework/snippets/src/itx/interactor_env_query.rs @@ -5,13 +5,13 @@ use multiversx_sc_scenario::{ multiversx_sc::{ tuple_util::NestedTupleFlatten, types::{ - AnnotatedValue, FunctionCall, ManagedAddress, Tx, TxBaseWithEnv, TxEnv, + AnnotatedValue, FunctionCall, ManagedAddress, RHListExec, Tx, TxBaseWithEnv, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, }, scenario_env_util::*, scenario_model::{ScQueryStep, TxResponse}, - RHListScenario, ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, + ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, }; use crate::{Interactor, InteractorPrepareAsync}; @@ -41,7 +41,7 @@ impl<'w> ScenarioTxEnv for InteractorEnvQuery<'w> { pub struct InteractorQueryStep<'w, RH> where - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { world: &'w mut Interactor, @@ -53,7 +53,7 @@ impl<'w, To, RH> InteractorPrepareAsync for Tx, (), To, (), (), FunctionCall, RH> where To: TxToSpecified>, - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { type Exec = InteractorQueryStep<'w, RH>; @@ -70,7 +70,7 @@ where impl<'w, RH> InteractorQueryStep<'w, RH> where - RH: RHListScenario>, + RH: RHListExec>, RH::ListReturns: NestedTupleFlatten, { pub async fn run(self) -> ::Unpacked { @@ -90,7 +90,7 @@ impl Interactor { pub async fn chain_query(&mut self, f: F) -> &mut Self where To: TxToSpecified, - RH: RHListScenario, + RH: RHListExec, F: FnOnce( TxBaseWithEnv, ) -> Tx, RH>, diff --git a/framework/snippets/src/itx/interactor_env_transf.rs b/framework/snippets/src/itx/interactor_env_transf.rs index 993b2b04d6..19a161b18f 100644 --- a/framework/snippets/src/itx/interactor_env_transf.rs +++ b/framework/snippets/src/itx/interactor_env_transf.rs @@ -5,8 +5,8 @@ use multiversx_sc_scenario::{ multiversx_sc::{ tuple_util::NestedTupleFlatten, types::{ - AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, - RHListSync, Tx, TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, + AnnotatedValue, Code, DeployCall, FunctionCall, ManagedAddress, ManagedBuffer, Tx, + TxBaseWithEnv, TxCodeSource, TxCodeSourceSpecified, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified, }, }, @@ -14,7 +14,7 @@ use multiversx_sc_scenario::{ scenario_model::{ AddressValue, BytesValue, ScCallStep, ScDeployStep, TransferStep, TxResponse, }, - RHListScenario, ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, + ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld, }; use crate::{Interactor, InteractorEnvExec, InteractorPrepareAsync};