-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unified syntax - interactor multi tx
- Loading branch information
1 parent
43934fd
commit 62fafc9
Showing
8 changed files
with
105 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
gateway = 'https://testnet-gateway.multiversx.com' | ||
gateway = 'https://devnet-gateway.multiversx.com' |
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
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,7 +1,9 @@ | ||
mod homogenous_tx_buffer; | ||
mod interactor_multi_sc_exec; | ||
mod interactor_multi_sc_process; | ||
mod interactor_step; | ||
mod step_buffer; | ||
|
||
pub use homogenous_tx_buffer::HomogenousTxBuffer; | ||
pub use interactor_step::InteractorStep; | ||
pub use step_buffer::StepBuffer; |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use multiversx_sc_scenario::{ | ||
multiversx_sc::{ | ||
tuple_util::NestedTupleFlatten, | ||
types::{RHListExec, TxBaseWithEnv}, | ||
}, | ||
scenario::tx_to_step::{StepWithResponse, StepWrapper, TxToStep}, | ||
scenario_model::TxResponse, | ||
ScenarioTxEnvData, | ||
}; | ||
|
||
use crate::{Interactor, InteractorExecEnv, InteractorStep, StepBuffer}; | ||
|
||
pub struct HomogenousTxBuffer<'w, Step, RH> { | ||
env: InteractorExecEnv<'w>, | ||
steps: Vec<StepWrapper<ScenarioTxEnvData, Step, RH>>, | ||
} | ||
|
||
impl Interactor { | ||
/// Creates a buffer that can hold multiple transactions, and then execute them all at once. | ||
/// | ||
/// This buffer holds transactions of the same type (call/deploy) and with identical result handler types. | ||
/// Therefore, after execution, all results will have the same type. | ||
pub fn homogenous_call_buffer<Step, RH>(&mut self) -> HomogenousTxBuffer<'_, Step, RH> { | ||
let data = self.new_env_data(); | ||
let env = InteractorExecEnv { world: self, data }; | ||
HomogenousTxBuffer { | ||
env, | ||
steps: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<'w, Step, RH> HomogenousTxBuffer<'w, Step, RH> | ||
where | ||
Step: InteractorStep + StepWithResponse, | ||
RH: RHListExec<TxResponse, ScenarioTxEnvData>, | ||
RH::ListReturns: NestedTupleFlatten, | ||
{ | ||
pub fn push_tx<Tx, F>(&mut self, f: F) -> &mut Self | ||
where | ||
Tx: TxToStep<Env = ScenarioTxEnvData, Step = Step, RH = RH>, | ||
F: FnOnce(TxBaseWithEnv<ScenarioTxEnvData>) -> Tx, | ||
{ | ||
let env = self.env.world.new_env_data(); | ||
let tx_base = TxBaseWithEnv::new_with_env(env); | ||
let tx = f(tx_base); | ||
|
||
self.steps.push(tx.tx_to_step()); | ||
|
||
self | ||
} | ||
|
||
pub async fn run(mut self) -> Vec<<RH::ListReturns as NestedTupleFlatten>::Unpacked> { | ||
let mut step_buffer = StepBuffer::default(); | ||
for step in &mut self.steps { | ||
step_buffer.refs.push(&mut step.step); | ||
} | ||
self.env.world.multi_sc_exec(step_buffer).await; | ||
|
||
self.steps | ||
.into_iter() | ||
.map(|step| step.process_result()) | ||
.collect() | ||
} | ||
} |