novax_data/types/
payment.rs1use multiversx_sc::api::ManagedTypeApi;
2use multiversx_sc::types::EsdtTokenPayment;
3use multiversx_sc_scenario::api::StaticApi;
4use crate::types::managed::ManagedConvertible;
5use crate::types::native::NativeConvertible;
6
7#[derive(Clone, PartialEq, Debug)]
22pub struct Payment {
23 pub token_identifier: String,
25 pub token_nonce: u64,
28 pub amount: num_bigint::BigUint
30}
31
32impl<M: ManagedTypeApi> NativeConvertible for EsdtTokenPayment<M> {
33 type Native = Payment;
34
35 fn to_native(&self) -> Self::Native {
36 Payment {
37 token_identifier: self.token_identifier.to_native(),
38 token_nonce: self.token_nonce.to_native(),
39 amount: self.amount.to_native()
40 }
41 }
42}
43
44impl ManagedConvertible<EsdtTokenPayment<StaticApi>> for Payment {
45 fn to_managed(&self) -> EsdtTokenPayment<StaticApi> {
46 EsdtTokenPayment::new(
47 self.token_identifier.to_managed(),
48 self.token_nonce.to_managed(),
49 self.amount.to_managed()
50 )
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use multiversx_sc::types::{BigUint, EsdtTokenPayment, TokenIdentifier};
57 use multiversx_sc_scenario::api::StaticApi;
58 use crate::Payment;
59 use crate::types::managed::ManagedConvertible;
60
61 #[test]
62 fn test_payment_to_managed_payment() {
63 let payment = Payment {
64 token_identifier: "WEGLD-abcdef".to_string(),
65 token_nonce: 14u64,
66 amount: num_bigint::BigUint::from(100u8),
67 };
68 let managed: EsdtTokenPayment<StaticApi> = payment.to_managed();
69
70 let expected = EsdtTokenPayment::new(
71 TokenIdentifier::from("WEGLD-abcdef"),
72 14u64,
73 BigUint::from(100u64)
74 );
75
76 assert_eq!(
77 managed,
78 expected
79 );
80 }
81}