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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It is built using the _MetaStack_ consisting of the following tools:
- [shank](https://github.com/metaplex-foundation/shank) which extracts IDL data from the Rust
program
- [solita](https://github.com/metaplex-foundation/solita) which generates a TypeScript SDK from
the extrated IDL
the extracted IDL
- [amman](https://github.com/metaplex-foundation/amman) which allows debugging and testing the
program on a local validator

Expand All @@ -32,6 +32,11 @@ functions against that program after it is deployed on a local validator via _am
```sh
cd program && cargo build-bpf
```
### Generating SDK

```sh
cd ts && yarn api:gen
```

### Running SDK Tests

Expand All @@ -51,11 +56,11 @@ For example to checkout step **2** you'd do: `git switch 2 -c pr/2`.

1. [adding solana rust program with processor method stubs](https://github.com/thlorenz/tictactoe/pull/1)
2. [setup SDK package](https://github.com/thlorenz/tictactoe/pull/2)
3. [preparing SDK generation](https://github.com/thlorenz/tictactoe/pull/3)

## Resources

- [Figma
Board](https://www.figma.com/file/mjzOnSoQ6cOlmRhCLFYgxn/Shank%2FSolita%2FAmman-Solana-Development-Toolbelt)
- [Figma Board](https://www.figma.com/file/mjzOnSoQ6cOlmRhCLFYgxn/Shank%2FSolita%2FAmman-Solana-Development-Toolbelt)
used to explain the _MetaStack_.

## LICENSE
Expand Down
1 change: 1 addition & 0 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ test-bpf = []
borsh = "0.9.3"
num-derive = "0.3.3"
num-traits = "0.2.15"
shank = "0.0.10"
solana-program = "1.14.5"
thiserror = "1.0.37"
7 changes: 6 additions & 1 deletion program/src/instructions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use borsh::BorshDeserialize;
use shank::ShankInstruction;

// -----------------
// Instruction
// -----------------
#[derive(BorshDeserialize)]
#[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),
Expand Down
9 changes: 9 additions & 0 deletions ts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"tabWidth": 2,
"arrowParens": "always",
"printWidth": 80
}
14 changes: 14 additions & 0 deletions ts/.solitarc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path')
const programDir = path.join(__dirname, '..', 'program')
const idlDir = path.join(__dirname, 'idl')
const sdkDir = path.join(__dirname, 'src', 'generated')
const binaryInstallDir = path.join(__dirname, '.crates')

module.exports = {
idlGenerator: 'shank',
programName: 'tictactoe',
idlDir,
sdkDir,
binaryInstallDir,
programDir,
}
3 changes: 2 additions & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build": "rimraf dist && tsc -p tsconfig.json",
"pretest": "yarn build",
"test": "tape dist/test/*.js",
"t": "esr ./test/tictactoe.ts | tap-spec"
"t": "esr ./test/tictactoe.ts | tap-spec",
"api:gen": "solita"
},
"dependencies": {
"@metaplex-foundation/beet": "^0.7.1",
Expand Down