1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::sync::Arc;

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

use crate::check_and_update_err;
use common::command::{CliCommand, CliCommandInfo, CliError, ProcessResult};
use common::contract::state::tick_array::TickArray;

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

    let tick_index = tick_index.unwrap().parse::<i32>().unwrap();
    let tick_spacing = tick_spacing.unwrap().parse::<u16>().unwrap();

    Ok(CliCommandInfo {
        command: CliCommand::ArrayIndex {
            tick: tick_index,
            tick_spacing,
        },
        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_array_index_info(tick_index: i32, tick_spacing: u16) -> ProcessResult {
    let array_info = TickArray::array_info(tick_index, tick_spacing);
    let color = Color::try_from(" ".cyan().to_string()).unwrap();
    Ok(Table::new(vec![array_info])
        .with(Rotate::Bottom)
        .with(Rotate::Right)
        .with(Style::modern())
        .with(color)
        .with(Panel("Array Index Info", 0))
        .with(Modify::new(Segment::all()).with(Alignment::center()))
        .to_string())
}