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
pub mod config;
pub mod rpc;
use std::io::{self, Error, ErrorKind};
use crate::ids;
pub fn vm_name_to_id(s: impl AsRef<[u8]>) -> io::Result<ids::Id> {
let d = s.as_ref();
if d.len() > ids::LEN {
return Err(Error::new(
ErrorKind::Other,
format!("non-hashed name must be <= 32 bytes, found {}", d.len()),
));
}
Ok(ids::Id::from_slice(d))
}
#[test]
fn test_vm_name_to_id() {
let id = vm_name_to_id("timestampvm").unwrap();
println!("{id}");
assert_eq!(
id.to_string(),
"tGas3T58KzdjcJ2iKSyiYsWiqYctRXaPTqBCA11BqEkNg8kPc"
);
}