multiversx_sc_scenario/scenario/model/step/
transfer_step.rs1use crate::scenario::model::{
2 AddressValue, BigUintValue, BytesValue, TxESDT, TxTransfer, TxValidatorReward, U64Value,
3};
4
5#[derive(Debug, Default, Clone)]
6pub struct TransferStep {
7 pub id: String,
8 pub tx_id: Option<String>,
9 pub comment: Option<String>,
10 pub tx: Box<TxTransfer>,
11}
12
13#[derive(Debug, Clone)]
14pub struct ValidatorRewardStep {
15 pub id: String,
16 pub tx_id: Option<String>,
17 pub comment: Option<String>,
18 pub tx: Box<TxValidatorReward>,
19}
20
21impl TransferStep {
22 pub fn new() -> Self {
23 Self::default().gas_limit("50,000")
26 }
27
28 pub fn from<A>(mut self, address: A) -> Self
29 where
30 AddressValue: From<A>,
31 {
32 self.tx.from = AddressValue::from(address);
33 self
34 }
35
36 pub fn to<A>(mut self, address: A) -> Self
37 where
38 AddressValue: From<A>,
39 {
40 self.tx.to = AddressValue::from(address);
41 self
42 }
43
44 pub fn egld_value<A>(mut self, amount: A) -> Self
45 where
46 BigUintValue: From<A>,
47 {
48 if !self.tx.esdt_value.is_empty() {
49 panic!("Cannot transfer both EGLD and ESDT");
50 }
51
52 self.tx.egld_value = BigUintValue::from(amount);
53 self
54 }
55
56 pub fn esdt_transfer<T, N, A>(mut self, token_id: T, token_nonce: N, amount: A) -> Self
57 where
58 BytesValue: From<T>,
59 U64Value: From<N>,
60 BigUintValue: From<A>,
61 {
62 if self.tx.egld_value.value > 0u32.into() {
63 panic!("Cannot transfer both EGLD and ESDT");
64 }
65
66 self.tx.esdt_value.push(TxESDT {
67 esdt_token_identifier: BytesValue::from(token_id),
68 nonce: U64Value::from(token_nonce),
69 esdt_value: BigUintValue::from(amount),
70 });
71
72 self
73 }
74
75 pub fn gas_limit<V>(mut self, value: V) -> Self
76 where
77 U64Value: From<V>,
78 {
79 self.tx.gas_limit = U64Value::from(value);
80 self
81 }
82}