Extend shank instructions to work with Instruction struct variants#32
Merged
thlorenz merged 4 commits intometaplex-foundation:masterfrom Aug 21, 2022
Merged
Conversation
bba156f to
2664ec8
Compare
This was referenced Aug 19, 2022
- they are inside an instruction thus that context is already provided - shorter names result in better generated code with solita
thlorenz
approved these changes
Aug 21, 2022
Contributor
thlorenz
left a comment
There was a problem hiding this comment.
Very nice work, I reviewed and also ran the IDL against solita to see what the generated code looks like.
One improvement we could do in the future is to represent the instructions args as tuples, i.e. [u8, String, ComplexType] instead, but for now this solution is fine.
I fixed one minor nit (instructionArgs seemed a bit long to me, also when we're talking about one arg it shouldn't be named instructionArgs0, but instructionArg0 or just arg0).
Aside from that all checks out and I'm happy to merge if you're fine with my modification.
Contributor
Author
|
Absolutely! Go for it. Thanks Thorsten! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds two features to
ShankInstructions:instructionArgs0,instructionArgs1, etc)This is necessary to use Shank with SPL instructions. Closes #33
Example: Instruction variant with named arguments
Instructions with named arguments now works. The following
compiles to:
{ "version": "", "name": "", "instructions": [ { "name": "CreateThing", "accounts": [ { "name": "creator", "isMut": false, "isSigner": true }, { "name": "thing", "isMut": true, "isSigner": false } ], "args": [ { "name": "someArgs", "type": { "defined": "SomeArgs" } }, { "name": "otherArgs", "type": { "defined": "OtherArgs" } } ], "discriminant": { "type": "u8", "value": 0 } }, { "name": "CloseThing", "accounts": [ { "name": "creator", "isMut": false, "isSigner": true } ], "args": [ { "name": "instructionArgs", "type": { "option": "u8" } } ], "discriminant": { "type": "u8", "value": 1 } } ], "metadata": { "origin": "shank" } }Example: Instruction variant with multiple unnamed arguments
Previously this would throw with an error saying
"An Instruction can only have one arg field". But now it works. The followingcompiles to
{ "version": "", "name": "", "instructions": [ { "name": "CloseThing", "accounts": [ { "name": "creator", "isMut": false, "isSigner": true } ], "args": [ { "name": "instructionArgs0", "type": { "option": "u8" } }, { "name": "instructionArgs1", "type": { "defined": "ComplexArgs" } }, { "name": "instructionArgs2", "type": { "defined": "ComplexArgs" } } ], "discriminant": { "type": "u8", "value": 0 } } ], "metadata": { "origin": "shank" } }Todo: