2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
solana_sdk::{
|
|
|
|
instruction::{CompiledInstruction, Instruction},
|
|
|
|
message::SanitizedMessage,
|
|
|
|
},
|
|
|
|
std::{cell::RefCell, rc::Rc},
|
2020-09-24 22:36:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Records and compiles cross-program invoked instructions
|
|
|
|
#[derive(Clone, Default)]
|
|
|
|
pub struct InstructionRecorder {
|
|
|
|
inner: Rc<RefCell<Vec<Instruction>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl InstructionRecorder {
|
2021-08-17 15:17:56 -07:00
|
|
|
pub fn compile_instructions(
|
|
|
|
&self,
|
|
|
|
message: &SanitizedMessage,
|
|
|
|
) -> Option<Vec<CompiledInstruction>> {
|
2020-09-24 22:36:22 +08:00
|
|
|
self.inner
|
|
|
|
.borrow()
|
|
|
|
.iter()
|
2021-08-17 15:17:56 -07:00
|
|
|
.map(|ix| message.try_compile_instruction(ix))
|
2020-09-24 22:36:22 +08:00
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn record_instruction(&self, instruction: Instruction) {
|
|
|
|
self.inner.borrow_mut().push(instruction);
|
|
|
|
}
|
|
|
|
}
|