Skip to content

Commit

Permalink
lang: Change dispatch ix matching to DISCRIMINATOR
Browse files Browse the repository at this point in the history
  • Loading branch information
cyphersnake committed Jun 29, 2022
1 parent f178d38 commit fdefc4f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lang/syn/src/codegen/program/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::codegen::program::common::*;
use crate::Program;
use heck::CamelCase;
use quote::quote;

pub fn generate(program: &Program) -> proc_macro2::TokenStream {
Expand Down Expand Up @@ -98,12 +99,14 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
.ixs
.iter()
.map(|ix| {
let ix_method_name = &ix.raw_method.sig.ident;
let sighash_arr = sighash(SIGHASH_GLOBAL_NAMESPACE, &ix_method_name.to_string());
let sighash_tts: proc_macro2::TokenStream =
format!("{:?}", sighash_arr).parse().unwrap();
let ix_method_name = &ix.raw_method.sig.ident.to_string();
let ix_name_camel = proc_macro2::Ident::new(
&ix_method_name.as_str().to_camel_case(),
ix.raw_method.sig.ident.span(),
);

quote! {
#sighash_tts => {
instruction::#ix_name_camel::DISCRIMINATOR => {
__private::__global::#ix_method_name(
program_id,
accounts,
Expand Down

0 comments on commit fdefc4f

Please sign in to comment.