Proposal: log binary data for Solidity
The program_id is not needed on "Program return data: " because it always preceeded by the program invoke message, so no need to repeat the program id. Also rename this to "Program return: " since "data" is redundant.
This commit is contained in:
23
programs/bpf/rust/log_data/Cargo.toml
Normal file
23
programs/bpf/rust/log_data/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-log-data"
|
||||
version = "1.8.0"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
documentation = "https://docs.rs/solana-bpf-rust-log-data"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.8.0" }
|
||||
|
||||
[features]
|
||||
default = ["program"]
|
||||
program = []
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
24
programs/bpf/rust/log_data/src/lib.rs
Normal file
24
programs/bpf/rust/log_data/src/lib.rs
Normal file
@ -0,0 +1,24 @@
|
||||
//! @brief Example Rust-based BPF program that uses sol_log_data syscall
|
||||
|
||||
#![cfg(feature = "program")]
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, log::sol_log_data,
|
||||
program::set_return_data, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_accounts: &[AccountInfo],
|
||||
instruction_data: &[u8],
|
||||
) -> ProgramResult {
|
||||
let fields: Vec<&[u8]> = instruction_data.split(|e| *e == 0).collect();
|
||||
|
||||
set_return_data(&[0x08, 0x01, 0x44]);
|
||||
|
||||
sol_log_data(&fields);
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user