substrate_stellar_sdk/xdr/impls/operations/
set_options.rs

1use core::convert::AsRef;
2
3use crate::{
4    compound_types::LimitedString,
5    types::{OperationBody, SetOptionsOp},
6    IntoAccountId, Operation, Signer, StellarSdkError,
7};
8
9impl Operation {
10    pub fn new_set_options<T: IntoAccountId, S: AsRef<[u8]>>(
11        inflation_dest: Option<T>,
12        clear_flags: Option<u32>,
13        set_flags: Option<u32>,
14        master_weight: Option<u8>,
15        low_threshold: Option<u8>,
16        med_threshold: Option<u8>,
17        high_threshold: Option<u8>,
18        home_domain: Option<S>,
19        signer: Option<Signer>,
20    ) -> Result<Operation, StellarSdkError> {
21        let home_domain = match home_domain {
22            Some(home_domain) => Some(LimitedString::new(home_domain.as_ref().to_vec())?),
23            None => None,
24        };
25
26        let inflation_dest = match inflation_dest {
27            Some(inflation_dest) => Some(inflation_dest.into_account_id()?),
28            None => None,
29        };
30
31        Ok(Operation {
32            source_account: None,
33            body: OperationBody::SetOptions(SetOptionsOp {
34                inflation_dest,
35                clear_flags,
36                set_flags,
37                master_weight: master_weight.map(|weight| weight as u32),
38                low_threshold: low_threshold.map(|weight| weight as u32),
39                med_threshold: med_threshold.map(|weight| weight as u32),
40                high_threshold: high_threshold.map(|weight| weight as u32),
41                home_domain,
42                signer,
43            }),
44        })
45    }
46}