Skip to content

Commit

Permalink
fix: Derive discriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
vadorovsky committed Nov 4, 2024
1 parent 4977c38 commit f83f5bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare_id!("7yucc7fL3JGbyMwg4neUaenNSdySS39hbAk89Ao3t1Hz");

#[program]
pub mod name_service {
use light_hasher::Discriminator;
use light_sdk::account_info::convert_metas_to_infos;

use super::*;
Expand All @@ -29,12 +30,12 @@ pub mod name_service {
let inputs = LightInstructionData::deserialize(&inputs)?;
let mut account_infos = convert_metas_to_infos(&inputs.accounts, &crate::ID)?;

msg!("name: {}", name);
account_infos[0].derive_address(
&[b"name-serice", name.as_bytes()],
&[b"name-service", name.as_bytes()],
&crate::ID,
ctx.remaining_accounts,
)?;
account_infos[0].set_discriminator(NameRecord::discriminator());

let mut light_accounts = LightCreateRecord::try_light_accounts(&account_infos)?;

Expand All @@ -61,7 +62,10 @@ pub mod name_service {
new_rdata: RData,
) -> Result<()> {
let inputs = LightInstructionData::deserialize(&inputs)?;
let account_infos = convert_metas_to_infos(&inputs.accounts, &crate::ID)?;
let mut account_infos = convert_metas_to_infos(&inputs.accounts, &crate::ID)?;

account_infos[0].set_discriminator(NameRecord::discriminator());

let mut light_accounts = LightCreateRecord::try_light_accounts(&account_infos)?;

if light_accounts.record.owner != ctx.accounts.signer.key() {
Expand All @@ -88,7 +92,10 @@ pub mod name_service {
inputs: Vec<u8>,
) -> Result<()> {
let inputs = LightInstructionData::deserialize(&inputs)?;
let account_infos = convert_metas_to_infos(&inputs.accounts, &crate::ID)?;
let mut account_infos = convert_metas_to_infos(&inputs.accounts, &crate::ID)?;

account_infos[0].set_discriminator(NameRecord::discriminator());

let light_accounts = LightDeleteRecord::try_light_accounts(&account_infos)?;

if light_accounts.record.owner != ctx.accounts.signer.key() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ where
address_queue_pubkey: env.address_merkle_tree_queue_pubkey,
};
let account = LightAccountMeta::new_init(
None,
None,
&env.merkle_tree_pubkey,
Some(&address_merkle_context),
Expand Down Expand Up @@ -378,8 +377,6 @@ where
compressed_account,
rpc_result.root_indices[0],
&merkle_tree_pubkey,
None,
None,
false,
remaining_accounts,
);
Expand Down Expand Up @@ -451,7 +448,6 @@ where

let compressed_account = LightAccountMeta::new_close(
compressed_account,
None,
rpc_result.root_indices[0],
remaining_accounts,
);
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl<'a> LightAccountInfo<'a> {
}
}

pub fn set_discriminator(&mut self, discriminator: [u8; 8]) {
self.discriminator = Some(discriminator);
}

/// Converts the given [LightAccountInfo] into a
/// [PackedCompressedAccountWithMerkleContext] which can be sent to the
/// light-system program.
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ pub fn verify<'info, 'a, 'b, 'c, T>(
where
T: AnchorSerialize,
{
anchor_lang::prelude::msg!(
"light program: {}",
ctx.accounts.get_light_system_program().key()
);
anchor_lang::prelude::msg!("expedted: {}", PROGRAM_ID_LIGHT_SYSTEM);
if ctx.accounts.get_light_system_program().key() != PROGRAM_ID_LIGHT_SYSTEM {
return err!(LightSdkError::InvalidLightSystemProgram);
}
Expand Down

0 comments on commit f83f5bd

Please sign in to comment.