Cleanup usage of feature "program" (#7712)

This commit is contained in:
Jack May
2020-01-08 13:49:35 -08:00
committed by GitHub
parent 57858b8015
commit 09cff5e4cc
8 changed files with 93 additions and 26 deletions

View File

@ -1,5 +1,4 @@
use crate::{account::Account, pubkey::Pubkey};
use std::{cmp, fmt};
/// AccountInfo

View File

@ -1,5 +1,7 @@
//! @brief Solana Rust-based BPF program entrypoint and its parameter types
#![cfg(feature = "program")]
extern crate alloc;
use crate::{account_info::AccountInfo, pubkey::Pubkey};

View File

@ -117,10 +117,7 @@ pub fn limited_deserialize<T>(data: &[u8]) -> Result<T, InstructionError>
where
T: serde::de::DeserializeOwned,
{
#[cfg(not(feature = "program"))]
let limit = crate::packet::PACKET_DATA_SIZE as u64;
#[cfg(feature = "program")]
let limit = 1024;
bincode::config()
.limit(limit)
.deserialize(data)

View File

@ -2,9 +2,11 @@
extern crate self as solana_sdk;
pub mod account;
pub mod account_info;
pub mod account_utils;
pub mod bpf_loader;
pub mod clock;
pub mod commitment_config;
pub mod epoch_schedule;
pub mod fee_calculator;
pub mod hash;
@ -54,7 +56,6 @@ pub mod timing;
pub use solana_sdk_macro::declare_id;
// On-chain program specific modules
pub mod account_info;
pub mod entrypoint;
pub mod log;
@ -64,8 +65,6 @@ pub mod bank_hash;
#[cfg(not(feature = "program"))]
pub mod client;
#[cfg(not(feature = "program"))]
pub mod commitment_config;
#[cfg(not(feature = "program"))]
pub mod genesis_config;
#[cfg(not(feature = "program"))]
pub mod signature;

View File

@ -1,6 +1,8 @@
//! @brief Solana Rust-based BPF program logging
use crate::account_info::AccountInfo;
#![cfg(feature = "program")]
use crate::{account_info::AccountInfo, pubkey::Pubkey};
/// Prints a string
/// There are two forms and are fast
@ -27,37 +29,29 @@ macro_rules! info {
/// Prints a string to stdout
///
/// @param message - Message to print
#[cfg(feature = "program")]
#[inline]
pub fn sol_log(message: &str) {
unsafe {
sol_log_(message.as_ptr(), message.len() as u64);
}
}
#[cfg(feature = "program")]
extern "C" {
fn sol_log_(message: *const u8, length: u64);
}
#[cfg(not(feature = "program"))]
pub fn sol_log(_message: &str) {}
/// Prints 64 bit values represented as hexadecimal to stdout
///
/// @param argx - integer arguments to print
#[cfg(feature = "program")]
#[inline]
pub fn sol_log_64(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64) {
unsafe {
sol_log_64_(arg1, arg2, arg3, arg4, arg5);
}
}
#[cfg(feature = "program")]
extern "C" {
fn sol_log_64_(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64);
}
#[cfg(not(feature = "program"))]
pub fn sol_log_64(_arg1: u64, _arg2: u64, _arg3: u64, _arg4: u64, _arg5: u64) {}
/// Prints the hexadecimal representation of a slice
///
@ -69,6 +63,18 @@ pub fn sol_log_slice(slice: &[u8]) {
}
}
/// Prints a pubkey
pub trait Log {
fn log(&self);
}
impl Log for Pubkey {
fn log(&self) {
for (i, k) in self.to_bytes().iter().enumerate() {
sol_log_64(0, 0, 0, i as u64, u64::from(*k));
}
}
}
/// Prints the hexadecimal representation of the program's input parameters
///
/// @param ka - A pointer to an array of `AccountInfo` to print

View File

@ -56,12 +56,6 @@ impl Pubkey {
Self::new(&rand::random::<[u8; 32]>())
}
pub fn log(&self) {
use crate::log::sol_log_64;
for (i, k) in self.0.iter().enumerate() {
sol_log_64(0, 0, 0, i as u64, u64::from(*k));
}
}
pub fn to_bytes(self) -> [u8; 32] {
self.0
}