Skip to content

Commit

Permalink
Merge pull request #1806 from multiversx/gateway-refactor-10
Browse files Browse the repository at this point in the history
Generic gateway proxy in interactor environments
  • Loading branch information
andrei-marinica authored Oct 4, 2024
2 parents 16a8588 + 1e465b7 commit 3bbf434
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 95 deletions.
6 changes: 0 additions & 6 deletions framework/snippets/src/interactor_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,3 @@ pub use interactor_exec_step::InteractorExecStep;
pub use interactor_prepare_async::InteractorPrepareAsync;
pub use interactor_query_env::InteractorEnvQuery;
pub use interactor_query_step::InteractorQueryStep;

#[deprecated(since = "0.50.2", note = "Renamed to InteractorExecEnv")]
pub type InteractorExecEnv<'a> = InteractorEnvExec<'a>;

#[deprecated(since = "0.50.2", note = "Renamed to InteractorEnvQuery")]
pub type InteractorQueryEnv<'a> = InteractorEnvQuery<'a>;
22 changes: 12 additions & 10 deletions framework/snippets/src/interactor_tx/interactor_exec_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ use crate::InteractorBase;

use super::{InteractorEnvExec, InteractorExecStep, InteractorPrepareAsync};

impl<'w, From, To, Payment, Gas, RH> InteractorPrepareAsync
for Tx<InteractorEnvExec<'w>, From, To, Payment, Gas, FunctionCall<StaticApi>, RH>
impl<'w, GatewayProxy, From, To, Payment, Gas, RH> InteractorPrepareAsync
for Tx<InteractorEnvExec<'w, GatewayProxy>, From, To, Payment, Gas, FunctionCall<StaticApi>, RH>
where
From: TxFromSpecified<InteractorEnvExec<'w>>,
To: TxToSpecified<InteractorEnvExec<'w>>,
Payment: TxPayment<InteractorEnvExec<'w>>,
Gas: TxGas<InteractorEnvExec<'w>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Payment: TxPayment<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
type Exec = InteractorExecStep<'w, ScCallStep, RH>;
type Exec = InteractorExecStep<'w, GatewayProxy, ScCallStep, RH>;

fn prepare_async(self) -> Self::Exec {
InteractorExecStep {
Expand All @@ -36,9 +37,10 @@ where
}
}

