Switch programs to use Pubkey from SolPubkey (#5821)
This commit is contained in:
parent
6057768fdc
commit
d9817c153a
|
@ -22,7 +22,7 @@ fn return_sstruct() -> SStruct {
|
|||
entrypoint!(process_instruction);
|
||||
fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data: &[u8]) -> bool {
|
||||
info!("Program identifier:");
|
||||
sol_log_key(&info.program_id);
|
||||
info.program_id.log();
|
||||
|
||||
// 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
|
||||
|
|
|
@ -4,14 +4,12 @@ extern crate alloc;
|
|||
use alloc::vec::Vec;
|
||||
use core::mem::size_of;
|
||||
use core::slice::{from_raw_parts, from_raw_parts_mut};
|
||||
|
||||
/// Public key
|
||||
pub type SolPubkey = [u8; 32];
|
||||
use crate::pubkey::Pubkey;
|
||||
|
||||
/// Keyed Account
|
||||
pub struct SolKeyedAccount<'a> {
|
||||
/// Public key of the account
|
||||
pub key: &'a SolPubkey,
|
||||
pub key: &'a Pubkey,
|
||||
/// Public key of the account
|
||||
pub is_signer: bool,
|
||||
/// Number of lamports owned by this account
|
||||
|
@ -19,14 +17,14 @@ pub struct SolKeyedAccount<'a> {
|
|||
/// On-chain data within this account
|
||||
pub data: &'a mut [u8],
|
||||
/// Program that owns this account
|
||||
pub owner: &'a SolPubkey,
|
||||
pub owner: &'a Pubkey,
|
||||
}
|
||||
|
||||
/// Information about the state of the cluster immediately before the program
|
||||
/// started executing the current instruction
|
||||
pub struct SolClusterInfo<'a> {
|
||||
/// program_id of the currently executing program
|
||||
pub program_id: &'a SolPubkey,
|
||||
pub program_id: &'a Pubkey,
|
||||
}
|
||||
|
||||
/// Declare entrypoint of the program.
|
||||
|
@ -75,8 +73,8 @@ pub unsafe fn deserialize<'a>(
|
|||
};
|
||||
offset += size_of::<u64>();
|
||||
|
||||
let key: &SolPubkey = &*(input.add(offset) as *const [u8; size_of::<SolPubkey>()]);
|
||||
offset += size_of::<SolPubkey>();
|
||||
let key: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let lamports = &mut *(input.add(offset) as *mut u64);
|
||||
|
@ -89,8 +87,8 @@ pub unsafe fn deserialize<'a>(
|
|||
let data = { from_raw_parts_mut(input.add(offset), data_length) };
|
||||
offset += data_length;
|
||||
|
||||
let owner: &SolPubkey = &*(input.add(offset) as *const [u8; size_of::<SolPubkey>()]);
|
||||
offset += size_of::<SolPubkey>();
|
||||
let owner: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
kas.push(SolKeyedAccount {
|
||||
key,
|
||||
|
@ -112,7 +110,7 @@ pub unsafe fn deserialize<'a>(
|
|||
|
||||
// Program Id
|
||||
|
||||
let program_id: &SolPubkey = &*(input.add(offset) as *const [u8; size_of::<SolPubkey>()]);
|
||||
let program_id: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
let info = SolClusterInfo { program_id };
|
||||
|
||||
Ok((kas, info, data))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! @brief Solana Rust-based BPF program logging
|
||||
|
||||
use crate::entrypoint::{SolKeyedAccount, SolPubkey};
|
||||
use crate::entrypoint::SolKeyedAccount;
|
||||
|
||||
/// Prints a string
|
||||
/// There are two forms and are fast
|
||||
|
@ -48,16 +48,6 @@ extern "C" {
|
|||
fn sol_log_64_(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64);
|
||||
}
|
||||
|
||||
/// Prints the hexadecimal representation of a public key
|
||||
///
|
||||
/// @param - key The public key to print
|
||||
#[allow(dead_code)]
|
||||
pub fn sol_log_key(key: &SolPubkey) {
|
||||
for (i, k) in key.iter().enumerate() {
|
||||
sol_log_64(0, 0, 0, i as u64, u64::from(*k));
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints the hexadecimal representation of a slice
|
||||
///
|
||||
/// @param slice - The array to print
|
||||
|
@ -80,13 +70,13 @@ pub fn sol_log_params(ka: &[SolKeyedAccount], data: &[u8]) {
|
|||
sol_log("- Is signer");
|
||||
sol_log_64(0, 0, 0, 0, k.is_signer as u64);
|
||||
sol_log("- Key");
|
||||
sol_log_key(&k.key);
|
||||
k.key.log();
|
||||
sol_log("- Lamports");
|
||||
sol_log_64(0, 0, 0, 0, *k.lamports);
|
||||
sol_log("- AccountData");
|
||||
sol_log_slice(k.data);
|
||||
sol_log("- Owner");
|
||||
sol_log_key(&k.owner);
|
||||
k.owner.log();
|
||||
}
|
||||
sol_log("Instruction data");
|
||||
sol_log_slice(data);
|
||||
|
|
|
@ -51,6 +51,14 @@ impl Pubkey {
|
|||
pub fn new_rand() -> Self {
|
||||
Self::new(&rand::random::<[u8; 32]>())
|
||||
}
|
||||
|
||||
#[cfg(feature = "program")]
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for Pubkey {
|
||||
|
|
Loading…
Reference in New Issue