crema-cli 0.1.0

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

use clap::ArgMatches;
use colored::Colorize;
use solana_clap_utils::keypair::DefaultSigner;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use tabled::{Alignment, Modify, Panel, Rotate, Style, Table};
use tabled::object::Segment;
use tabled::style::Color;

use crate::check_and_update_err;
use crate::command::{CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult};
use crate::contract::state::farming::mine::Rewarder;

pub fn parse_farming_mine_rewarder_info<'a>(matches: &'a ArgMatches, default_signer: &DefaultSigner, wallet_manager: &mut Option<Arc<RemoteWalletManager>>) -> Result<CliCommandInfo<'a>, CliError> {
    let rewarder = matches.value_of("rewarder");

    Ok(CliCommandInfo {
        command: CliCommand::FarmingMineRewarderInfo {
            rewarder: Pubkey::from_str(rewarder.unwrap()).unwrap(),
        },
        signers: vec![check_and_update_err!(default_signer.signer_from_path(matches, wallet_manager), CliError::RpcRequestError("owner key is invalid".to_string()))?],
    })
}

pub fn process_farming_mine_rewarder_info(
    rpc_client: &RpcClient,
    _: &CliConfig,
    rewarder: Pubkey,
) -> ProcessResult {
    let info = Rewarder::get_info(rpc_client, &rewarder);

    let color = Color::try_from(" ".cyan().to_string()).unwrap();

    Ok(Table::new(vec![info])
        .with(Rotate::Bottom)
        .with(Rotate::Right)
        .with(Style::modern())
        .with(color)
        .with(Panel("Rewarder Info", 0))
        .with(Modify::new(Segment::all()).with(Alignment::center()))
        .to_string())
}