Move system_program out of src/

This commit is contained in:
Michael Vines
2018-12-03 13:32:31 -08:00
parent ae0be1e857
commit 9a4f8199d6
28 changed files with 332 additions and 571 deletions

10
sdk/src/bpf_loader.rs Normal file
View File

@ -0,0 +1,10 @@
use pubkey::Pubkey;
pub const BPF_LOADER_PROGRAM_ID: [u8; 32] = [
128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
];
pub fn id() -> Pubkey {
Pubkey::new(&BPF_LOADER_PROGRAM_ID)
}

View File

@ -1,4 +1,5 @@
pub mod account;
pub mod bpf_loader;
pub mod hash;
pub mod loader_instruction;
pub mod native_loader;
@ -7,6 +8,7 @@ pub mod packet;
pub mod pubkey;
pub mod signature;
pub mod system_instruction;
pub mod system_program;
pub mod timing;
pub mod transaction;

View File

@ -1,5 +1,44 @@
use account::KeyedAccount;
use pubkey::Pubkey;
use std;
/// Reasons a program might have rejected an instruction.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ProgramError {
/// The program instruction returned an error
GenericError,
/// The arguments provided to a program instruction where invalid
InvalidArgument,
/// An instruction resulted in an account with a negative balance
/// The difference from InsufficientFundsForFee is that the transaction was executed by the
/// contract
ResultWithNegativeTokens,
/// Program's instruction token balance does not equal the balance after the instruction
UnbalancedInstruction,
/// Program modified an account's program id
ModifiedProgramId,
/// Program spent the tokens of an account that doesn't belong to it
ExternalAccountTokenSpend,
/// SystemInstruction::Assign was attempted on an account unowned by the system program
AssignOfUnownedAccount,
/// SystemInstruction::Spawn was attempted on an account that was not finalized by
/// LoaderInstruction::Finalize
AccountNotFinalized,
}
impl std::fmt::Display for ProgramError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "error")
}
}
impl std::error::Error for ProgramError {}
// All native programs export a symbol named process()
pub const ENTRYPOINT: &str = "process";
@ -10,7 +49,7 @@ pub type Entrypoint = unsafe extern "C" fn(
keyed_accounts: &mut [KeyedAccount],
data: &[u8],
tick_height: u64,
) -> bool;
) -> Result<(), ProgramError>;
// Convenience macro to define the native program entrypoint. Supply a fn to this macro that
// conforms to the `Entrypoint` type signature.
@ -23,29 +62,8 @@ macro_rules! solana_entrypoint(
keyed_accounts: &mut [KeyedAccount],
data: &[u8],
tick_height: u64
) -> bool {
return $entrypoint(program_id, keyed_accounts, data, tick_height);
) -> Result<(), ProgramError> {
$entrypoint(program_id, keyed_accounts, data, tick_height)
}
)
);
/// Reasons a program might have rejected an instruction.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ProgramError {
/// Contract's transactions resulted in an account with a negative balance
/// The difference from InsufficientFundsForFee is that the transaction was executed by the
/// contract
ResultWithNegativeTokens,
/// The program returned an error
GenericError,
/// Program's instruction token balance does not equal the balance after the instruction
UnbalancedInstruction,
/// Program modified an account's program id
ModifiedProgramId,
/// Program spent the tokens of an account that doesn't belong to it
ExternalAccountTokenSpend,
}

View File

@ -1,7 +1,5 @@
use pubkey::Pubkey;
pub const SYSTEM_PROGRAM_ID: [u8; 32] = [0u8; 32];
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum SystemInstruction {
/// Create a new account

11
sdk/src/system_program.rs Normal file
View File

@ -0,0 +1,11 @@
use pubkey::Pubkey;
pub const SYSTEM_PROGRAM_ID: [u8; 32] = [0u8; 32];
pub fn id() -> Pubkey {
Pubkey::new(&SYSTEM_PROGRAM_ID)
}
pub fn check_id(program_id: &Pubkey) -> bool {
program_id.as_ref() == SYSTEM_PROGRAM_ID
}