From 59f7f2ffd733404a8c21e875c17d9183d462d391 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Thu, 21 Mar 2019 14:51:23 -0700 Subject: [PATCH] try to reduce boilerplate --- programs/budget/src/lib.rs | 6 +----- sdk/src/native_program.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/programs/budget/src/lib.rs b/programs/budget/src/lib.rs index 6cf66ffe41daf2..0bb0fc2cf8cfeb 100644 --- a/programs/budget/src/lib.rs +++ b/programs/budget/src/lib.rs @@ -1,5 +1 @@ -mod budget_processor; - -use crate::budget_processor::process_instruction; - -solana_sdk::process_instruction_entrypoint!(process_instruction); +solana_sdk::processor_entrypoint!(budget_processor); diff --git a/sdk/src/native_program.rs b/sdk/src/native_program.rs index 86c28cc918b616..730b43171a2984 100644 --- a/sdk/src/native_program.rs +++ b/sdk/src/native_program.rs @@ -49,3 +49,25 @@ macro_rules! process_instruction_entrypoint( } ) ); + +// Macro to define an entrypoint for a processor module +#[macro_export] +macro_rules! processor_entrypoint( + ($processor:ident) => ( + mod $processor; + + solana_sdk::solana_entrypoint!(process_instruction_entrypoint); + fn process_instruction_entrypoint( + program_id: &solana_sdk::pubkey::Pubkey, + keyed_accounts: &mut [solana_sdk::account::KeyedAccount], + data: &[u8], + tick_height: u64, + ) -> Result<(), solana_sdk::transaction::InstructionError> { + solana_logger::setup(); + + log::trace!("process_instruction: {:?}", data); + log::trace!("keyed_accounts: {:?}", keyed_accounts); + crate::$processor::process_instruction(program_id, keyed_accounts, data, tick_height) + } + ) +);