-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1803 from multiversx/gateway-refactor-9
Gateway refactor - StepBuffer - removed trait object
- Loading branch information
Showing
5 changed files
with
60 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,66 @@ | ||
use crate::sdk::data::transaction::Transaction; | ||
use multiversx_sc_scenario::{ | ||
mandos_system::ScenarioRunner, | ||
scenario::tx_to_step::StepWithResponse, | ||
scenario_model::{AddressValue, ScCallStep, ScDeployStep, TxResponse}, | ||
}; | ||
use multiversx_sdk_http::GatewayHttpProxy; | ||
use multiversx_sdk::gateway::GatewayAsyncService; | ||
|
||
use crate::InteractorBase; | ||
|
||
/// Describes a scenario step that can be executed in an interactor. | ||
pub trait InteractorStep { | ||
fn to_transaction(&self, interactor: &InteractorBase<GatewayHttpProxy>) -> Transaction; | ||
|
||
fn sender_address(&self) -> &AddressValue; | ||
|
||
fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner); | ||
|
||
fn set_response(&mut self, tx_response: TxResponse); | ||
pub enum InteractorStepRef<'a> { | ||
ScCall(&'a mut ScCallStep), | ||
ScDeploy(&'a mut ScDeployStep), | ||
} | ||
|
||
impl InteractorStep for ScCallStep { | ||
fn to_transaction(&self, interactor: &InteractorBase<GatewayHttpProxy>) -> Transaction { | ||
interactor.tx_call_to_blockchain_tx(&self.tx) | ||
impl<'a> InteractorStepRef<'a> { | ||
pub fn to_transaction<GatewayProxy: GatewayAsyncService>( | ||
&self, | ||
interactor: &InteractorBase<GatewayProxy>, | ||
) -> Transaction { | ||
match self { | ||
InteractorStepRef::ScCall(sc_call) => interactor.tx_call_to_blockchain_tx(&sc_call.tx), | ||
InteractorStepRef::ScDeploy(sc_deploy) => { | ||
interactor.sc_deploy_to_blockchain_tx(sc_deploy) | ||
}, | ||
} | ||
} | ||
|
||
fn sender_address(&self) -> &AddressValue { | ||
&self.tx.from | ||
pub fn sender_address(&self) -> &AddressValue { | ||
match self { | ||
InteractorStepRef::ScCall(sc_call) => &sc_call.tx.from, | ||
InteractorStepRef::ScDeploy(sc_deploy) => &sc_deploy.tx.from, | ||
} | ||
} | ||
|
||
fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner) { | ||
let mut clone = self.clone(); | ||
step_runner.run_sc_call_step(&mut clone); // TODO: make mutability uniform | ||
pub fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner) { | ||
match self { | ||
InteractorStepRef::ScCall(sc_call) => step_runner.run_sc_call_step(sc_call), | ||
InteractorStepRef::ScDeploy(sc_deploy) => step_runner.run_sc_deploy_step(sc_deploy), | ||
} | ||
} | ||
|
||
fn set_response(&mut self, response: TxResponse) { | ||
self.save_response(response); | ||
pub fn set_response(&mut self, tx_response: TxResponse) { | ||
match self { | ||
InteractorStepRef::ScCall(sc_call) => sc_call.save_response(tx_response), | ||
InteractorStepRef::ScDeploy(sc_deploy) => sc_deploy.save_response(tx_response), | ||
} | ||
} | ||
} | ||
|
||
impl InteractorStep for ScDeployStep { | ||
fn to_transaction(&self, interactor: &InteractorBase<GatewayHttpProxy>) -> Transaction { | ||
interactor.sc_deploy_to_blockchain_tx(self) | ||
} | ||
|
||
fn sender_address(&self) -> &AddressValue { | ||
&self.tx.from | ||
} | ||
/// Describes a scenario step that can be executed in an interactor. | ||
pub trait InteractorStep: StepWithResponse { | ||
fn as_interactor_step(&mut self) -> InteractorStepRef<'_>; | ||
} | ||
|
||
fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner) { | ||
step_runner.run_sc_deploy_step(self); | ||
impl InteractorStep for ScCallStep { | ||
fn as_interactor_step(&mut self) -> InteractorStepRef<'_> { | ||
InteractorStepRef::ScCall(self) | ||
} | ||
} | ||
|
||
fn set_response(&mut self, response: TxResponse) { | ||
self.save_response(response); | ||
impl InteractorStep for ScDeployStep { | ||
fn as_interactor_step(&mut self) -> InteractorStepRef<'_> { | ||
InteractorStepRef::ScDeploy(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters