1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use multiversx_sc_scenario::{
    mandos_system::ScenarioRunner,
    scenario_model::{AddressValue, ScCallStep, ScDeployStep, TxResponse},
};
use multiversx_sdk::data::transaction::Transaction;

use crate::Interactor;

pub trait TransactionSpec {
    fn to_transaction(&self, interactor: &Interactor) -> Transaction;

    fn to_address(&self) -> &AddressValue;

    fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner);

    fn set_response(&mut self, tx_response: TxResponse);
}

impl TransactionSpec for ScCallStep {
    fn to_transaction(&self, interactor: &Interactor) -> Transaction {
        interactor.tx_call_to_blockchain_tx(&self.tx)
    }

    fn to_address(&self) -> &AddressValue {
        &self.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
    }

    fn set_response(&mut self, response: TxResponse) {
        self.save_response(response);
    }
}

impl TransactionSpec for ScDeployStep {
    fn to_transaction(&self, interactor: &Interactor) -> Transaction {
        interactor.sc_deploy_to_blockchain_tx(self)
    }

    fn to_address(&self) -> &AddressValue {
        &self.tx.from
    }

    fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner) {
        step_runner.run_sc_deploy_step(self);
    }

    fn set_response(&mut self, response: TxResponse) {
        self.save_response(response);
    }
}