casper_client/types/
named_key.rs1use std::fmt::{self, Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5use casper_types::{Key, KeyFromStrError};
6
7#[cfg(doc)]
8use crate::types::{Account, Contract};
9
10#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
13#[serde(deny_unknown_fields)]
14pub struct NamedKey {
15 name: String,
16 key: String,
17}
18
19impl NamedKey {
20 pub fn name(&self) -> &str {
22 &self.name
23 }
24
25 pub fn key(&self) -> Result<Key, KeyFromStrError> {
27 Key::from_formatted_str(&self.key)
28 }
29}
30
31impl Display for NamedKey {
32 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
33 write!(formatter, "{}: {}", self.name, self.key)
34 }
35}