waves_rust/model/
id.rs

1use crate::error::Result;
2use crate::model::ByteString;
3use crate::util::Base58;
4use std::fmt;
5
6#[derive(Clone, Eq, PartialEq, Hash)]
7pub struct Id {
8    bytes: Vec<u8>,
9}
10
11impl fmt::Debug for Id {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        write!(f, "Id {{ {} }}", self.encoded())
14    }
15}
16
17impl Id {
18    pub fn from_string(id: &str) -> Result<Id> {
19        Ok(Id {
20            bytes: Base58::decode(id)?,
21        })
22    }
23
24    pub fn from_bytes(id: &[u8]) -> Id {
25        Id { bytes: id.into() }
26    }
27}
28
29impl ByteString for Id {
30    fn bytes(&self) -> Vec<u8> {
31        self.bytes.clone()
32    }
33
34    fn encoded(&self) -> String {
35        Base58::encode(&self.bytes, false)
36    }
37
38    fn encoded_with_prefix(&self) -> String {
39        Base58::encode(&self.bytes, true)
40    }
41}