Proposal: log binary data for Solidity

Rename "Program return data: " to "Program return: " since "data" is
redundant.

(cherry picked from commit b89177c8de)

Conflicts:
	programs/bpf_loader/src/syscalls.rs
	sdk/bpf/c/inc/sol/log.h
	sdk/program/Cargo.toml
	sdk/src/feature_set.rs
	sdk/src/process_instruction.rs
This commit is contained in:
Sean Young
2021-09-17 09:14:49 +01:00
parent 400a88786a
commit ebe77a0985
17 changed files with 429 additions and 8 deletions

View File

@@ -36,10 +36,12 @@ thiserror = "1.0"
[target.'cfg(not(target_arch = "bpf"))'.dependencies]
blake3 = "0.3.7"
base64 = "0.13"
curve25519-dalek = "2.1.0"
libsecp256k1 = "0.5.0"
rand = "0.7.0"
solana-logger = { path = "../../logger", version = "=1.8.1" }
itertools = "0.9.0"
[dev-dependencies]
static_assertions = "1.1.0"

View File

@@ -85,6 +85,23 @@ extern "C" {
fn sol_log_64_(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64);
}
/// Print some slices as base64
///
/// @param data - The slices to print
pub fn sol_log_data(data: &[&[u8]]) {
#[cfg(target_arch = "bpf")]
{
extern "C" {
fn sol_log_data(data: *const u8, data_len: u64);
}
unsafe { sol_log_data(data as *const _ as *const u8, data.len() as u64) };
}
#[cfg(not(target_arch = "bpf"))]
crate::program_stubs::sol_log_data(data);
}
/// Print the hexadecimal representation of a slice
///
/// @param slice - The array to print

View File

@@ -6,6 +6,7 @@ use crate::{
account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction,
program_error::UNSUPPORTED_SYSVAR, pubkey::Pubkey,
};
use itertools::Itertools;
use std::sync::{Arc, RwLock};
lazy_static::lazy_static! {
@@ -51,7 +52,7 @@ pub trait SyscallStubs: Sync + Send {
unsafe fn sol_memcpy(&self, dst: *mut u8, src: *const u8, n: usize) {
// cannot be overlapping
if dst as usize + n > src as usize && src as usize > dst as usize {
panic!("memcpy does not support oveerlapping regions");
panic!("memcpy does not support overlapping regions");
}
std::ptr::copy_nonoverlapping(src, dst, n as usize);
}
@@ -84,6 +85,9 @@ pub trait SyscallStubs: Sync + Send {
None
}
fn sol_set_return_data(&mut self, _data: &[u8]) {}
fn sol_log_data(&self, fields: &[&[u8]]) {
println!("data: {}", fields.iter().map(base64::encode).join(" "));
}
}
struct DefaultSyscallStubs {}
@@ -165,3 +169,7 @@ pub(crate) fn sol_get_return_data() -> Option<(Pubkey, Vec<u8>)> {
pub(crate) fn sol_set_return_data(data: &[u8]) {
SYSCALL_STUBS.write().unwrap().sol_set_return_data(data)
}
pub(crate) fn sol_log_data(data: &[&[u8]]) {
SYSCALL_STUBS.read().unwrap().sol_log_data(data)
}