Use trace! inside solitaire

Change-Id: Ic26fcabbb6d6000b306d190aab306307ab9cda7f
This commit is contained in:
Reisen 2021-07-01 05:51:40 +00:00
parent 18e52aafe6
commit af00a3c02a
3 changed files with 12 additions and 8 deletions

View File

@ -40,9 +40,8 @@ macro_rules! solitaire {
entrypoint::ProgramResult,
program_error::ProgramError,
pubkey::Pubkey,
msg,
};
use solitaire::{FromAccounts, Persist, Result};
use solitaire::{FromAccounts, Persist, Result, trace};
/// Generated:
/// This Instruction contains a 1-1 mapping for each enum variant to function call. The
@ -59,7 +58,7 @@ macro_rules! solitaire {
match Instruction::try_from_slice(d).map_err(|e| SolitaireError::InstructionDeserializeFailed(e))? {
$(
Instruction::$row(ix_data) => {
msg!("Dispatch: {}", stringify!($row));
trace!("Dispatch: {}", stringify!($row));
let (mut accounts): ($row) = FromAccounts::from(p, &mut a.iter(), &())?;
$fn(&ExecutionContext{program_id: p, accounts: a}, &mut accounts, ix_data)?;
Persist::persist(&accounts, p)?;
@ -74,9 +73,9 @@ macro_rules! solitaire {
}
pub fn solitaire<'a, 'b: 'a>(p: &Pubkey, a: &'a [AccountInfo<'b>], d: &[u8]) -> ProgramResult {
solana_program::msg!(&format!("{} {} built with {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), solitaire::PKG_NAME_VERSION));
trace!("{} {} built with {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), solitaire::PKG_NAME_VERSION);
if let Err(err) = dispatch(p, a, d) {
solana_program::msg!("Error: {:?}", err);
trace!("Error: {:?}", err);
return Err(err.into());
}
Ok(())

View File

@ -6,6 +6,7 @@ use solana_program::{
pubkey::Pubkey,
};
use std::slice::Iter;
use crate::trace;
/// The context is threaded through each check. Include anything within this structure that you
/// would like to have access to as each layer of dependency is peeled off.
@ -36,6 +37,7 @@ impl<'a, 'b: 'a, 'c, T> Context<'a, 'b, 'c, T> {
match self.info {
None => {
let info = next_account_info(self.iter).unwrap();
trace!("{}", info.key);
self.info = Some(info);
info
}

View File

@ -163,12 +163,10 @@ fn generate_fields(name: &syn::Ident, data: &Data) -> TokenStream2 {
let recurse = fields.named.iter().map(|f| {
// Field name, to assign to.
let name = &f.ident;
let name_string =
format!("Peeling: {}", name.to_token_stream().to_string());
let ty = &f.ty;
quote! {
solana_program::msg!(#name_string);
trace!(stringify!(#name));
let #name: #ty = solitaire::Peel::peel(&mut solitaire::Context::new(
pid,
iter,
@ -185,6 +183,8 @@ fn generate_fields(name: &syn::Ident, data: &Data) -> TokenStream2 {
// Write out our iterator and return the filled structure.
quote! {
use solana_program::account_info::next_account_info;
use solitaire::trace;
trace!("Peeling:");
#(#recurse;)*
Ok(#name { #(#names,)* })
}
@ -261,12 +261,15 @@ fn generate_persist(name: &syn::Ident, data: &Data) -> TokenStream2 {
let ty = &f.ty;
quote! {
trace!(stringify!(#name));
Peel::persist(&self.#name, program_id)?;
}
});
// Write out our iterator and return the filled structure.
quote! {
use solitaire::trace;
trace!("Persisting:");
#(#recurse;)*
Ok(())
}