crema-cli 0.1.0

Blockchain, Crema for Solana
Documentation
use std::str::FromStr;

use borsh::BorshDeserialize;
use clap::ArgMatches;
use colored::Colorize;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use tabled::{Alignment, Modify, Panel, Rotate, Style, Table};
use tabled::object::Segment;
use tabled::style::Color;

use crate::command::{CliCommand, CliCommandInfo, CliError, ProcessResult};
use crate::contract::state::fee_tier::FeeTier;

pub fn parse_fee_tier_info<'a>(
    matches: &'a ArgMatches,
) -> Result<CliCommandInfo<'a>, CliError> {
    let fee_tier = matches.value_of("fee_tier_key");

    Ok(CliCommandInfo {
        command: CliCommand::PairFeeTierInfo {
            fee_tier: Pubkey::from_str(fee_tier.unwrap()).unwrap(),
        },
        signers: vec![],
    })
}

pub fn process_fee_tier_info(rpc_client: &RpcClient, fee_tier: Pubkey) -> ProcessResult {
    let data = rpc_client.get_account_data(&fee_tier).unwrap();

    let config_account: FeeTier = FeeTier::try_from_slice(&data[8..]).unwrap();

    let color = Color::try_from(" ".cyan().to_string()).unwrap();
    Ok(Table::new(vec![config_account])
        .with(Rotate::Bottom)
        .with(Rotate::Right)
        .with(Style::modern())
        .with(color)
        .with(Panel("Fee tier Account Info", 0))
        .with(Modify::new(Segment::all()).with(Alignment::center()))
        .to_string())
}