Add return data implementation

This consists of:
 - syscalls
 - passing return data from invoked to invoker
 - printing to stable log
 - rust and C SDK changes
This commit is contained in:
Sean Young
2021-09-01 10:14:01 +01:00
parent 2dee098b91
commit 098585234d
23 changed files with 641 additions and 35 deletions

View File

@ -67,6 +67,8 @@ pub struct ThisInvokeContext<'a> {
sysvars: RefCell<Vec<(Pubkey, Option<Rc<Vec<u8>>>)>>,
blockhash: &'a Hash,
fee_calculator: &'a FeeCalculator,
// return data and program_id that set it
return_data: Option<(Pubkey, Vec<u8>)>,
}
impl<'a> ThisInvokeContext<'a> {
#[allow(clippy::too_many_arguments)]
@ -116,6 +118,7 @@ impl<'a> ThisInvokeContext<'a> {
sysvars: RefCell::new(vec![]),
blockhash,
fee_calculator,
return_data: None,
};
invoke_context.push(program_id, message, instruction, program_indices, accounts)?;
Ok(invoke_context)
@ -329,6 +332,12 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
fn get_fee_calculator(&self) -> &FeeCalculator {
self.fee_calculator
}
fn set_return_data(&mut self, return_data: Option<(Pubkey, Vec<u8>)>) {
self.return_data = return_data;
}
fn get_return_data(&self) -> &Option<(Pubkey, Vec<u8>)> {
&self.return_data
}
}
pub struct ThisLogger {
log_collector: Option<Rc<LogCollector>>,