Expose tick_height to native programs
This commit is contained in:
parent
0bf2ff6138
commit
5a8938209b
|
@ -137,7 +137,7 @@ fn deserialize_parameters(keyed_accounts: &mut [KeyedAccount], buffer: &[u8]) {
|
|||
}
|
||||
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8], _tick_height: u64) -> bool {
|
||||
static INIT: Once = ONCE_INIT;
|
||||
INIT.call_once(|| {
|
||||
// env_logger can only be initialized once
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::sync::{Once, ONCE_INIT};
|
|||
mod token_program;
|
||||
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(info: &mut [KeyedAccount], input: &[u8]) -> bool {
|
||||
fn entrypoint(info: &mut [KeyedAccount], input: &[u8], _tick_height: u64) -> bool {
|
||||
// env_logger can only be initialized once
|
||||
static INIT: Once = ONCE_INIT;
|
||||
INIT.call_once(env_logger::init);
|
||||
|
|
|
@ -53,7 +53,7 @@ fn run_lua(keyed_accounts: &mut [KeyedAccount], code: &str, data: &[u8]) -> Resu
|
|||
}
|
||||
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8], _tick_height: u64) -> bool {
|
||||
static INIT: Once = ONCE_INIT;
|
||||
INIT.call_once(|| {
|
||||
// env_logger can only be initialized once
|
||||
|
@ -174,11 +174,11 @@ mod tests {
|
|||
(bob_pubkey, Account::new(1, 0, owner)),
|
||||
];
|
||||
let data = serialize(&10u64).unwrap();
|
||||
process(&mut create_keyed_accounts(&mut accounts), &data);
|
||||
process(&mut create_keyed_accounts(&mut accounts), &data, 0);
|
||||
assert_eq!(accounts[1].1.tokens, 90);
|
||||
assert_eq!(accounts[2].1.tokens, 11);
|
||||
|
||||
process(&mut create_keyed_accounts(&mut accounts), &data);
|
||||
process(&mut create_keyed_accounts(&mut accounts), &data, 0);
|
||||
assert_eq!(accounts[1].1.tokens, 80);
|
||||
assert_eq!(accounts[2].1.tokens, 21);
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ mod tests {
|
|||
(Pubkey::default(), Account::new(1, 0, owner)),
|
||||
];
|
||||
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
||||
process(&mut keyed_accounts, &[]);
|
||||
process(&mut keyed_accounts, &[], 0);
|
||||
// Verify deterministic ordering of a serialized Lua table.
|
||||
assert_eq!(
|
||||
str::from_utf8(&keyed_accounts[3].account.userdata).unwrap(),
|
||||
|
@ -281,19 +281,19 @@ mod tests {
|
|||
).as_bytes()
|
||||
.to_vec();
|
||||
|
||||
process(&mut keyed_accounts, &data);
|
||||
process(&mut keyed_accounts, &data, 0);
|
||||
assert_eq!(keyed_accounts[4].account.tokens, 1);
|
||||
|
||||
let data = format!(r#""{}""#, carol_pubkey).into_bytes();
|
||||
process(&mut keyed_accounts, &data);
|
||||
process(&mut keyed_accounts, &data, 0);
|
||||
assert_eq!(keyed_accounts[4].account.tokens, 1);
|
||||
|
||||
let data = format!(r#""{}""#, dan_pubkey).into_bytes();
|
||||
process(&mut keyed_accounts, &data);
|
||||
process(&mut keyed_accounts, &data, 0);
|
||||
assert_eq!(keyed_accounts[4].account.tokens, 101); // Pay day!
|
||||
|
||||
let data = format!(r#""{}""#, erin_pubkey).into_bytes();
|
||||
process(&mut keyed_accounts, &data);
|
||||
process(&mut keyed_accounts, &data, 0);
|
||||
assert_eq!(keyed_accounts[4].account.tokens, 101); // No change!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ extern crate solana_sdk;
|
|||
use solana_sdk::account::KeyedAccount;
|
||||
|
||||
solana_entrypoint!(entrypoint);
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool {
|
||||
fn entrypoint(keyed_accounts: &mut [KeyedAccount], data: &[u8], tick_height: u64) -> bool {
|
||||
println!("noop: keyed_accounts: {:#?}", keyed_accounts);
|
||||
println!("noop: data: {:?}", data);
|
||||
println!("noop: tick_height: {:?}", tick_height);
|
||||
true
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ pub const ENTRYPOINT: &str = "process";
|
|||
|
||||
// Native program ENTRYPOINT prototype
|
||||
pub type Entrypoint =
|
||||
unsafe extern "C" fn(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> bool;
|
||||
unsafe extern "C" fn(keyed_accounts: &mut [KeyedAccount], data: &[u8], tick_height: u64)
|
||||
-> bool;
|
||||
|
||||
// Convenience macro to define the native program entrypoint. Supply a fn to this macro that
|
||||
// conforms to the `Entrypoint` type signature.
|
||||
|
@ -13,8 +14,8 @@ pub type Entrypoint =
|
|||
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);
|
||||
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], data: &[u8], tick_height: u64) -> bool {
|
||||
return $entrypoint(keyed_accounts, data, tick_height);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
|
@ -846,6 +846,7 @@ impl Bank {
|
|||
if !native_loader::process_instruction(
|
||||
&mut keyed_accounts,
|
||||
&tx.instructions[instruction_index].userdata,
|
||||
self.tick_height(),
|
||||
) {
|
||||
return Err(BankError::ProgramRuntimeError(instruction_index as u8));
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ pub fn process_instruction(
|
|||
return false;
|
||||
}
|
||||
};
|
||||
return entrypoint(&mut keyed_accounts[1..], ix_userdata);
|
||||
return entrypoint(&mut keyed_accounts[1..], ix_userdata, tick_height);
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Unable to load: {:?}", e);
|
||||
|
|
Loading…
Reference in New Issue