3

Here's my solana program,

use my-rust-crate::do_cpi;


pub fn do_something(ctx:Context<DoSomething>) => Result<()>{
    do_cpi(ctx);
}

so this my rust crate is where the CPI happens, its not a solana program, its a rust program. In order to do the CPI i need a signer.

so how should i proceed with this.

this is the solana program function i'm try to CPI

pub fn register_client(ctx: Context<RegisterClient>, client_name: String) -> Result<()> {
        let name = client_name.as_bytes();

        if validate_name(name) == false {
            return err!(AgentError::InvalidName);
        }
        let client = &mut ctx.accounts.client.load_init()?;
        client.owner = ctx.accounts.owner.to_account_info().key();
        Ok(())
    }
0

1 Answer 1

1

Let's say we have puppet-master which is our main program that wants to CPI into puppet program.

CPIs extend the privileges of the caller to the callee. If an account is passed as a mutable account to the puppet-master then it was still mutable in the puppet program as well, The same applies to signatures (Signers).

Source: https://book.anchor-lang.com/anchor_in_depth/CPIs.html#privilege-extension

Example with authority as the signer.

 let cpi_program = self.puppet_program.to_account_info();
        let cpi_accounts = SetData {
            puppet: self.puppet.to_account_info(),
            authority: self.authority.to_account_info()
        };
        CpiContext::new(cpi_program, cpi_accounts)
4
  • but my program flow is like this puppet-master(solana program) -> A rust program(not solana program) -> Puppet (CPI target program) Commented Dec 22, 2022 at 18:13
  • You can only CPI into deployed Solana programs. You can't CPI into rust programs
    – vicyyn
    Commented Dec 22, 2022 at 19:56
  • any work around that? like passing signature in some way? Commented Dec 23, 2022 at 5:33
  • I'm not sure what you mean. If you are trying to invoke a rust program from a Solana program, you can't. It should be either deployed in a Solana program or the code exists inside the Solana program. Solana programs have no ability to interact with off-chain programs whatsoever.
    – vicyyn
    Commented Dec 23, 2022 at 12:12

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.