Merge native programs parts into one unit (#7047)

This commit is contained in:
Jack May
2019-11-20 10:12:43 -08:00
committed by GitHub
parent 42da1ce4e2
commit d184d3a732
71 changed files with 244 additions and 335 deletions

View File

@ -8,7 +8,7 @@ pub use crate::clock::{Epoch, Slot, DEFAULT_SLOTS_PER_EPOCH};
/// the beginning of epoch X - 1.
pub const DEFAULT_LEADER_SCHEDULE_SLOT_OFFSET: u64 = DEFAULT_SLOTS_PER_EPOCH;
/// based on MAX_LOCKOUT_HISTORY from vote_api
/// based on MAX_LOCKOUT_HISTORY from vote_program
pub const MINIMUM_SLOTS_PER_EPOCH: u64 = 32;
#[repr(C)]

View File

@ -11,6 +11,7 @@ pub type Entrypoint = unsafe extern "C" fn(
data: &[u8],
) -> Result<(), InstructionError>;
// Deprecated
// Convenience macro to define the native program entrypoint. Supply a fn to this macro that
// conforms to the `Entrypoint` type signature.
#[macro_export]
@ -27,6 +28,65 @@ macro_rules! solana_entrypoint(
)
);
/// Convenience macro to declare a native program
///
/// id: Variable containing the program's id (public key bytes)
/// bs58: BS58 encoding of the id, used verify check the id bytes
/// name: Name of the program, must match the library name in Cargo.toml
/// entrypoint: Program's entrypoint, must be of `type Entrypoint`
///
/// # Examples
///
/// ```
/// use solana_sdk::account::KeyedAccount;
/// use solana_sdk::instruction::InstructionError;
/// use solana_sdk::pubkey::Pubkey;
/// use solana_sdk::declare_program;
///
/// const MY_PROGRAM_ID: [u8; 32] = [
/// 6, 161, 216, 23, 145, 55, 84, 42, 152, 52, 55, 189, 254, 42, 122, 178, 85, 127, 83, 92, 138,
/// 120, 114, 43, 104, 164, 157, 192, 0, 0, 0, 0,
/// ];
///
/// fn my_process_instruction(
/// program_id: &Pubkey,
/// keyed_accounts: &mut [KeyedAccount],
/// data: &[u8],
/// ) -> Result<(), InstructionError> {
/// // Process an instruction
/// Ok(())
/// }
///
/// solana_sdk::declare_program!(
/// MY_PROGRAM_ID,
/// "My!!!11111111111111111111111111111111111111",
/// solana_my_program,
/// my_process_instruction
/// );
/// ```
#[macro_export]
macro_rules! declare_program(
($id:ident, $bs58:expr, $name:ident, $entrypoint:ident) => (
$crate::solana_name_id!($id, $bs58);
#[macro_export]
macro_rules! $name {
() => {
(stringify!($name).to_string(), $crate::id())
};
}
#[no_mangle]
pub extern "C" fn $name(
program_id: &$crate::pubkey::Pubkey,
keyed_accounts: &mut [$crate::account::KeyedAccount],
data: &[u8],
) -> Result<(), $crate::instruction::InstructionError> {
$entrypoint(program_id, keyed_accounts, data)
}
)
);
impl<T> From<T> for InstructionError
where
T: ToPrimitive,