multiversx_sc_scenario/scenario/model/step/
into_blockchain_call.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#![allow(deprecated)]

use super::{ScCallStep, ScDeployStep, ScQueryStep, TypedScCall, TypedScDeploy, TypedScQuery};
use crate::{
    api::StaticApi,
    multiversx_sc::{
        codec::TopEncodeMulti,
        types::{
            ContractCall, ContractCallNoPayment, ContractCallWithEgld,
            ContractCallWithEgldOrSingleEsdt, ContractCallWithMultiEsdt, ContractDeploy,
        },
    },
};

/// Converts a [`ContractCall`] or [`ContractDeploy`] into a scenario object that additonally
/// contains gas costs and transaction-related data.
#[deprecated(
    since = "0.42.0",
    note = "The recommended syntax is a variation of `sc_call` or `sc_deploy` with a scenario step built from the ContractCall."
)]
pub trait IntoBlockchainCall {
    type BlockchainCall;

    #[deprecated(
        since = "0.42.0",
        note = "The recommended syntax is a variation of `sc_call` or `sc_deploy` with a scenario step built from the ContractCall."
    )]
    fn into_blockchain_call(self) -> Self::BlockchainCall;
}

// implementing the trait for all ContractCall types explicitly
// otherwise the orphan rules kick in
macro_rules! impl_into_blockchain_call_cc {
    ($cc:ident) => {
        impl<OriginalResult> IntoBlockchainCall for $cc<StaticApi, OriginalResult>
        where
            OriginalResult: TopEncodeMulti,
        {
            type BlockchainCall = TypedScCall<OriginalResult>;

            fn into_blockchain_call(self) -> Self::BlockchainCall {
                ScCallStep::new().call(self).into()
            }
        }
    };
}

impl_into_blockchain_call_cc! {ContractCallNoPayment}
impl_into_blockchain_call_cc! {ContractCallWithEgld}
impl_into_blockchain_call_cc! {ContractCallWithEgldOrSingleEsdt}
impl_into_blockchain_call_cc! {ContractCallWithMultiEsdt}

impl<OriginalResult> IntoBlockchainCall for ContractDeploy<StaticApi, OriginalResult> {
    type BlockchainCall = TypedScDeploy<OriginalResult>;

    fn into_blockchain_call(self) -> Self::BlockchainCall {
        ScDeployStep::new().call(self)
    }
}

/// Converts a `ContractCall` into a scenario object that encodes a SC query.
pub trait IntoVMQuery {
    type VMQuery;

    fn into_vm_query(self) -> Self::VMQuery;
}

impl<CC> IntoVMQuery for CC
where
    CC: ContractCall<StaticApi>,
{
    type VMQuery = TypedScQuery<CC::OriginalResult>;
    fn into_vm_query(self) -> Self::VMQuery {
        ScQueryStep::default().call(self)
    }
}