|
@@ -19,15 +19,24 @@ use syn::parse_macro_input;
|
|
|
/// and the account deserialization will exit with an error.
|
|
|
#[proc_macro_attribute]
|
|
|
pub fn account(
|
|
|
- _args: proc_macro::TokenStream,
|
|
|
+ args: proc_macro::TokenStream,
|
|
|
input: proc_macro::TokenStream,
|
|
|
) -> proc_macro::TokenStream {
|
|
|
+ let namespace = args.to_string().replace("\"", "");
|
|
|
+
|
|
|
let account_strct = parse_macro_input!(input as syn::ItemStruct);
|
|
|
let account_name = &account_strct.ident;
|
|
|
|
|
|
let discriminator: proc_macro2::TokenStream = {
|
|
|
// Namespace the discriminator to prevent collisions.
|
|
|
- let discriminator_preimage = format!("account:{}", account_name.to_string());
|
|
|
+ let discriminator_preimage = {
|
|
|
+ if namespace.is_empty() {
|
|
|
+ format!("account:{}", account_name.to_string())
|
|
|
+ } else {
|
|
|
+ format!("{}:{}", namespace, account_name.to_string())
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
let mut discriminator = [0u8; 8];
|
|
|
discriminator.copy_from_slice(
|
|
|
&anchor_syn::hash::hash(discriminator_preimage.as_bytes()).to_bytes()[..8],
|