1

Not able to understand this error. function takes 4 arguments but 3 arguments were suppliedrustcClick for full compiler diagnostic entrypoint.rs(132, 19): Actual error occurred here entrypoint.rs(132, 39): an argument of type &whitelist::Tree is missing lib.rs(11, 4): function defined here entrypoint.rs(132, 39): provide the argument: (&program_id, &accounts, &instruction_data, /* &whitelist::Tree */)

use instructions::{whitelist, Tree, WHITELIST_TREE};
use solana_program::{
    account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
};

pub mod instructions;
pub mod processor;

entrypoint!(process_instruction);

fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
    whitelist_tree: &whitelist::Tree,
) -> ProgramResult {
    processor::process_instruction(program_id, accounts, instruction_data, whitelist_tree)
}

Passing right arguments :-

use {
    borsh::{BorshDeserialize, BorshSerialize},
    solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey},
};

use crate::instructions::{
    create::{create_token, CreateTokenArgs},
    mint::{mint_token, MintSplArgs},
    transfer::{transfer_tokens, TransferTokensArgs},
    whitelist::{whitelist_account, WhitelistArgs, Tree},
    presale::{pre_sale, PreSaleArgs, BuyerArgs},
};

#[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],
    whitelist_tree : &Tree,
) -> 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 => pre_sale(accounts, whitelist_tree),
    }
}

1 Answer 1

1

The entrypoint! macro only takes three parameters for a good reason -- they are the raw parameters provided by the runtime to the program. The runtime only passes accounts and instruction data, so you must find a way to include your Tree either in instruction data, or stored in account data.

It looks like you've asked a few questions in this domain -- if you want some mutable global data available, you can try including an account in all instructions to your program.

You can learn more about the Solana programming model and accounts at https://solana.com/docs/core/accounts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.