Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized Anchor IDL type [{"generic":"T"}] #308

Open
ngundotra opened this issue Nov 18, 2024 · 4 comments
Open

Unrecognized Anchor IDL type [{"generic":"T"}] #308

ngundotra opened this issue Nov 18, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ngundotra
Copy link

While rendering JS client for IDL for solana program dump vmT2hAx4N2U6DyjYxgQHER4VGC8tHJCfHNsSepBKCJZ,

I got the following: CodamaError: Unrecognized Anchor IDL type [{"generic":"T"}].

import { renderVisitor } from '@codama/renderers-js';
import { createFromRoot } from 'codama';
import { rootNodeFromAnchor } from '@codama/nodes-from-anchor';

import fs from 'fs';
import path from 'path';

// solana program dump vmT2hAx4N2U6DyjYxgQHER4VGC8tHJCfHNsSepBKCJZ
const anchorIdl = JSON.parse(fs.readFileSync('anchor-idl.json', 'utf8'));
const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));

const pathToGeneratedFolder = path.join(__dirname, 'clients', 'rust', 'src', 'generated');
const options = {}; // See below.
codama.accept(renderVisitor(pathToGeneratedFolder, options));
@ngundotra ngundotra added the bug Something isn't working label Nov 18, 2024
@ngundotra
Copy link
Author

@lorisleiva
Copy link
Member

Oh yeah that's because Codama doesn't support generic types. I thought there was an issue for this already but I couldn't find it.

The main reason Codama doesn't support generics (yet?) is because the Codama spec aims to be language agnostic. It describes high-level program logic and binary layouts regardless of how the program was written. It also means it can be used to render client code for any languages. Many of whom don't support generics. So by adding generics support to the spec, we are limiting the set of languages Codama can work with.

Anchor doesn't need to worry about this because it limits itself to Rust on the program side and JavaScript on the client side.

A potential solution to this would be to force a "fallback" type for generic types that can be used when generics are not supported by the language. But this wouldn't help here with the conversion from Anchor.

@ngundotra
Copy link
Author

Can we get a fallback type for now so anchor users can at least use non-generic aspects of their IDL?

@lorisleiva
Copy link
Member

Do we have any relevant info on the Anchor IDL to provide a fallback type? Like if I see a generic type T, what should I transform it to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants