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
use ::strkey::StrKey;
use ::error::{Result, Error};

pub enum Asset {
    Native,
    Credit { code: String, issuer: StrKey },
}

impl Asset {
    pub fn native() -> Asset {
        Asset::Native
    }

    pub fn credit(code: String, issuer: StrKey) -> Result<Asset> {
        if code.len() > 12 {
            Err(Error::TBD) // string too long
        } else {
            Ok(Asset::Credit {
                code: code,
                issuer: issuer,
            })
        }
    }
}

#[cfg(test)]
mod tests {
    use StrKey;
    use Asset;

    #[test]
    fn test_code_too_long() {
        let issuer =
            StrKey::from_account_id("GCLDNMHZTEY6PUYQBYOVERBBZ2W3RLMYOSZWHAMY5R4YW2N6MM4LFA72")
                .unwrap();
        let asset = Asset::credit("NAMETOOLONGFORSURE".to_string(), issuer);
        assert!(asset.is_err());
    }
}