Skip to content

Commit 691812d

Browse files
committed
add log_ix trait fn
1 parent f00135a commit 691812d

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/putils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "putils"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
description = "Utilities for writing Solana programs with the pinocchio framework"
55
keywords = ["solana", "pinocchio"]
66
documentation = "https://docs.rs/putils/latest/putils/"

crates/putils/src/processor.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ pub trait InstructionProcessor<'a, Ix, T>: Sized {
77
/// Constructions the instruction process type from a slice of accounts
88
fn from_accounts(accounts: &'a [AccountInfo]) -> Result<Self, ProgramError>;
99

10+
/// The main entrypoint for processing this specific instruction, ensuring that
11+
///
12+
/// * The instruction name is logged
13+
/// * Validations are performed
14+
/// * Business logic is invoked
1015
fn try_process(&self, instruction: Ix) -> ProgramResult {
16+
self.log_ix();
1117
let validations_result = self.validations(&instruction)?;
1218
self.process(instruction, validations_result)
1319
}
@@ -22,10 +28,15 @@ pub trait InstructionProcessor<'a, Ix, T>: Sized {
2228
/// to create an account, without having to re-derive the PDA
2329
///
2430
fn validations(&self, instruction: &Ix) -> Result<Option<T>, ProgramError>;
31+
32+
/// Logs the instruction name being invoked
33+
fn log_ix(&self);
2534
}
2635

2736
#[cfg(test)]
2837
mod test {
38+
use pinocchio::msg;
39+
2940
use super::*;
3041
#[derive(Clone, Debug, PartialEq, Eq)]
3142
pub enum TestInstruction {
@@ -72,6 +83,9 @@ mod test {
7283
fn validations(&self, instruction: &TestInstruction) -> Result<Option<()>, ProgramError> {
7384
Ok(None)
7485
}
86+
fn log_ix(&self) {
87+
msg!("Instruction: HelloAccounts")
88+
}
7589
}
7690
impl<'a> InstructionProcessor<'a, TestInstruction, HelloAccountsValidationResult>
7791
for HelloAccounts<'a>
@@ -92,5 +106,8 @@ mod test {
92106
) -> Result<Option<HelloAccountsValidationResult>, ProgramError> {
93107
Ok(None)
94108
}
109+
fn log_ix(&self) {
110+
msg!("Instruction: HelloAccounts")
111+
}
95112
}
96113
}

0 commit comments

Comments
 (0)