use std::str::FromStr;
use std::sync::Arc;
use clap::ArgMatches;
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 crate::check_and_update_err;
use crate::command::{CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult};
use crate::contract::instructions::farming::quarry_mine::create_quarry_v2::new_create_quarry_v2;
use crate::contract::instructions::farming::quarry_mine::set_famine::new_set_famine;
use crate::contract::instructions::farming::quarry_mine::set_rewards_share::new_set_rewards_share;
use crate::contract::state::farming::mine::Rewarder;
use crate::program::FARMING_MINE_PROGRAM_ID;
use crate::utils::send::send_tx;
pub fn parse_farming_quarry_mine_new<'a>(matches: &'a ArgMatches, default_signer: &DefaultSigner, wallet_manager: &mut Option<Arc<RemoteWalletManager>>) -> Result<CliCommandInfo<'a>, CliError> {
let rewarder = matches.value_of("rewarder");
let mint = matches.value_of("mint");
let famine_ts = matches.value_of("famine-ts");
let share = matches.value_of("share");
Ok(CliCommandInfo {
command: CliCommand::FarmingQuarryMineNew {
rewarder: Pubkey::from_str(rewarder.unwrap()).unwrap(),
mint: Pubkey::from_str(mint.unwrap()).unwrap(),
famine_ts: famine_ts.unwrap().parse::<u64>().unwrap(),
share: share.unwrap().parse::<u64>().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_quarry_mine_new(
rpc_client: &RpcClient,
config: &CliConfig,
rewarder: Pubkey,
mint: Pubkey,
famine_ts: u64,
share: u64,
) -> ProcessResult {
let rewarder_account = Rewarder::get_account(rpc_client, &rewarder);
let quarry = Pubkey::find_program_address(
&[
b"Quarry",
rewarder.as_ref(),
mint.as_ref(),
],
&FARMING_MINE_PROGRAM_ID,
);
let ixs = [
new_create_quarry_v2(
quarry.0,
rewarder,
mint,
config.pubkey().unwrap(),
),
new_set_rewards_share(
rewarder,
quarry.0,
config.pubkey().unwrap(),
share
),
new_set_famine(
rewarder,
rewarder_account.owner,
quarry.0,
famine_ts,
),
];
let res = send_tx(rpc_client, config, &ixs)?;
Ok("signers : ".to_owned() + res.to_string().as_str())
}