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

Possible to support multiple programs with inter-dependencies? #52

Closed
0xBraunGuy opened this issue Aug 8, 2022 · 2 comments
Closed

Comments

@0xBraunGuy
Copy link

Apologies if this is a dumb question, let's say I have a project with a few programs:

programs/main
programs/admin
programs/pools

where the accounts, structs, enums, etc are defined in the main program, and referenced as a dependency in the other two. Anchor creates three IDL's. Is it possible to generate a client (or three different clients?) from this structure? Right now I don't think it's possible to expose the structs cross-program.

@kklas
Copy link
Owner

kklas commented Aug 9, 2022

It's not a dumb question. Anchor has some limitations when it comes to generating IDL definitions for types imported from external modules and I don't think this kind of use-case is fully supported within Anchor IDL generation itself - i.e. IIRC Anchor will generate "incomplete" IDLs e.g. for the admin program where the IDL will reference types which are not included within it. So this is something that is currently not supported from Anchor and has been descussed here coral-xyz/anchor#1972. I've also proposed a way support for this could be added for Anchor coral-xyz/anchor#2011.

I haven't tested anchor-client-gen for your specific setup, but what I would assume would happen is that the client generation would fail for programs/admin and programs/pools due to missing type definitions in the IDL (and possibly other missing things).
As a workaround I can suggest manually creating an IDL which contain all the necessary definitions for each of the programs and then running anchor-client-gen using that. Either that or just combine these programs into one if possible.

@0xBraunGuy
Copy link
Author

Ahh thanks for the links those are what I was looking for. And yea the IDL generation fails because not all the types are there...expected.

I was able to temporarily work around by just removing the Type-Defined parameters, and go back to the raw primitives. Not ideal but I'm unblocked for now.

I've got all the program business logic centralized right now but it's becoming monolithic so I'm trying to break it out into smaller programs with extra CPI calls.

Thanks for the info and appreciate your work on this project, it's been extremely helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants