multiversx_sc_snippets/multi/
step_buffer.rs

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
55
56
use multiversx_sc_scenario::scenario_model::{ScCallStep, ScDeployStep};

use super::InteractorStepRef;

#[derive(Default)]
pub struct StepBuffer<'a> {
    pub refs: Vec<InteractorStepRef<'a>>,
}

impl<'a> StepBuffer<'a> {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn add_sc_call<'b, S>(&'a mut self, step: &'b mut S)
    where
        'b: 'a,
        S: AsMut<ScCallStep>,
    {
        self.refs.push(InteractorStepRef::ScCall(step.as_mut()));
    }

    pub fn add_sc_call_vec<'b, S>(&'a mut self, steps: &'b mut Vec<S>)
    where
        'b: 'a,
        S: AsMut<ScCallStep>,
    {
        for step in steps {
            self.refs.push(InteractorStepRef::ScCall(step.as_mut()));
        }
    }

    pub fn from_sc_call_vec<'b, S>(steps: &'b mut Vec<S>) -> Self
    where
        'b: 'a,
        S: AsMut<ScCallStep>,
    {
        let mut buffer = Self::default();
        for step in steps {
            buffer.refs.push(InteractorStepRef::ScCall(step.as_mut()));
        }
        buffer
    }

    pub fn from_sc_deploy_vec<'b, S>(steps: &'b mut Vec<S>) -> Self
    where
        'b: 'a,
        S: AsMut<ScDeployStep>,
    {
        let mut buffer = Self::default();
        for step in steps {
            buffer.refs.push(InteractorStepRef::ScDeploy(step.as_mut()));
        }
        buffer
    }
}