add comment

This commit is contained in:
Armani Ferrante 2022-07-03 10:41:38 -04:00
parent ea2952b5d7
commit 4d92e266f5
1 changed files with 11 additions and 2 deletions

View File

@ -15,12 +15,21 @@ pub mod bump_seed_canonicalization_recommended {
#[derive(Accounts)]
#[instruction(key: u64)]
pub struct BumpSeed<'info> {
#[account(seeds = [key.to_le_bytes().as_ref()], bump = data.bump)]
// Note a subtle pattern that is not displayed here.
//
// Usually, the usage of PDAs is broken into two parts:
//
// 1) allocation via `#[account(init, seeds = [...], bump)]`
// 2) using the account via `#[account(init, seeds = [...], bump = data.bump)]
//
// When using a PDA, it's usually recommend to store the bump seed in the
// account data, so that you can use it as demonstrated in 2), which will
// provide a more efficient check.
#[account(seeds = [key.to_le_bytes().as_ref()], bump)]
data: Account<'info, Data>,
}
#[account]
pub struct Data {
value: u64,
bump: u8,
}