Skip to content

Commit 8b391aa

Browse files
lang: Replace hardcoded discriminators with Discriminator::DISCRIMINATOR (#3578)
1 parent c869e11 commit 8b391aa

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lang/attribute/program/src/declare_program/mods/cpi.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anchor_lang_idl::types::Idl;
22
use heck::CamelCase;
33
use quote::{format_ident, quote};
44

5-
use super::common::{convert_idl_type_to_syn_type, gen_accounts_common, gen_discriminator};
5+
use super::common::{convert_idl_type_to_syn_type, gen_accounts_common};
66

77
pub fn gen_cpi_mod(idl: &Idl) -> proc_macro2::TokenStream {
88
let cpi_instructions = gen_cpi_instructions(idl);
@@ -49,8 +49,6 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
4949
}
5050
};
5151

52-
let discriminator = gen_discriminator(&ix.discriminator);
53-
5452
let (ret_type, ret_value) = match ix.returns.as_ref() {
5553
Some(ty) => {
5654
let ty = convert_idl_type_to_syn_type(ty);
@@ -73,7 +71,7 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
7371
let ix = {
7472
let ix = internal::args::#arg_value;
7573
let mut data = Vec::with_capacity(256);
76-
data.extend_from_slice(&#discriminator);
74+
data.extend_from_slice(internal::args::#accounts_ident::DISCRIMINATOR);
7775
AnchorSerialize::serialize(&ix, &mut data)
7876
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;
7977

lang/attribute/program/src/declare_program/mods/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn gen_events_mod(idl: &Idl) -> proc_macro2::TokenStream {
2121
impl anchor_lang::Event for #name {
2222
fn data(&self) -> Vec<u8> {
2323
let mut data = Vec::with_capacity(256);
24-
data.extend_from_slice(&#discriminator);
24+
data.extend_from_slice(#name::DISCRIMINATOR);
2525
self.serialize(&mut data).unwrap();
2626
data
2727
}

0 commit comments

Comments
 (0)