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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::error::{Error, Result};
use crate::xdr;
bitflags! {
pub struct AccountFlags: u32 {
const AUTH_REQUIRED = xdr::AccountFlags::AuthRequiredFlag as u32;
const AUTH_REVOCABLE = xdr::AccountFlags::AuthRevocableFlag as u32;
const AUTH_IMMUTABLE = xdr::AccountFlags::AuthImmutableFlag as u32;
}
}
bitflags! {
pub struct TrustLineFlags: u32 {
const AUTHORIZED = xdr::TrustLineFlags::AuthorizedFlag as u32;
const AUTHORIZED_TO_MAINTAIN_LIABILITIES = xdr::TrustLineFlags::AuthorizedToMaintainLiabilitiesFlag as u32;
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataValue(Vec<u8>);
impl DataValue {
pub fn from_slice(value: &[u8]) -> Result<DataValue> {
if value.len() > 64 {
return Err(Error::InvalidDataValue);
}
Ok(DataValue(value.to_vec()))
}
pub fn from_base64(encoded: &str) -> Result<DataValue> {
let decoded = base64::decode(encoded)?;
DataValue::from_slice(&decoded)
}
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
pub fn to_xdr(&self) -> Result<xdr::DataValue> {
let inner = self.as_bytes().to_vec();
Ok(xdr::DataValue::new(inner))
}
pub fn from_xdr(x: &xdr::DataValue) -> Result<DataValue> {
DataValue::from_slice(&x.value)
}
}