Add convenience macro for native program entrypoint
This commit is contained in:
parent
e33f3a2562
commit
0bf2ff6138
|
@ -7,6 +7,7 @@ extern crate env_logger;
|
|||
extern crate log;
|
||||
extern crate libc;
|
||||
extern crate solana_rbpf;
|
||||
#[macro_use]
|
||||
extern crate solana_sdk;
|
||||
|
||||
use bincode::deserialize;
|
||||
|
@ -135,8 +136,8 @@ fn deserialize_parameters(keyed_accounts: &mut [KeyedAccount], buffer: &[u8]) {
|
|||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||
static INIT: Once = ONCE_INIT;
|
||||
INIT.call_once(|| {
|
||||
// env_logger can only be initialized once
|
||||
|
|
|
@ -7,6 +7,7 @@ extern crate log;
|
|||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate solana_sdk;
|
||||
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
|
@ -14,8 +15,8 @@ use std::sync::{Once, ONCE_INIT};
|
|||
|
||||
mod token_program;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn process(info: &mut [KeyedAccount], input: &[u8]) -> bool {
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(info: &mut [KeyedAccount], input: &[u8]) -> bool {
|
||||
// env_logger can only be initialized once
|
||||
static INIT: Once = ONCE_INIT;
|
||||
INIT.call_once(env_logger::init);
|
||||
|
|
|
@ -3,6 +3,7 @@ extern crate env_logger;
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate rlua;
|
||||
#[macro_use]
|
||||
extern crate solana_sdk;
|
||||
|
||||
use bincode::deserialize;
|
||||
|
@ -51,8 +52,8 @@ fn run_lua(keyed_accounts: &mut [KeyedAccount], code: &str, data: &[u8]) -> Resu
|
|||
update_accounts(&lua, "accounts", keyed_accounts)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||
static INIT: Once = ONCE_INIT;
|
||||
INIT.call_once(|| {
|
||||
// env_logger can only be initialized once
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate solana_sdk;
|
||||
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool {
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool {
|
||||
println!("noop: keyed_accounts: {:#?}", keyed_accounts);
|
||||
println!("noop: data: {:?}", data);
|
||||
true
|
||||
|
|
|
@ -6,3 +6,15 @@ pub const ENTRYPOINT: &str = "process";
|
|||
// Native program ENTRYPOINT prototype
|
||||
pub type Entrypoint =
|
||||
unsafe extern "C" fn(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool;
|
||||
|
||||
// Convenience macro to define the native program entrypoint. Supply a fn to this macro that
|
||||
// conforms to the `Entrypoint` type signature.
|
||||
#[macro_export]
|
||||
macro_rules! solana_entrypoint(
|
||||
($entrypoint:ident) => (
|
||||
#[no_mangle]
|
||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool {
|
||||
return $entrypoint(keyed_accounts, data);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue