Skip to content

Commit

Permalink
add seeds macro (#73)
Browse files Browse the repository at this point in the history
* use `seeds` macro over `signer` macro

* fix doc to pass doc test

* deprecate  macro
  • Loading branch information
publicqi authored Mar 1, 2025
1 parent 1a10e22 commit 01c1c7a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sdk/pinocchio/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,35 @@ impl<'a, 'b, const SIZE: usize> From<&'b [Seed<'a>; SIZE]> for Signer<'a, 'b> {
/// let signer = signer!(b"seed", &[pda_bump]);
/// ```
#[macro_export]
#[deprecated(since = "0.8.0", note = "Use `seeds!` macro instead")]
macro_rules! signer {
( $($seed:expr),* ) => {
$crate::instruction::Signer::from(&[$(
$seed.into(),
)*])
};
}

/// Convenience macro for constructing a `[Seed; N]` array from a list of seeds.
///
/// # Example
///
/// Creating seeds array and signer for a PDA with a single seed and bump value:
/// ```
/// use pinocchio::{seeds, instruction::Signer};
/// use pinocchio::pubkey::Pubkey;
///
/// let pda_bump = 0xffu8;
/// let pda_ref = &[pda_bump]; // prevent temporary value being freed
/// let example_key = Pubkey::default();
/// let seeds = seeds!(b"seed", &example_key, pda_ref);
/// let signer = Signer::from(&seeds);
/// ```
#[macro_export]
macro_rules! seeds {
( $($seed:expr),* ) => {
[$(
$crate::instruction::Seed::from($seed),
)*]
};
}

0 comments on commit 01c1c7a

Please sign in to comment.