fix: update examples (#485)
This commit is contained in:
@ -5,15 +5,15 @@
|
|||||||
|
|
||||||
#include <solana_sdk.h>
|
#include <solana_sdk.h>
|
||||||
|
|
||||||
extern bool entrypoint(const uint8_t *input) {
|
extern uint32_t entrypoint(const uint8_t *input) {
|
||||||
SolKeyedAccount ka[1];
|
SolKeyedAccount ka[1];
|
||||||
SolParameters params = (SolParameters) { .ka = ka };
|
SolParameters params = (SolParameters) { .ka = ka };
|
||||||
|
|
||||||
sol_log("Hello World");
|
sol_log("Hello World");
|
||||||
|
|
||||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||||
return false;
|
return 1;
|
||||||
}
|
}
|
||||||
sol_log_params(¶ms);
|
sol_log_params(¶ms);
|
||||||
return true;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "solana-bpf-rust-noop"
|
name = "solana-bpf-rust-noop"
|
||||||
version = "0.16.0"
|
version = "0.19.0-pre0"
|
||||||
description = "Solana BPF noop program written in Rust"
|
description = "Solana BPF noop program written in Rust"
|
||||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||||
repository = "https://github.com/solana-labs/solana"
|
repository = "https://github.com/solana-labs/solana"
|
||||||
@ -12,11 +12,11 @@ homepage = "https://solana.com/"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
solana-sdk-bpf-utils = { path = "../../bpf-sdk/rust/rust-utils" }
|
solana-sdk = { git = "https://github.com/solana-labs/solana", default-features = false }
|
||||||
solana-sdk-bpf-no-std = { path = "../../bpf-sdk/rust/rust-no-std" }
|
|
||||||
|
|
||||||
[dev_dependencies]
|
[features]
|
||||||
solana-sdk-bpf-test = { path = "../../bpf-sdk/rust/rust-test"}
|
program = ["solana-sdk/program"]
|
||||||
|
default = ["program"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = []
|
members = []
|
||||||
|
@ -1,6 +1,2 @@
|
|||||||
[dependencies.compiler_builtins]
|
[target.bpfel-unknown-unknown.dependencies.std]
|
||||||
path = "../../bpf-sdk/dependencies/rust-bpf-sysroot/src/compiler-builtins"
|
features = []
|
||||||
features = ["c", "mem"]
|
|
||||||
|
|
||||||
[target.bpfel-unknown-unknown.dependencies]
|
|
||||||
alloc = { path = "../../bpf-sdk/dependencies/rust-bpf-sysroot/src/liballoc" }
|
|
@ -20,26 +20,37 @@ Supported actions:
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sdkDir=../../bpf-sdk
|
||||||
|
targetDir="$PWD"/target
|
||||||
|
profile=bpfel-unknown-unknown/release
|
||||||
|
|
||||||
perform_action() {
|
perform_action() {
|
||||||
set -e
|
set -e
|
||||||
case "$1" in
|
case "$1" in
|
||||||
build)
|
build)
|
||||||
../../bpf-sdk/rust/build.sh "$PWD"
|
"$sdkDir"/rust/build.sh "$PWD"
|
||||||
|
|
||||||
|
so_path="$targetDir/$profile"
|
||||||
|
so_name="solana_bpf_rust_noop"
|
||||||
|
if [ -f "$so_path/${so_name}.so" ]; then
|
||||||
|
cp "$so_path/${so_name}.so" "$so_path/${so_name}_debug.so"
|
||||||
|
"$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/$so_name.so"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
clean)
|
clean)
|
||||||
../../bpf-sdk/rust/clean.sh "$PWD"
|
"$sdkDir"/rust/clean.sh "$PWD"
|
||||||
;;
|
;;
|
||||||
test)
|
test)
|
||||||
echo "test $2"
|
echo "test"
|
||||||
cargo +nightly test
|
cargo +nightly test
|
||||||
;;
|
;;
|
||||||
clippy)
|
clippy)
|
||||||
echo "clippy $2"
|
echo "clippy"
|
||||||
cargo +nightly clippy
|
cargo +nightly clippy
|
||||||
;;
|
;;
|
||||||
fmt)
|
fmt)
|
||||||
echo "formatting $2"
|
echo "formatting"
|
||||||
cargo fmt
|
cargo fmt
|
||||||
;;
|
;;
|
||||||
help)
|
help)
|
||||||
usage
|
usage
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
#![allow(unreachable_code)]
|
#![allow(unreachable_code)]
|
||||||
#![allow(unused_attributes)]
|
|
||||||
|
|
||||||
#[cfg(not(test))]
|
extern crate solana_sdk;
|
||||||
extern crate solana_sdk_bpf_no_std;
|
use solana_sdk::{
|
||||||
extern crate solana_sdk_bpf_utils;
|
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, log::*, pubkey::Pubkey,
|
||||||
|
};
|
||||||
use solana_sdk_bpf_utils::entrypoint::*;
|
|
||||||
use solana_sdk_bpf_utils::log::*;
|
|
||||||
use solana_sdk_bpf_utils::{entrypoint, info};
|
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
struct SStruct {
|
struct SStruct {
|
||||||
x: u64,
|
x: u64,
|
||||||
y: u64,
|
y: u64,
|
||||||
@ -24,28 +20,22 @@ fn return_sstruct() -> SStruct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entrypoint!(process_instruction);
|
entrypoint!(process_instruction);
|
||||||
fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data: &[u8]) -> bool {
|
fn process_instruction(program_id: &Pubkey, accounts: &mut [AccountInfo], data: &[u8]) -> u32 {
|
||||||
info!("Program identifier:");
|
info!("Program identifier:");
|
||||||
sol_log_key(&info.program_id);
|
program_id.log();
|
||||||
|
|
||||||
// Log the provided account keys and instruction input data. In the case of
|
// Log the provided account keys and instruction input data. In the case of
|
||||||
// the no-op program, no account keys or input data are expected but real
|
// the no-op program, no account keys or input data are expected but real
|
||||||
// programs will have specific requirements so they can do their work.
|
// programs will have specific requirements so they can do their work.
|
||||||
info!("Account keys and instruction input data:");
|
info!("Account keys and instruction input data:");
|
||||||
sol_log_params(ka, data);
|
sol_log_params(accounts, data);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Test - arch config
|
// Test - use std methods, unwrap
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
|
||||||
panic!();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Test - use core methods, unwrap
|
|
||||||
|
|
||||||
// valid bytes, in a stack-allocated array
|
// valid bytes, in a stack-allocated array
|
||||||
let sparkle_heart = [240, 159, 146, 150];
|
let sparkle_heart = [240, 159, 146, 150];
|
||||||
let result_str = core::str::from_utf8(&sparkle_heart).unwrap();
|
let result_str = std::str::from_utf8(&sparkle_heart).unwrap();
|
||||||
assert_eq!(4, result_str.len());
|
assert_eq!(4, result_str.len());
|
||||||
assert_eq!("💖", result_str);
|
assert_eq!("💖", result_str);
|
||||||
info!(result_str);
|
info!(result_str);
|
||||||
@ -58,6 +48,21 @@ fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data:
|
|||||||
assert_eq!(s.x + s.y + s.z, 6);
|
assert_eq!(s.x + s.y + s.z, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Success");
|
{
|
||||||
true
|
// Test - arch config
|
||||||
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
|
||||||
|
SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_return_sstruct() {
|
||||||
|
assert_eq!(SStruct { x: 1, y: 2, z: 3 }, return_sstruct());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
web3.js/test/fixtures/noop-c/noop.so
vendored
BIN
web3.js/test/fixtures/noop-c/noop.so
vendored
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user