Closed DedicatedDev closed 2 years ago
It's because the IDL take your Candidate struct as an account cause you have the attribute #[account]
and not as a type.
Try to create another struct and just derive it with #[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq)]
so the IDL take it as a type and then you can use it correctly as a parameter
Please use discord for questions https://discord.gg/GVRw4kHB
As you can see following code, I've use custom struct as Parameter. It has no any issue in build. but if I try to test, it is shows error message. IdlError: Type not found: {"type":{"defined":"Candidate"}} so node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:94:19) I've checked this part, and this module check type of parameters. looks don't support custom data type., candidate:Candidate) -> Result<()> {
let vote_account = &mut ctx.accounts.vote_account;
if vote_account.candidates.contains(&candidate) {
Err(ErrorCode::AlreadyRegistered.into())
} else {
vote_account.candidates.push(candidate);
Ok(())
}
}
pub fn register_candidate(ctx: Context
[account]
[derive(PartialEq)]
pub struct Candidate { pub name: String, pub age: String, pub photo: String, }
is someone there to give me advice? Best.