Update rust example to use BPF enabled infrastructure (#2974)

This commit is contained in:
Jack May
2019-02-28 22:05:11 -08:00
committed by GitHub
parent 6b228df3df
commit b9524217fe
11 changed files with 173 additions and 183 deletions

View File

@@ -7,6 +7,17 @@ mod solana_sdk;
use solana_sdk::*;
struct SStruct {
x: u64,
y: u64,
z: u64,
}
#[inline(never)]
fn return_sstruct() -> SStruct {
SStruct { x: 1, y: 2, z: 3 }
}
fn process(ka: &mut [SolKeyedAccount], data: &[u8], info: &SolClusterInfo) -> bool {
sol_log("Tick height:");
sol_log_64(info.tick_height, 0, 0, 0, 0);
@@ -18,5 +29,27 @@ fn process(ka: &mut [SolKeyedAccount], data: &[u8], info: &SolClusterInfo) -> bo
// programs will have specific requirements so they can do their work.
sol_log("Account keys and instruction input data:");
sol_log_params(ka, data);
{
// Test - use core methods, unwrap
// valid bytes, in a stack-allocated array
let sparkle_heart = [240, 159, 146, 150];
let result_str = core::str::from_utf8(&sparkle_heart).unwrap();
sol_log_64(0, 0, 0, 0, result_str.len() as u64);
sol_log(result_str);
assert_eq!("💖", result_str);
}
{
// Test - struct return
let s = return_sstruct();
sol_log_64(0, 0, s.x, s.y, s.z);
assert_eq!(s.x + s.y + s.z, 6);
}
sol_log("Success");
true
}