Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fixed" seeds #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions core/src/account_payer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ pub struct AccountPayer {}

impl AccountPayer {
pub fn seeds(ncn: &Pubkey) -> Vec<Vec<u8>> {
vec![b"account_payer".to_vec(), ncn.to_bytes().to_vec()]
// Note: The second NCN is an error from the original code, most presumably a copy/paste or Claude error
vec![
b"account_payer".to_vec(),
ncn.to_bytes().to_vec(),
ncn.to_bytes().to_vec(),
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we have to keep the extra ncn because that's what the pda in mainnet is now derived off right?

}

pub fn find_program_address(program_id: &Pubkey, ncn: &Pubkey) -> (Pubkey, u8, Vec<Vec<u8>>) {
let mut seeds = Self::seeds(ncn);
seeds.push(ncn.to_bytes().to_vec());
let seeds = Self::seeds(ncn);
let (address, bump) = Pubkey::find_program_address(
&seeds.iter().map(|s| s.as_slice()).collect::<Vec<_>>(),
program_id,
Expand Down Expand Up @@ -172,21 +176,6 @@ mod tests {

use super::*;

#[test]
fn test_seeds() {
let ncn = Pubkey::new_unique();
let seeds = AccountPayer::seeds(&ncn);

// Verify we get exactly 2 seeds
assert_eq!(seeds.len(), 2);

// Verify first seed is the string literal
assert_eq!(seeds[0], b"account_payer".to_vec());

// Verify second seed is the pubkey bytes
assert_eq!(seeds[1], ncn.to_bytes().to_vec());
}

#[test]
fn test_find_program_address() {
let program_id = Pubkey::new_unique();
Expand Down
5 changes: 3 additions & 2 deletions core/src/epoch_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ impl EpochMarker {
}

pub fn seeds(ncn: &Pubkey, epoch: u64) -> Vec<Vec<u8>> {
// Note: The second NCN is an error from the original code, most presumably a copy/paste or Claude error
vec![
b"epoch_marker".to_vec(),
ncn.to_bytes().to_vec(),
epoch.to_le_bytes().to_vec(),
ncn.to_bytes().to_vec(),
]
}

Expand All @@ -56,8 +58,7 @@ impl EpochMarker {
ncn: &Pubkey,
epoch: u64,
) -> (Pubkey, u8, Vec<Vec<u8>>) {
let mut seeds = Self::seeds(ncn, epoch);
seeds.push(ncn.to_bytes().to_vec());
let seeds = Self::seeds(ncn, epoch);
let (address, bump) = Pubkey::find_program_address(
&seeds.iter().map(|s| s.as_slice()).collect::<Vec<_>>(),
program_id,
Expand Down