multiversx_sc_scenario/scenario/tx_to_step/
step_annotation.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
77
78
79
80
81
82
83
84
85
86
87
use multiversx_chain_scenario_format::serde_raw::ValueSubTree;
use multiversx_sc::types::{
    AnnotatedValue, BigUint, Code, ManagedAddress, ManagedBuffer, TokenIdentifier, TxCodeValue,
    TxEnv, TxGas,
};

use crate::scenario_model::{AddressValue, BigUintValue, BytesKey, BytesValue, U64Value};

pub fn address_annotated<Env, Addr>(env: &Env, from: &Addr) -> AddressValue
where
    Env: TxEnv,
    Addr: AnnotatedValue<Env, ManagedAddress<Env::Api>>,
{
    let annotation = from.annotation(env).to_string();
    AddressValue {
        value: from.to_value(env).to_address(),
        original: ValueSubTree::Str(annotation),
    }
}

pub fn u64_annotated<Env, T>(env: &Env, from: &T) -> U64Value
where
    Env: TxEnv,
    T: AnnotatedValue<Env, u64>,
{
    let annotation = from.annotation(env).to_string();
    U64Value {
        value: from.to_value(env),
        original: ValueSubTree::Str(annotation),
    }
}

pub fn big_uint_annotated<Env, T>(env: &Env, from: &T) -> BigUintValue
where
    Env: TxEnv,
    T: AnnotatedValue<Env, BigUint<Env::Api>>,
{
    let annotation = from.annotation(env).to_string();
    BigUintValue {
        value: from.to_value(env).to_alloc(),
        original: ValueSubTree::Str(annotation),
    }
}

pub fn bytes_annotated<Env, T>(env: &Env, value: T) -> BytesValue
where
    Env: TxEnv,
    T: AnnotatedValue<Env, ManagedBuffer<Env::Api>>,
{
    let annotation = value.annotation(env).to_string();
    BytesValue {
        value: value.into_value(env).to_vec(),
        original: ValueSubTree::Str(annotation),
    }
}

pub fn token_identifier_annotated<Env, T>(env: &Env, value: T) -> BytesKey
where
    Env: TxEnv,
    T: AnnotatedValue<Env, TokenIdentifier<Env::Api>>,
{
    let annotation = value.annotation(env).to_string();
    BytesKey {
        value: value.into_value(env).into_managed_buffer().to_vec(),
        original: annotation,
    }
}

pub fn code_annotated<Env, CodeValue>(env: &Env, code: Code<CodeValue>) -> BytesValue
where
    Env: TxEnv,
    CodeValue: TxCodeValue<Env>,
{
    bytes_annotated(env, code.0)
}

pub fn gas_annotated<Env, Gas>(env: &Env, gas: Gas) -> U64Value
where
    Env: TxEnv,
    Gas: TxGas<Env>,
{
    let annotation = gas.gas_annotation(env).to_string();
    U64Value {
        value: gas.gas_value(env),
        original: ValueSubTree::Str(annotation),
    }
}