Add convenience macro for native program entrypoint
This commit is contained in:
@ -7,6 +7,7 @@ extern crate env_logger;
|
|||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate solana_rbpf;
|
extern crate solana_rbpf;
|
||||||
|
#[macro_use]
|
||||||
extern crate solana_sdk;
|
extern crate solana_sdk;
|
||||||
|
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
@ -135,8 +136,8 @@ fn deserialize_parameters(keyed_accounts: &mut [KeyedAccount], buffer: &[u8]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
solana_entrypoint!(entrypoint);
|
||||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||||
static INIT: Once = ONCE_INIT;
|
static INIT: Once = ONCE_INIT;
|
||||||
INIT.call_once(|| {
|
INIT.call_once(|| {
|
||||||
// env_logger can only be initialized once
|
// env_logger can only be initialized once
|
||||||
|
@ -7,6 +7,7 @@ extern crate log;
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
#[macro_use]
|
||||||
extern crate solana_sdk;
|
extern crate solana_sdk;
|
||||||
|
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
@ -14,8 +15,8 @@ use std::sync::{Once, ONCE_INIT};
|
|||||||
|
|
||||||
mod token_program;
|
mod token_program;
|
||||||
|
|
||||||
#[no_mangle]
|
solana_entrypoint!(entrypoint);
|
||||||
pub extern "C" fn process(info: &mut [KeyedAccount], input: &[u8]) -> bool {
|
fn entrypoint(info: &mut [KeyedAccount], input: &[u8]) -> bool {
|
||||||
// env_logger can only be initialized once
|
// env_logger can only be initialized once
|
||||||
static INIT: Once = ONCE_INIT;
|
static INIT: Once = ONCE_INIT;
|
||||||
INIT.call_once(env_logger::init);
|
INIT.call_once(env_logger::init);
|
||||||
|
@ -3,6 +3,7 @@ extern crate env_logger;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate rlua;
|
extern crate rlua;
|
||||||
|
#[macro_use]
|
||||||
extern crate solana_sdk;
|
extern crate solana_sdk;
|
||||||
|
|
||||||
use bincode::deserialize;
|
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)
|
update_accounts(&lua, "accounts", keyed_accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
solana_entrypoint!(entrypoint);
|
||||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||||
static INIT: Once = ONCE_INIT;
|
static INIT: Once = ONCE_INIT;
|
||||||
INIT.call_once(|| {
|
INIT.call_once(|| {
|
||||||
// env_logger can only be initialized once
|
// env_logger can only be initialized once
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
#[macro_use]
|
||||||
extern crate solana_sdk;
|
extern crate solana_sdk;
|
||||||
|
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
|
|
||||||
#[no_mangle]
|
solana_entrypoint!(entrypoint);
|
||||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool {
|
fn entrypoint(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool {
|
||||||
println!("noop: keyed_accounts: {:#?}", keyed_accounts);
|
println!("noop: keyed_accounts: {:#?}", keyed_accounts);
|
||||||
println!("noop: data: {:?}", data);
|
println!("noop: data: {:?}", data);
|
||||||
true
|
true
|
||||||
|
@ -6,3 +6,15 @@ pub const ENTRYPOINT: &str = "process";
|
|||||||
// Native program ENTRYPOINT prototype
|
// Native program ENTRYPOINT prototype
|
||||||
pub type Entrypoint =
|
pub type Entrypoint =
|
||||||
unsafe extern "C" fn(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool;
|
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);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
Reference in New Issue
Block a user