Skip to content

Commit

Permalink
lang: Export Discriminator trait from prelude (#3075)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Jul 8, 2024
1 parent 59ee310 commit 0a1d458
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Add optional `commitment` parameter to `Program.addEventListener` ([#3052](https://github.com/coral-xyz/anchor/pull/3052)).
- cli, idl: Pass `cargo` args to IDL generation when building program or IDL ([#3059](https://github.com/coral-xyz/anchor/pull/3059)).
- cli: Add checks for incorrect usage of `idl-build` feature ([#3061](https://github.com/coral-xyz/anchor/pull/3061)).
- lang: Export `Discriminator` trait from `prelude` ([#3075](https://github.com/coral-xyz/anchor/pull/3075)).

### Fixes

Expand Down
5 changes: 3 additions & 2 deletions lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ pub mod prelude {
require_keys_neq, require_neq,
solana_program::bpf_loader_upgradeable::UpgradeableLoaderState, source,
system_program::System, zero_copy, AccountDeserialize, AccountSerialize, Accounts,
AccountsClose, AccountsExit, AnchorDeserialize, AnchorSerialize, Id, InitSpace, Key,
Lamports, Owner, ProgramData, Result, Space, ToAccountInfo, ToAccountInfos, ToAccountMetas,
AccountsClose, AccountsExit, AnchorDeserialize, AnchorSerialize, Discriminator, Id,
InitSpace, Key, Lamports, Owner, ProgramData, Result, Space, ToAccountInfo, ToAccountInfos,
ToAccountMetas,
};
pub use anchor_attribute_error::*;
pub use borsh;
Expand Down
2 changes: 0 additions & 2 deletions lang/syn/src/codegen/program/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
sighash
};


use anchor_lang::Discriminator;
match sighash {
#(#global_dispatch_arms)*
anchor_lang::idl::IDL_IX_TAG_LE => {
Expand Down
2 changes: 1 addition & 1 deletion lang/syn/src/idl/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn gen_idl_build_impl_accounts_struct(accounts: &AccountsStruct) -> TokenStr
if let Some(ty) = <#defined>::create_type() {
let account = #idl::IdlAccount {
name: ty.name.clone(),
discriminator: <#defined as anchor_lang::Discriminator>::DISCRIMINATOR.into(),
discriminator: #defined::DISCRIMINATOR.into(),
};
accounts.insert(account.name.clone(), account);
types.insert(ty.name.clone(), ty);
Expand Down
2 changes: 1 addition & 1 deletion lang/syn/src/idl/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn impl_idl_build_event(event_struct: &syn::ItemStruct) -> TokenStream {
let ty = #ts;
let event = #idl::IdlEvent {
name: ty.name.clone(),
discriminator: <Self as anchor_lang::Discriminator>::DISCRIMINATOR.into(),
discriminator: Self::DISCRIMINATOR.into(),
};
types.insert(ty.name.clone(), ty);
Some(event)
Expand Down
5 changes: 1 addition & 4 deletions lang/syn/src/idl/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
let name = ix.ident.to_string();
let name_pascal = format_ident!("{}", name.to_camel_case());
let ctx_ident = &ix.anchor_ident;
let discriminator = quote! {
<crate::instruction::#name_pascal as anchor_lang::Discriminator>::DISCRIMINATOR
};

let docs = match &ix.docs {
Some(docs) if !no_docs => quote! { vec![#(#docs.into()),*] },
Expand Down Expand Up @@ -80,7 +77,7 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
#idl::IdlInstruction {
name: #name.into(),
docs: #docs,
discriminator: #discriminator.into(),
discriminator: crate::instruction::#name_pascal::DISCRIMINATOR.into(),
accounts: #ctx_ident::__anchor_private_gen_idl_accounts(
&mut accounts,
&mut types,
Expand Down

0 comments on commit 0a1d458

Please sign in to comment.