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

Implement some way of tying together enums and instruction parameter structs in the autogenerated code #48

Open
jarry-xiao opened this issue Dec 15, 2022 · 3 comments

Comments

@jarry-xiao
Copy link

jarry-xiao commented Dec 15, 2022

The one thing that i wish shank could do a little better on the code generation side is to allow for instruction identifiers and instruction parameters to be split up into 2 separate components. Here are 2 examples from the typescript client for Phoenix:
image

image

I had to inject logic into this function to get it to work properly. This is what one of them looks like at generation:

image

Reference:
https://github.com/Ellipsis-Labs/phoenix-sdk/blob/master/typescript/phoenix-sdk/src/instructions/Swap.ts#L58
https://github.com/Ellipsis-Labs/phoenix-sdk/blob/master/typescript/phoenix-sdk/src/instructions/CancelMultipleOrdersById.ts#L68

This minimal amount of boilerplate isn't the end of the world, but it would be nice if there was some way to have this work done for me. If I could tag the struct that I wanted to include as a parameter:

 #[parameter(instruction=0, param_index=0, name = "cancel_order_params")]

I think it should in theory be possible to group everything together.

Maybe this is more suited for Solita. I think this is an awesome tool that really doesn't try to force me into a hole when programming. I like being able to write pure Rust code without having to jump through hoops imposed by a framework.

@febo
Copy link
Contributor

febo commented Feb 2, 2023

@jarry-xiao Wondering if this is still an issue. If I understood correctly what you are describing, I think you can use an enum with data for your instructions – e.g.:

pub enum Instruction {
    Swap(OrderPacket),
    ...
}

The generated code will then expect an OrderPacket object as a parameter to create the Swap instruction.

@jarry-xiao
Copy link
Author

I worked around this by injecting some logic into our IDL generation. Really appreciate this tool being so flexible

@jarry-xiao
Copy link
Author

When we make our program open source, I'll link our solution here

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