crema-cli 0.1.0

Blockchain, Crema for Solana
Documentation
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::mint_wrapper::transfer_mint::new_transfer_mint;
use crate::contract::state::farming::mint_wrapper::MintWrapper;
use crate::utils::send::send_tx;

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

    Ok(CliCommandInfo {
        command: CliCommand::FarmingMintWrapperBackAuthority {
            wrapper: Pubkey::from_str(wrapper.unwrap()).unwrap(),
            authority: Pubkey::from_str(authority.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_mint_wrapper_back_authority(
    rpc_client: &RpcClient,
    wrapper: Pubkey,
    config: &CliConfig,
    authority: Pubkey,
) -> ProcessResult {
    let wrapper_info = MintWrapper::get_info(rpc_client, &wrapper);

    let ixs = [
        new_transfer_mint(
            wrapper,
            authority,
            wrapper_info.token_mint,
            config.pubkey().unwrap(),
        )
    ];

    let res = send_tx(rpc_client, config, &ixs)?;

    Ok("signers : ".to_owned() + res.to_string().as_str())
}