15 lines
475 B
Rust
15 lines
475 B
Rust
|
|
use solana_program::pubkey::Pubkey;
|
||
|
|
|
||
|
|
pub fn sanitize_string(s: &str) -> String {
|
||
|
|
s.trim_end_matches('\0').to_string()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn base58_to_pubkey(address: &str) -> anyhow::Result<Pubkey, Box<dyn std::error::Error>> {
|
||
|
|
let decoded = bs58::decode(address).into_vec()?;
|
||
|
|
if decoded.len() != 32 {
|
||
|
|
return Err("Address must be 32 bytes long".into());
|
||
|
|
}
|
||
|
|
let mut bytes = [0u8; 32];
|
||
|
|
bytes.copy_from_slice(&decoded);
|
||
|
|
Ok(Pubkey::new_from_array(bytes))
|
||
|
|
}
|