2018-09-26 17:55:36 -06:00
|
|
|
use bs58;
|
|
|
|
use generic_array::typenum::U32;
|
|
|
|
use generic_array::GenericArray;
|
|
|
|
use std::fmt;
|
|
|
|
|
2018-10-04 09:44:44 -07:00
|
|
|
#[repr(C)]
|
2018-09-26 17:55:36 -06:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
|
|
|
pub struct Pubkey(GenericArray<u8, U32>);
|
|
|
|
|
|
|
|
impl Pubkey {
|
|
|
|
pub fn new(pubkey_vec: &[u8]) -> Self {
|
|
|
|
Pubkey(GenericArray::clone_from_slice(&pubkey_vec))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<[u8]> for Pubkey {
|
|
|
|
fn as_ref(&self) -> &[u8] {
|
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for Pubkey {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", bs58::encode(self.0).into_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Pubkey {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", bs58::encode(self.0).into_string())
|
|
|
|
}
|
|
|
|
}
|