in a nutshell I'm wondering how to send one CPI call with a vector of Instructions.
Here's an example:
I noticed there's a function in the solana_program
Rust crate called:
solana_program::system_instruction::transfer_many
It's parameters & return type are as follows:
pub fn transfer_many( from_pubkey: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec<Instruction>
This will obviously return to me a vector of Instruction types, but as far as I can tell invoke
and invoke_signed
are designed for one instruction at a time.
How can I use this vector of instructions dynamically, say if I want my program to transfer 3 different amounts to 3 different accounts in one transaction?
One can infer that you could iterate over the vector and use invoke
, but that raises three concerns:
- This seems sort of strange.
- How do I determine, for each
invoke
call, what accounts to pass? - How do I determine, for each
invoke_signed
call, what seeds to sign with?
Is there some way to do a single CPI that will send a transaction with multiple instructions?
Link to function: https://docs.rs/solana-program/latest/solana_program/system_instruction/fn.transfer_many.html