Allow passing of program_ids to programs (#8639)

This commit is contained in:
Jack May
2020-03-05 10:57:12 -08:00
committed by GitHub
parent 0e3a8fa6d9
commit 97c5fb8141
4 changed files with 19 additions and 16 deletions

View File

@ -7,6 +7,7 @@ use crate::{
short_vec, system_instruction,
};
use itertools::Itertools;
use std::convert::TryFrom;
fn position(keys: &[Pubkey], key: &Pubkey) -> u8 {
keys.iter().position(|k| k == key).unwrap() as u8
@ -233,6 +234,17 @@ impl Message {
.collect()
}
pub fn is_key_passed_to_program(&self, index: usize) -> bool {
if let Ok(index) = u8::try_from(index) {
for ix in self.instructions.iter() {
if ix.accounts.contains(&index) {
return true;
}
}
}
false
}
pub fn program_position(&self, index: usize) -> Option<usize> {
let program_ids = self.program_ids();
program_ids