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::minter::minter_update::new_minter_update;
use crate::contract::instructions::farming::minter::new_minter_v2::new_minter_v2;
use crate::program::FARMING_MINT_WRAPPER_PROGRAM_ID;
use crate::utils::send::send_tx;
pub fn parse_farming_minter_new<'a>(matches: &'a ArgMatches, default_signer: &DefaultSigner, wallet_manager: &mut Option<Arc<RemoteWalletManager>>) -> Result<CliCommandInfo<'a>, CliError> {
let wrapper = matches.value_of("wrapper");
let allowance = matches.value_of("allowance");
let authority = matches.value_of("authority");
Ok(CliCommandInfo {
command: CliCommand::FarmingMinterNew {
wrapper: Pubkey::from_str(wrapper.unwrap()).unwrap(),
authority: Pubkey::from_str(authority.unwrap()).unwrap(),
allowance: allowance.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_minter_new(
rpc_client: &RpcClient,
config: &CliConfig,
wrapper: Pubkey,
allowance: u64,
authority: Pubkey,
) -> ProcessResult {
let minter =
Pubkey::find_program_address(
&[
b"MintWrapperMinter",
wrapper.as_ref(),
authority.as_ref(),
],
&FARMING_MINT_WRAPPER_PROGRAM_ID,
);
let ixs = [
new_minter_v2(
wrapper,
authority,
minter.0,
config.pubkey().unwrap(),
),
new_minter_update(
wrapper,
minter.0,
allowance,
config.pubkey().unwrap(),
),
];
let res = send_tx(rpc_client, config, &ixs)?;
Ok("signers : ".to_owned() + res.to_string().as_str())
}