substreams_solana_program_instructions/
pubkey.rs

1/// Number of bytes in a pubkey
2pub const PUBKEY_BYTES: usize = 32;
3/// maximum length of derived `Pubkey` seed
4// pub const MAX_SEED_LEN: usize = 32;
5// /// Maximum number of seeds
6// pub const MAX_SEEDS: usize = 16;
7// /// Maximum string length of a base58 encoded pubkey
8// const MAX_BASE58_LEN: usize = 44;
9//
10// const PDA_MARKER: &[u8; 21] = b"ProgramDerivedAddress";
11
12#[derive(Clone, Copy, Debug, PartialEq)]
13pub struct Pubkey(pub(crate) [u8; 32]);
14
15impl Pubkey{
16    pub fn to_bytes(self) -> [u8; 32] {
17        self.0
18    }
19}
20
21impl AsRef<[u8]> for Pubkey {
22    fn as_ref(&self) -> &[u8] {
23        &self.0[..]
24    }
25}
26
27impl From<[u8; 32]> for Pubkey {
28    #[inline]
29    fn from(from: [u8; 32]) -> Self {
30        Self(from)
31    }
32}
33
34impl TryFrom<&[u8]> for Pubkey {
35    type Error = std::array::TryFromSliceError;
36
37    #[inline]
38    fn try_from(pubkey: &[u8]) -> Result<Self, Self::Error> {
39        <[u8; 32]>::try_from(pubkey).map(Self::from)
40    }
41}
42
43impl TryFrom<Vec<u8>> for Pubkey {
44    type Error = Vec<u8>;
45
46    #[inline]
47    fn try_from(pubkey: Vec<u8>) -> Result<Self, Self::Error> {
48        <[u8; 32]>::try_from(pubkey).map(Self::from)
49    }
50}
51