I'm trying to do a CPI call to my main program, which is
#[derive(Accounts)]
pub struct RegisterClient<'info> {
#[account(mut)]
pub owner: Signer<'info>,
#[account(init, payer= owner, space=56,seeds= ["client".as_ref(), owner.key().as_ref()], bump)]
pub client: AccountLoader<'info, Client>,
pub system_program: Program<'info, System>,
}
from this program
use anchor_lang::prelude::*;
use sdk_agent;
use sdk_agent::instruction::RegisterClient as Reg;
use sdk_agent::Client;
use sdk_agent::RegisterClient;
declare_id!("As7EtU3YKAiKmagtnFXnQPCdRXsYs7rk3cXGzN5WN2HF");
#[program]
pub mod sample_program {
use anchor_lang::solana_program::{
instruction,
program::{invoke, invoke_signed, invoke_unchecked},
system_instruction::create_account,
system_program,
};
use super::*;
pub fn cpi(ctx: Context<CPI>) -> Result<()> {
msg!("here");
let client_name = String::from("testing");
let cpi_program = ctx.accounts.agent.to_account_info();
let account = vec![
ctx.accounts.owner.to_account_info(),
ctx.accounts.client.to_account_info(),
ctx.accounts.system_program.to_account_info(),
];
invoke(
&create_account(
ctx.accounts.owner.key,
&ctx.accounts.client.key(),
1280640,
56,
ctx.accounts.agent.key,
),
&account,
)?;
msg!("here");
let accounts = sdk_agent::cpi::accounts::RegisterClient {
owner: ctx.accounts.owner.to_account_info(),
client: ctx.accounts.client.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
};
let cpi_context = CpiContext::new(cpi_program, accounts);
sdk_agent::cpi::register_client(cpi_context, client_name)?;
// invoke(&instruction, accounts.as_slice());
msg!("here");
Ok(())
}
}
#[derive(Accounts)]
pub struct CPI<'info> {
#[account(mut)]
pub owner: Signer<'info>,
pub client: AccountLoader<'info, Client>,
///CHECK
pub agent: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
}
here client account should be initialized before hand,otherwise its throwing error, i tried to use create_account
But the the program is not reaching there , Probably gets stuck here checking this
pub client: AccountLoader<'info, Client>,
i can't convert it to Unchecked Account
or Account_info
since the Cpi_context require it to be account_loader struct.
I tried to initialize this account in the tests
const _tx = new anchor.web3.Transaction().add(
anchor.web3.SystemProgram.createAccount({
fromPubkey: program.provider.publicKey,
newAccountPubkey: client,
space: 56,
programId: agent,
lamports,
})
);
await program.provider.sendAndConfirm(mint_tx);
But signature verificatrion is failing , cause maybe it requires The Client seed or keypair to sign it as well.
can anyone help me tackle this?