use std::sync::Arc;
use borsh::BorshDeserialize;
use clap::ArgMatches;
use colored::Colorize;
use solana_clap_utils::keypair::DefaultSigner;
use solana_client::rpc_client::RpcClient;
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::pubkey::Pubkey;
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, CliError, ProcessResult};
use crate::contract::state::clmmpools::Clmmpool;
pub fn parse_pair_info<'a>(
matches: &ArgMatches,
default_signer: &DefaultSigner,
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
) -> Result<CliCommandInfo<'a>, CliError> {
let pool_address = matches.value_of("pool");
Ok(CliCommandInfo {
command: CliCommand::PairInfo {
pair_key: pool_address.unwrap().parse::<Pubkey>().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_pair_info(rpc_client: &RpcClient, pair_key: &Pubkey) -> ProcessResult {
let data = rpc_client.get_account_data(pair_key).unwrap();
let swap_account: Clmmpool = Clmmpool::try_from_slice(&data[8..]).unwrap();
let color = Color::try_from(" ".cyan().to_string()).unwrap();
Ok(Table::new(vec![swap_account])
.with(Rotate::Bottom)
.with(Rotate::Right)
.with(Style::modern())
.with(color)
.with(Panel("Swap Account Info", 0))
.with(Modify::new(Segment::all()).with(Alignment::center()))
.to_string())
}