switchboard_program2/
lib.rs1use quick_protobuf::serialize_into_vec;
2use solana_program::instruction::AccountMeta;
3use solana_program::{account_info::AccountInfo, program::invoke, program_error::ProgramError};
4use switchboard_protos::protos::instruction::mod_SwitchboardInstruction::GetAggregateInstruction;
5use switchboard_protos::protos::instruction::mod_SwitchboardInstruction::OneOfinstruction::get_aggregate_instruction;
6use switchboard_protos::protos::instruction::SwitchboardInstruction;
7
8pub use switchboard_protos::protos::aggregator_state::RoundResult;
9
10pub fn invoke_feed<'a>(
11 switchboard: &'a AccountInfo<'a>,
12 switchboard_feed: &'a AccountInfo<'a>,
13 callback: &'a AccountInfo<'a>,
14 callback_signer: &'a AccountInfo<'a>,
15 other_accounts: &'a [AccountInfo<'a>],
16) -> Result<(), ProgramError> {
17 let switchboard_instruction = SwitchboardInstruction {
18 instruction: get_aggregate_instruction(GetAggregateInstruction {}),
19 };
20
21 let mut account_metas = vec![
22 AccountMeta::new(*switchboard_feed.key, false),
23 AccountMeta::new(*callback.key, false),
24 AccountMeta::new(*callback_signer.key, true),
25 ];
26 let mut other_account_metas: Vec<AccountMeta> = other_accounts
27 .to_vec()
28 .iter_mut()
29 .map(|account_info| AccountMeta::new(*account_info.key, false))
30 .collect();
31 account_metas.append(&mut other_account_metas);
32 let solana_instruction = solana_program::instruction::Instruction {
33 program_id: *switchboard.key,
34 data: serialize_into_vec(&switchboard_instruction).unwrap(),
35 accounts: account_metas,
36 };
37 let mut accounts = vec![
38 switchboard.clone(),
39 switchboard_feed.clone(),
40 callback.clone(),
41 callback_signer.clone(),
42 ];
43 accounts.append(&mut other_accounts.to_vec());
44 invoke(&solana_instruction, &accounts)?;
45 Ok(())
46}