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

03: preparing SDK generation #3

Merged
merged 4 commits into from
Oct 18, 2022
Merged

03: preparing SDK generation #3

merged 4 commits into from
Oct 18, 2022

Conversation

thlorenz
Copy link
Owner

@thlorenz thlorenz commented Oct 18, 2022

previous | next


Summary

In this PR we setup code generation via solita and shank.

We added shank as a dependency to the Rust program and annotated the first instruction in
order to describe which accounts should be passed to it and which should be writable and/or
signer.

#[derive(BorshDeserialize, ShankInstruction)]
#[rustfmt::skip]
pub enum TictactoeInstruction {
    #[account(name = "player_x", signer, desc = "The player initializing the game")]
    #[account(name = "game_pda", mut, desc="The game PDA")]
    #[account(name = "system_program", desc="The system program")]
    InitializeGame,
    PlayerJoin,
    PlayerMove(PlayerMove),
}

NOTE that for now we only annotated the first instruction, we will worry about the other two
later.

Inside the TypeScript SDK (./ts) we added the configuration files .solitarc and
.prettierrc that solita will use to generate the SDK code and then format it.

Additionally we added the script api:gen that we can run in order to generate the IDL and
then the code.

What you can do

Read through the changed files in this PR.

Checkout the PR via git switch 03 -c pr/03 and try the following from the ./ts folder:

Run yarn api:gen.

  • this will ensure that a shank CLI is installed that matches the one that we're using in the program and then use it to generate the program IDL
  • the first time it will install it so it is a bit slow, however due to caching it is a lot faster afterwards
  • finally solita generates a TypeScript SDK from that IDL

Screen Shot 2022-10-18 at 5 28 48 PM

Even though it isn't necessary, setting the DEBUG env var as follows results in nicer and more readable output:

Screen Shot 2022-10-18 at 5 29 21 PM

  • we will go into SDK generation in the next step in more detail

previous | next

@thlorenz thlorenz merged commit 128e0a6 into master Oct 18, 2022
@thlorenz thlorenz deleted the sdk/gen branch October 18, 2022 23:40
This was referenced Oct 18, 2022
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

Successfully merging this pull request may close these issues.

1 participant