1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use core::convert::AsRef;

use crate::{
    compound_types::LimitedString,
    types::{OperationBody, SetOptionsOp},
    IntoAccountId, Operation, Signer, StellarSdkError,
};

impl Operation {
    pub fn new_set_options<T: IntoAccountId, S: AsRef<[u8]>>(
        inflation_dest: Option<T>,
        clear_flags: Option<u32>,
        set_flags: Option<u32>,
        master_weight: Option<u8>,
        low_threshold: Option<u8>,
        med_threshold: Option<u8>,
        high_threshold: Option<u8>,
        home_domain: Option<S>,
        signer: Option<Signer>,
    ) -> Result<Operation, StellarSdkError> {
        let home_domain = match home_domain {
            Some(home_domain) => Some(LimitedString::new(home_domain.as_ref().to_vec())?),
            None => None,
        };

        let inflation_dest = match inflation_dest {
            Some(inflation_dest) => Some(inflation_dest.into_account_id()?),
            None => None,
        };

        Ok(Operation {
            source_account: None,
            body: OperationBody::SetOptions(SetOptionsOp {
                inflation_dest,
                clear_flags,
                set_flags,
                master_weight: master_weight.map(|weight| weight as u32),
                low_threshold: low_threshold.map(|weight| weight as u32),
                med_threshold: med_threshold.map(|weight| weight as u32),
                high_threshold: high_threshold.map(|weight| weight as u32),
                home_domain,
                signer,
            }),
        })
    }
}