Here in processor in instruction pre_sale i want to use Tree struct from whitelist. but this error comes Error: ELF error: ELF error: Failed to parse ELF file: Section or symbol name .bss._ZN3ico12in
is longer than 16
bytes. This error comes whenever i tires to declare global variable. I have also tried to use lazy_static.
Update :- This is my elf file line where i am getting error, .dynamic .bss._ZN3ico12instructions9whitelist14WHITELIST_TREE17hd158279cb8bbdda1E
Processor :-
use solana_program::program_error::ProgramError;
use {
borsh::{BorshDeserialize, BorshSerialize},
solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey},
};
use crate::instructions::{
self,
create::{create_token, CreateTokenArgs},
mint::{mint_token, MintSplArgs},
presale::{pre_sale, BuyerArgs, PreSaleArgs},
transfer::{transfer_tokens, TransferTokensArgs},
whitelist::{whitelist_account, WhitelistArgs, WHITELIST_TREE}
};
#[derive(BorshSerialize, BorshDeserialize, Debug)]
enum MyInstruction {
Create(CreateTokenArgs),
MintSpl(MintSplArgs),
TransferTokens(TransferTokensArgs),
WhiteListAccount(WhitelistArgs, String),
PreSale(),
}
pub fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
let instruction = MyInstruction::try_from_slice(instruction_data)?;
match instruction {
MyInstruction::Create(args) => create_token(accounts, args),
MyInstruction::MintSpl(args) => mint_token(accounts, args),
MyInstruction::TransferTokens(args) => transfer_tokens(accounts, args),
MyInstruction::WhiteListAccount(args, admin_account) => {
match whitelist_account(args, admin_account) {
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
MyInstruction::PreSale() => {
let tree = unsafe { WHITELIST_TREE.as_ref().unwrap() };
pre_sale(accounts, tree )
}
}
}
WhiteList :-
use {
borsh::{BorshDeserialize, BorshSerialize},
merkletreers::{tree::MerkleTree, utils::hash_it},
solana_program::{entrypoint::ProgramResult, msg, program_error::ProgramError},
};
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct WhitelistArgs {
pub accounts: Vec<String>,
}
pub struct Tree {
pub merkle_tree: MerkleTree,
}
pub(crate) static mut WHITELIST_TREE: Option<Tree> = None;
pub fn whitelist_account(args: WhitelistArgs) -> ProgramResult {
let leaves: Vec<[u8; 32]> = args
.accounts
.iter()
.map(|account_str| {
let account_bytes = account_str.as_bytes();
let mut buffer = [0u8; 32];
hash_it(account_bytes, &mut buffer);
buffer
})
.collect();
let whitelist_tree = MerkleTree::new(leaves);
let tree = Tree {
merkle_tree: whitelist_tree,
};
msg!("Accounts have been added to the whitelist");
msg!("{:?}", tree.merkle_tree.root);
unsafe {
WHITELIST_TREE = Some(tree);
}
Ok(())
}