Allow passing of program_id to programs (bp #8639) (#8670)

automerge
This commit is contained in:
mergify[bot]
2020-03-09 12:36:34 -07:00
committed by GitHub
parent f511296ee8
commit 889b06e1d4
4 changed files with 61 additions and 14 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