solana_scanner/src/utils.rs
Alexandre RAY-BERNAT e263b50e22
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Retrieves social infos + post on Telegram
2025-05-23 14:46:16 +02:00

28 lines
793 B
Rust

use reqwest::Client;
use solana_program::pubkey::Pubkey;
use crate::dto::TokenSocials;
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))
}
pub async fn get_token_socials(uri: &str) -> Result<TokenSocials, Box<dyn std::error::Error>> {
let client = Client::new();
let response = client.get(uri)
.send()
.await?;
let json: TokenSocials = response.json().await?;
Ok(json)
}