sol-chainsaw 0.0.2

Deserializing Solana accounts using their progam IDL
Documentation
use core::fmt;

use borsh::BorshDeserialize;
use serde::{Deserialize, Serialize};
use solana_idl::Idl;
use solana_program::pubkey::Pubkey;

#[derive(
    Debug, Clone, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq,
)]
pub struct IdlContainerAccount {
    pub authority: Pubkey,
    pub data: Vec<u8>,
}

pub struct FetchIdlResult {
    pub idl: Idl,
    pub account: IdlContainerAccount,
    pub program_id: Pubkey,
    pub idl_address: Pubkey,
    pub json: String,
}

pub struct FetchIdlJsonResult {
    pub account: IdlContainerAccount,
    pub program_id: Pubkey,
    pub idl_address: Pubkey,
    pub json: String,
}

/// Represents a Solana Cluster
///
/// TestNet, Devnet, MainnetBeta and Localhost wrap the known Urls.
/// To connect to another cluster use the [Cluster::Custom] variant.
pub enum Cluster {
    Testnet,
    Devnet,
    MainnetBeta,
    Localhost,
    Custom(String),
}

impl Cluster {
    pub fn endpoint(&self) -> &str {
        use Cluster::*;
        match self {
            Devnet => "https://api.devnet.solana.com",
            MainnetBeta => "https://api.mainnet-beta.solana.com",
            Testnet => "https://api.testnet.solana.com",
            Localhost => "http://localhost:8899",
            Custom(ref url) => url,
        }
    }
}

impl fmt::Display for Cluster {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        use Cluster::*;
        match self {
            Devnet => write!(f, "devnet"),
            MainnetBeta => write!(f, "mainnet-beta"),
            Testnet => write!(f, "testnet"),
            Localhost => write!(f, "localhost"),
            Custom(ref url) => write!(f, "{}", url),
        }
    }
}