substrate_stellar_sdk/xdr/impls/operations/
allow_trust.rs

1use crate::{
2    types::{AllowTrustOp, OperationBody},
3    AssetCode, IntoAccountId, Operation, StellarSdkError, TrustLineFlags,
4};
5
6impl Operation {
7    pub fn new_allow_trust<T: IntoAccountId, S: AsRef<[u8]>>(
8        trustor: T,
9        asset_code: S,
10        authorize: Option<TrustLineFlags>,
11    ) -> Result<Operation, StellarSdkError> {
12        let authorize: u32 = match authorize {
13            Some(authorize) => match authorize {
14                TrustLineFlags::TrustlineClawbackEnabledFlag => return Err(StellarSdkError::InvalidAuthorizeFlag),
15                _ => authorize as u32,
16            },
17            None => 0,
18        };
19
20        Ok(Operation {
21            source_account: None,
22            body: OperationBody::AllowTrust(AllowTrustOp {
23                trustor: trustor.into_account_id()?,
24                asset: AssetCode::new(asset_code)?,
25                authorize,
26            }),
27        })
28    }
29}