substrate_stellar_sdk/xdr/impls/operations/
path_payment_strict_send.rs

1use sp_std::vec::Vec;
2
3use crate::{
4    compound_types::LimitedVarArray,
5    types::{OperationBody, PathPaymentStrictSendOp},
6    Asset, IntoAmount, IntoMuxedAccountId, Operation, StellarSdkError,
7};
8
9impl Operation {
10    pub fn new_path_payment_strict_send<S: IntoAmount, U: IntoAmount, V: IntoMuxedAccountId>(
11        send_asset: Asset,
12        send_amount: S,
13        destination: V,
14        dest_asset: Asset,
15        dest_min: U,
16        path: Option<Vec<Asset>>,
17    ) -> Result<Operation, StellarSdkError> {
18        let path = match path {
19            Some(path) => LimitedVarArray::new(path)?,
20            None => LimitedVarArray::new_empty(),
21        };
22
23        Ok(Operation {
24            source_account: None,
25            body: OperationBody::PathPaymentStrictSend(PathPaymentStrictSendOp {
26                send_asset,
27                send_amount: send_amount.into_stroop_amount(false)?,
28                destination: destination.into_muxed_account_id()?,
29                dest_asset,
30                dest_min: dest_min.into_stroop_amount(false)?,
31                path,
32            }),
33        })
34    }
35}