Make default programs static (#9717)

This commit is contained in:
Jack May
2020-04-27 21:05:12 -07:00
committed by GitHub
parent 193dbb1794
commit efad193180
34 changed files with 134 additions and 173 deletions

View File

@ -1,6 +1,4 @@
use crate::{
native_loader::NativeLoader, rent_collector::RentCollector, system_instruction_processor,
};
use crate::{native_loader::NativeLoader, rent_collector::RentCollector};
use serde::{Deserialize, Serialize};
use solana_sdk::{
account::{create_keyed_readonly_accounts, Account, KeyedAccount},
@ -161,20 +159,17 @@ impl PreAccount {
pub type ProcessInstruction = fn(&Pubkey, &[KeyedAccount], &[u8]) -> Result<(), InstructionError>;
#[derive(Serialize, Deserialize)]
#[derive(Default, Deserialize, Serialize)]
pub struct MessageProcessor {
#[serde(skip)]
instruction_processors: Vec<(Pubkey, ProcessInstruction)>,
#[serde(skip)]
native_loader: NativeLoader,
}
impl Default for MessageProcessor {
fn default() -> Self {
Self {
instruction_processors: vec![(
system_program::id(),
system_instruction_processor::process_instruction,
)],
impl Clone for MessageProcessor {
fn clone(&self) -> Self {
MessageProcessor {
instruction_processors: self.instruction_processors.clone(),
native_loader: NativeLoader::default(),
}
}
@ -186,8 +181,16 @@ impl MessageProcessor {
program_id: Pubkey,
process_instruction: ProcessInstruction,
) {
self.instruction_processors
.push((program_id, process_instruction));
match self
.instruction_processors
.iter_mut()
.find(|(key, _)| program_id == *key)
{
Some((_, processor)) => *processor = process_instruction,
None => self
.instruction_processors
.push((program_id, process_instruction)),
}
}
/// Process an instruction