1

I'm getting an error when trying to do a cpi: Program log: AnchorError occurred. Error Code: InstructionFallbackNotFound. Error Number: 101. Error Message: Fallback functions are not supported.

i've the following code in a crate:

pub fn set_cfg<'info>(
ctx: CpiContext<'_, '_, '_, 'info, xHandler<'info>>,
a: u64,
b: u64,
c: u64,
d: u64,
e: u64,
f: u64,
g: u8,
h: u64,
i:u8,
j: u64,
) -> Result<()> {

//let mut data = hash(b"global:set_cfg").to_bytes()[..8].to_vec();
 let mut data = vec![0xe8, 0xfa, 0xd7, 0xfb, 0xe5, 0xfd, 0xaa, 0x12];
data.extend_from_slice(&a.to_le_bytes());
data.extend_from_slice(&b.to_le_bytes());
data.extend_from_slice(&c.to_le_bytes());
data.extend_from_slice(&d.to_le_bytes());
data.extend_from_slice(&e.to_le_bytes());
data.extend_from_slice(&f.to_le_bytes());
data.extend_from_slice(&[g]);
data.extend_from_slice(&h.to_le_bytes());
data.extend_from_slice(&[i]);
data.extend_from_slice(&j.to_le_bytes());


let ix = Instruction::new_with_borsh(ID, &data, ctx.accounts.to_account_metas(None));

solana_program::program::invoke_signed(
    &ix,
    &[
        ctx.accounts.account_a.clone(),
        ctx.accounts.account_b.clone(),
        ctx.accounts.account_c.clone(),
        ctx.accounts.system_program.clone(),
        ctx.accounts.instructions.clone()
    ],
    ctx.signer_seeds,
)
.map_err(Into::into)

}

In the program where i call this cpi i've:

        let accounts = x_programs::modules::xHandler{
        account_a: self.account_a.to_account_info(),
        account_b: self.account_b.to_account_info(),
        account_c: self.account_c.to_account_info(),
        account_d: self.system_program.to_account_info(),
        account_e: self.instructions.to_account_info()
    };

    let cpi_context = CpiContext::new(
        self.x_program.to_account_info(),
        accounts
    )

    x_program::modules::set_cfg(
        cpi_context,
        a,
        b, 
        c, 
        d, 
        e, 
        f, 
        g, 
        h,
        i,
        j,
     )?;   

In the program where the cpi is called i've

#[derive(Accounts)]
pub struct xHandler<'info> {
#[account(mut)]
account_a: Signer<'info>,
#[account(mut
)]
account_b: Box<Account<'info, x>>,
#[account(mut
)]
account_c: Box<Account<'info, z>>,
system_program: Program<'info, System>,
/// CHECK: 
#[account(address = sysvar::instructions::id())]
instructions: AccountInfo<'info>, 
}

impl<'info> xHandler<'info> {
pub fn  set_cfg(
    &mut self,
    bumps: &xHandlerBumps,
    a: u64,
    b: u64,
    c: u64,
    d: u64,
    e: u8,
    f: u64,
    g: u64,
    h: u64,
    i:u8,
    j: u64,
    ) -> Result<()> {

   self.account_b.set_inner(x{ 
        z1 : 0,
        bump: bumps.account_b,
        a,
        b,
        c,
        d,
        e,
        f, 
        g, 
        h,
        l: Clock::get()?.epoch,
        i,
        j
    });    
    Ok(())
}
}

Lib.rs

pub fn set_cfg(
    ctx: Context<xHandler>,
    a: u64,
    b: u64,
    c: u64,
    d: u64,
    e: u64,
    f: u64,
    g: u8,
    h: u64,
    i:u8,
    j: u64,
) -> Result<()> {
        ctx.accounts.set_cfg(
        &ctx.bumps,
        a,
        b,
        c,
        d,
        e,
        f,
        g,
        h,
        i,
        j
        )
       Ok(())
} 

}

Any idea? Thanks in advance

1 Answer 1

1

Fixed by using Instruction::new_with_bytes instead of Instruction::new_with_borsh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.