anchor
anchor copied to clipboard
Pass tuple enum to instruction data
I pass custom struct including tuple enum to instruction:
#[derive(Debug, AnchorSerialize, AnchorDeserialize)]
pub enum FeedValue {
Boolean(bool),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
U128(u128),
}
#[derive(Debug, AnchorSerialize, AnchorDeserialize)]
pub struct Feed {
/// The value that is stored within a single feed. In most cases, intermediate
/// nodes or non-leaf feeds will be None (although some may decide to have a
/// summary value for their children), and leaf feeds will have concrete values.
pub value: Option<FeedValue>,
}
#[program]
pub mod my_program {
use super::*;
pub fn create(ctx: Context<Create>, feed: Feed) -> Result<()> {
Ok(())
}
}
and I've got this error:
Error: Tuple enum variants not yet implemented.
at /Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:134:19
at Array.map (<anonymous>)
at /Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:132:45
at Array.map (<anonymous>)
at Function.typeDefLayout (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:127:44)
at Function.fieldLayout (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:96:27)
at Function.fieldLayout (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:77:22)
at /Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:122:28
at Array.map (<anonymous>)
at Function.typeDefLayout (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:121:48)
at Function.fieldLayout (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/idl.ts:96:27)
at /Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/instruction.ts:114:22
at Array.map (<anonymous>)
at /Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/instruction.ts:113:38
at Array.map (<anonymous>)
at Function.parseIxLayout (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/instruction.ts:112:26)
at new BorshInstructionCoder (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/instruction.ts:47:43)
at new BorshCoder (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/coder/borsh/index.ts:47:24)
at new Program (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/program/index.ts:283:28)
at /Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/workspace.ts:59:36
at Array.forEach (<anonymous>)
at Object.get (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/@project-serum/anchor/src/workspace.ts:52:10)
at Suite.<anonymous> (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/tests/orao-onchain.ts:9:38)
at Object.create (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object.<anonymous> (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/tests/orao-onchain.ts:5:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module.m._compile (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/ts-node/src/index.ts:442:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.exports.requireOrImport (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/mocha/lib/nodejs/esm-utils.js:60:20)
at Object.exports.loadFilesAsync (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
at singleRun (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at Object.exports.handler (/Volumes/DATA/SourceCode/orao-network/orao/orao-anchor/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1.
How to fix it?
See the error Error: Tuple enum variants not yet implemented.
. Please use a struct enum variant for now.
You might want to check out anchor-client-gen - it has tuple enum support.
Using tuple enum as an argument was implemented in #2185 and inside account data in #2601.
https://github.com/coral-xyz/anchor/blob/b5f4796156f3d160f22478f8996f685bddd57505/tests/idl/programs/client-interactions/src/lib.rs#L34-L37
https://github.com/coral-xyz/anchor/blob/b5f4796156f3d160f22478f8996f685bddd57505/tests/idl/programs/client-interactions/src/lib.rs#L81-L87
https://github.com/coral-xyz/anchor/blob/b5f4796156f3d160f22478f8996f685bddd57505/tests/idl/tests/client-interactions.ts#L90-L96