-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend shank instructions to work with Instruction struct variants (#32)
* extend shank instructions to have more than one field * parse multiple instruction fields * add test examples * chore: rename instructionArg(s) to arg(s) - they are inside an instruction thus that context is already provided - shorter names result in better generated code with solita Co-authored-by: Thorsten Lorenz <[email protected]>
- Loading branch information
Showing
10 changed files
with
391 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ | |
], | ||
"args": [ | ||
{ | ||
"name": "instructionArgs", | ||
"name": "args", | ||
"type": { | ||
"option": "u8" | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
shank-idl/tests/fixtures/instructions/single_file/instruction_with_multiple_args.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"version": "", | ||
"name": "", | ||
"instructions": [ | ||
{ | ||
"name": "CloseThing", | ||
"accounts": [ | ||
{ | ||
"name": "creator", | ||
"isMut": false, | ||
"isSigner": true | ||
} | ||
], | ||
"args": [ | ||
{ | ||
"name": "arg0", | ||
"type": { | ||
"option": "u8" | ||
} | ||
}, | ||
{ | ||
"name": "arg1", | ||
"type": { | ||
"defined": "ComplexArgs" | ||
} | ||
}, | ||
{ | ||
"name": "arg2", | ||
"type": { | ||
"defined": "ComplexArgs" | ||
} | ||
} | ||
], | ||
"discriminant": { | ||
"type": "u8", | ||
"value": 0 | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"origin": "shank" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shank-idl/tests/fixtures/instructions/single_file/instruction_with_multiple_args.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[derive(ShankInstruction)] | ||
pub enum Instruction { | ||
#[account(0, name = "creator", sig)] | ||
CloseThing(Option<u8>, ComplexArgs, ComplexArgs), | ||
} |
64 changes: 64 additions & 0 deletions
64
shank-idl/tests/fixtures/instructions/single_file/instruction_with_struct_args.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"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": "args", | ||
"type": { | ||
"option": "u8" | ||
} | ||
} | ||
], | ||
"discriminant": { | ||
"type": "u8", | ||
"value": 1 | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"origin": "shank" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
shank-idl/tests/fixtures/instructions/single_file/instruction_with_struct_args.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#[derive(ShankInstruction)] | ||
pub enum Instruction { | ||
#[account(0, name = "creator", sig)] | ||
#[account(1, name = "thing", mut)] | ||
CreateThing { | ||
some_args: SomeArgs, | ||
other_args: OtherArgs, | ||
}, | ||
#[account(0, name = "creator", sig)] | ||
CloseThing(Option<u8>), | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.