nit: Move builtins types to builtins file (#19597)
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
use crate::{
|
||||
bank::{Builtin, Builtins},
|
||||
system_instruction_processor,
|
||||
};
|
||||
use crate::system_instruction_processor;
|
||||
use solana_sdk::{
|
||||
feature_set,
|
||||
instruction::InstructionError,
|
||||
@@ -9,6 +6,10 @@ use solana_sdk::{
|
||||
pubkey::Pubkey,
|
||||
stake, system_program,
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
||||
use solana_frozen_abi::abi_example::AbiExample;
|
||||
|
||||
fn process_instruction_with_program_logging(
|
||||
process_instruction: ProcessInstructionWithContext,
|
||||
@@ -41,6 +42,59 @@ macro_rules! with_program_logging {
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(AbiExample, Debug, Clone)]
|
||||
pub enum ActivationType {
|
||||
NewProgram,
|
||||
NewVersion,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Builtin {
|
||||
pub name: String,
|
||||
pub id: Pubkey,
|
||||
pub process_instruction_with_context: ProcessInstructionWithContext,
|
||||
}
|
||||
|
||||
impl Builtin {
|
||||
pub fn new(
|
||||
name: &str,
|
||||
id: Pubkey,
|
||||
process_instruction_with_context: ProcessInstructionWithContext,
|
||||
) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
id,
|
||||
process_instruction_with_context,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Builtin {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Builtin [name={}, id={}]", self.name, self.id)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
||||
impl AbiExample for Builtin {
|
||||
fn example() -> Self {
|
||||
Self {
|
||||
name: String::default(),
|
||||
id: Pubkey::default(),
|
||||
process_instruction_with_context: |_, _, _| Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Builtins {
|
||||
/// Builtin programs that are always available
|
||||
pub genesis_builtins: Vec<Builtin>,
|
||||
|
||||
/// Builtin programs activated dynamically by feature
|
||||
pub feature_builtins: Vec<(Builtin, Pubkey, ActivationType)>,
|
||||
}
|
||||
|
||||
/// Builtin programs that are always available
|
||||
fn genesis_builtins() -> Vec<Builtin> {
|
||||
vec![
|
||||
@@ -72,12 +126,6 @@ fn genesis_builtins() -> Vec<Builtin> {
|
||||
]
|
||||
}
|
||||
|
||||
#[derive(AbiExample, Debug, Clone)]
|
||||
pub enum ActivationType {
|
||||
NewProgram,
|
||||
NewVersion,
|
||||
}
|
||||
|
||||
/// Builtin programs activated dynamically by feature
|
||||
///
|
||||
/// Note: If the feature_builtin is intended to replace another builtin program, it must have a new
|
||||
|
Reference in New Issue
Block a user