impl<'w, RH> InteractorExecStep<'w, ScCallStep, RH>
impl<'w, GatewayProxy, RH> InteractorExecStep<'w, GatewayProxy, ScCallStep, RH>
where
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
pub async fn run(mut self) -> <RH::ListReturns as NestedTupleFlatten>::Unpacked {
Expand Down
24 changes: 13 additions & 11 deletions framework/snippets/src/interactor_tx/interactor_exec_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ use crate::InteractorBase;

use super::{InteractorEnvExec, InteractorExecStep, InteractorPrepareAsync};

impl<'w, From, Payment, Gas, CodeValue, RH> InteractorPrepareAsync
impl<'w, GatewayProxy, From, Payment, Gas, CodeValue, RH> InteractorPrepareAsync
for Tx<
InteractorEnvExec<'w>,
InteractorEnvExec<'w, GatewayProxy>,
From,
(),
Payment,
Gas,
DeployCall<InteractorEnvExec<'w>, Code<CodeValue>>,
DeployCall<InteractorEnvExec<'w, GatewayProxy>, Code<CodeValue>>,
RH,
>
where
From: TxFromSpecified<InteractorEnvExec<'w>>,
Payment: TxPayment<InteractorEnvExec<'w>>,
Gas: TxGas<InteractorEnvExec<'w>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Payment: TxPayment<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
type Exec = InteractorExecStep<'w, ScDeployStep, RH>;
type Exec = InteractorExecStep<'w, GatewayProxy, ScDeployStep, RH>;

fn prepare_async(self) -> Self::Exec {
InteractorExecStep {
Expand All @@ -43,9 +44,10 @@ where
}
}

impl<'w, RH> InteractorExecStep<'w, ScDeployStep, RH>
impl<'w, GatewayProxy, RH> InteractorExecStep<'w, GatewayProxy, ScDeployStep, RH>
where
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
pub async fn run(mut self) -> <RH::ListReturns as NestedTupleFlatten>::Unpacked {
Expand Down
30 changes: 22 additions & 8 deletions framework/snippets/src/interactor_tx/interactor_exec_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@ use multiversx_sc_scenario::{
ScenarioTxEnv, ScenarioTxEnvData,
};
use multiversx_sdk::gateway::GatewayAsyncService;
use multiversx_sdk_http::GatewayHttpProxy;

use crate::InteractorBase;

impl InteractorBase<GatewayHttpProxy> {
pub fn tx(&mut self) -> TxBaseWithEnv<InteractorEnvExec<'_>> {
impl<GatewayProxy> InteractorBase<GatewayProxy>
where
GatewayProxy: GatewayAsyncService,
{
pub fn tx(&mut self) -> TxBaseWithEnv<InteractorEnvExec<'_, GatewayProxy>> {
let data = self.new_env_data();
let env = InteractorEnvExec { world: self, data };
Tx::new_with_env(env)
}
}

/// Environment for executing transactions.
pub struct InteractorEnvExec<'w> {
pub world: &'w mut InteractorBase<GatewayHttpProxy>,
pub struct InteractorEnvExec<'w, GatewayProxy>
where
GatewayProxy: GatewayAsyncService,
{
pub world: &'w mut InteractorBase<GatewayProxy>,
pub data: ScenarioTxEnvData,
}

impl<'w> TxEnv for InteractorEnvExec<'w> {
impl<'w, GatewayProxy> TxEnv for InteractorEnvExec<'w, GatewayProxy>
where
GatewayProxy: GatewayAsyncService,
{
type Api = StaticApi;

type RHExpect = TxExpect;
Expand All @@ -43,13 +51,19 @@ impl<'w> TxEnv for InteractorEnvExec<'w> {
}
}

impl<'w> ScenarioTxEnv for InteractorEnvExec<'w> {
impl<'w, GatewayProxy> ScenarioTxEnv for InteractorEnvExec<'w, GatewayProxy>
where
GatewayProxy: GatewayAsyncService,
{
fn env_data(&self) -> &ScenarioTxEnvData {
&self.data
}
}

impl<'w> TxEnvWithTxHash for InteractorEnvExec<'w> {
impl<'w, GatewayProxy> TxEnvWithTxHash for InteractorEnvExec<'w, GatewayProxy>
where
GatewayProxy: GatewayAsyncService,
{
fn set_tx_hash(&mut self, tx_hash: H256) {
self.data.set_tx_hash(tx_hash);
}
Expand Down
8 changes: 5 additions & 3 deletions framework/snippets/src/interactor_tx/interactor_exec_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use multiversx_sc_scenario::{
scenario::tx_to_step::StepWrapper,
scenario_model::TxResponse,
};
use multiversx_sdk::gateway::GatewayAsyncService;

use super::InteractorEnvExec;

pub struct InteractorExecStep<'w, Step, RH>
pub struct InteractorExecStep<'w, GatewayProxy, Step, RH>
where
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
pub(crate) step_wrapper: StepWrapper<InteractorEnvExec<'w>, Step, RH>,
pub(crate) step_wrapper: StepWrapper<InteractorEnvExec<'w, GatewayProxy>, Step, RH>,
}
21 changes: 13 additions & 8 deletions framework/snippets/src/interactor_tx/interactor_exec_transf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ use multiversx_sc_scenario::{
scenario::tx_to_step::TxToStep,
scenario_model::TransferStep,
};
use multiversx_sdk::gateway::GatewayAsyncService;

use super::{InteractorEnvExec, InteractorExecStep, InteractorPrepareAsync};

impl<'w, From, To, Payment, Gas> InteractorPrepareAsync
for Tx<InteractorEnvExec<'w>, From, To, Payment, Gas, (), ()>
impl<'w, GatewayProxy, From, To, Payment, Gas> InteractorPrepareAsync
for Tx<InteractorEnvExec<'w, GatewayProxy>, From, To, Payment, Gas, (), ()>
where
From: TxFromSpecified<InteractorEnvExec<'w>>,
To: TxToSpecified<InteractorEnvExec<'w>>,
Payment: TxPayment<InteractorEnvExec<'w>>,
Gas: TxGas<InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Payment: TxPayment<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
{
type Exec = InteractorExecStep<'w, TransferStep, ()>;
type Exec = InteractorExecStep<'w, GatewayProxy, TransferStep, ()>;

fn prepare_async(self) -> Self::Exec {
InteractorExecStep {
Expand All @@ -23,7 +25,10 @@ where
}
}

impl<'w> InteractorExecStep<'w, TransferStep, ()> {
impl<'w, GatewayProxy> InteractorExecStep<'w, GatewayProxy, TransferStep, ()>
where
GatewayProxy: GatewayAsyncService,
{
pub async fn run(self) {
self.step_wrapper
.env
Expand Down
55 changes: 30 additions & 25 deletions framework/snippets/src/interactor_tx/interactor_exec_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ use multiversx_sc_scenario::{
scenario_model::{ScDeployStep, TxResponse},
ScenarioTxEnvData,
};
use multiversx_sdk::gateway::GatewayAsyncService;

use crate::InteractorBase;

use super::{InteractorEnvExec, InteractorExecStep, InteractorPrepareAsync};

impl<'w, From, To, Gas, CodeValue, RH> InteractorPrepareAsync
impl<'w, GatewayProxy, From, To, Gas, CodeValue, RH> InteractorPrepareAsync
for Tx<
InteractorEnvExec<'w>,
InteractorEnvExec<'w, GatewayProxy>,
From,
To,
NotPayable,
Gas,
UpgradeCall<InteractorEnvExec<'w>, Code<CodeValue>>,
UpgradeCall<InteractorEnvExec<'w, GatewayProxy>, Code<CodeValue>>,
RH,
>
where
From: TxFromSpecified<InteractorEnvExec<'w>>,
To: TxToSpecified<InteractorEnvExec<'w>>,
Gas: TxGas<InteractorEnvExec<'w>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
type Exec = InteractorExecStep<'w, ScCallStep, RH>;
type Exec = InteractorExecStep<'w, GatewayProxy, ScCallStep, RH>;

fn prepare_async(self) -> Self::Exec {
InteractorExecStep {
Expand All @@ -43,27 +45,29 @@ where
}
}

impl<'w, From, To, Gas, RH, CodeValue> TxToStep<InteractorEnvExec<'w>, RH>
impl<'w, GatewayProxy, From, To, Gas, RH, CodeValue>
TxToStep<InteractorEnvExec<'w, GatewayProxy>, RH>
for Tx<
InteractorEnvExec<'w>,
InteractorEnvExec<'w, GatewayProxy>,
From,
To,
NotPayable,
Gas,
UpgradeCall<InteractorEnvExec<'w>, Code<CodeValue>>,
UpgradeCall<InteractorEnvExec<'w, GatewayProxy>, Code<CodeValue>>,
RH,
>
where
From: TxFromSpecified<InteractorEnvExec<'w>>,
To: TxToSpecified<InteractorEnvExec<'w>>,
Gas: TxGas<InteractorEnvExec<'w>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
type Step = ScCallStep;

fn tx_to_step(self) -> StepWrapper<InteractorEnvExec<'w>, Self::Step, RH> {
fn tx_to_step(self) -> StepWrapper<InteractorEnvExec<'w, GatewayProxy>, Self::Step, RH> {
let mut step =
tx_to_sc_call_upgrade_step(&self.env, self.from, self.to, self.gas, self.data);
step.expect = Some(self.result_handler.list_tx_expect());
Expand All @@ -76,18 +80,19 @@ where
}
}

pub fn tx_to_sc_call_upgrade_step<'a, 'w: 'a, From, To, Gas, CodeValue>(
env: &'a InteractorEnvExec<'w>,
pub fn tx_to_sc_call_upgrade_step<'a, 'w: 'a, GatewayProxy, From, To, Gas, CodeValue>(
env: &'a InteractorEnvExec<'w, GatewayProxy>,
from: From,
to: To,
gas: Gas,
data: UpgradeCall<InteractorEnvExec<'w>, Code<CodeValue>>,
data: UpgradeCall<InteractorEnvExec<'w, GatewayProxy>, Code<CodeValue>>,
) -> ScCallStep
where
From: TxFromSpecified<InteractorEnvExec<'w>>,
To: TxToSpecified<InteractorEnvExec<'w>>,
Gas: TxGas<InteractorEnvExec<'w>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w>>,
GatewayProxy: GatewayAsyncService,
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
CodeValue: TxCodeValue<InteractorEnvExec<'w, GatewayProxy>>,
{
let mut step = ScCallStep::new()
.from(address_annotated(env, &from))
Expand Down
18 changes: 10 additions & 8 deletions framework/snippets/src/interactor_tx/interactor_query_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ use crate::InteractorBase;

use super::{InteractorEnvQuery, InteractorPrepareAsync, InteractorQueryStep};

impl<'w, To, Payment, RH> InteractorPrepareAsync
for Tx<InteractorEnvQuery<'w>, (), To, Payment, (), FunctionCall<StaticApi>, RH>
impl<'w, GatewayProxy, To, Payment, RH> InteractorPrepareAsync
for Tx<InteractorEnvQuery<'w, GatewayProxy>, (), To, Payment, (), FunctionCall<StaticApi>, RH>
where
To: TxToSpecified<InteractorEnvQuery<'w>>,
Payment: TxNoPayment<InteractorEnvQuery<'w>>,
RH: RHListExec<TxResponse, InteractorEnvQuery<'w>>,
GatewayProxy: GatewayAsyncService,
To: TxToSpecified<InteractorEnvQuery<'w, GatewayProxy>>,
Payment: TxNoPayment<InteractorEnvQuery<'w, GatewayProxy>>,
RH: RHListExec<TxResponse, InteractorEnvQuery<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
type Exec = InteractorQueryStep<'w, RH>;
type Exec = InteractorQueryStep<'w, GatewayProxy, RH>;

fn prepare_async(self) -> Self::Exec {
InteractorQueryStep {
Expand All @@ -31,9 +32,10 @@ where
}
}

impl<'w, RH> InteractorQueryStep<'w, RH>
impl<'w, GatewayProxy, RH> InteractorQueryStep<'w, GatewayProxy, RH>
where
RH: RHListExec<TxResponse, InteractorEnvQuery<'w>>,
GatewayProxy: GatewayAsyncService,
RH: RHListExec<TxResponse, InteractorEnvQuery<'w, GatewayProxy>>,
RH::ListReturns: NestedTupleFlatten,
{
pub async fn run(mut self) -> <RH::ListReturns as NestedTupleFlatten>::Unpacked {
Expand Down
Loading

0 comments on commit 3bbf434

Please sign in to comment.