-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add relations derivation to idl generation through compilation
- Loading branch information
Showing
10 changed files
with
209 additions
and
7 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#[cfg(feature = "idl-gen")] | ||
pub mod gen; | ||
#[cfg(feature = "idl-parse")] | ||
#[cfg(any(feature = "idl-parse", feature = "idl-gen"))] | ||
pub mod parse; | ||
#[cfg(any(feature = "idl-types", feature = "idl-gen", feature = "idl-parse"))] | ||
pub mod types; |
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
22 changes: 22 additions & 0 deletions
22
tests/idl-generation/programs/relations-derivation/Cargo.toml
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,22 @@ | ||
[package] | ||
name = "relations-derivation" | ||
version = "0.1.0" | ||
description = "Created with Anchor" | ||
rust-version = "1.60" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "relations_derivation" | ||
|
||
[features] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
cpi = ["no-entrypoint"] | ||
idl-gen = [ | ||
"anchor-lang/idl-gen", | ||
] | ||
default = [] | ||
|
||
[dependencies] | ||
anchor-lang = { path = "../../../../lang" } |
2 changes: 2 additions & 0 deletions
2
tests/idl-generation/programs/relations-derivation/Xargo.toml
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,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
68 changes: 68 additions & 0 deletions
68
tests/idl-generation/programs/relations-derivation/src/lib.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,68 @@ | ||
//! The typescript example serves to show how one would setup an Anchor | ||
//! workspace with TypeScript tests and migrations. | ||
|
||
use anchor_lang::prelude::*; | ||
|
||
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"); | ||
|
||
#[program] | ||
pub mod relations_derivation { | ||
use super::*; | ||
|
||
pub fn init_base(ctx: Context<InitBase>) -> Result<()> { | ||
ctx.accounts.account.my_account = ctx.accounts.my_account.key(); | ||
ctx.accounts.account.bump = ctx.bumps["account"]; | ||
Ok(()) | ||
} | ||
pub fn test_relation(_ctx: Context<TestRelation>) -> Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct InitBase<'info> { | ||
/// CHECK: yeah I know | ||
#[account(mut)] | ||
my_account: Signer<'info>, | ||
#[account( | ||
init, | ||
payer = my_account, | ||
seeds = [b"seed"], | ||
space = 100, | ||
bump, | ||
)] | ||
account: Account<'info, MyAccount>, | ||
system_program: Program<'info, System> | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct Nested<'info> { | ||
/// CHECK: yeah I know | ||
my_account: UncheckedAccount<'info>, | ||
#[account( | ||
has_one = my_account, | ||
seeds = [b"seed"], | ||
bump = account.bump | ||
)] | ||
account: Account<'info, MyAccount>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct TestRelation<'info> { | ||
/// CHECK: yeah I know | ||
my_account: UncheckedAccount<'info>, | ||
#[account( | ||
has_one = my_account, | ||
seeds = [b"seed"], | ||
bump = account.bump | ||
)] | ||
account: Account<'info, MyAccount>, | ||
nested: Nested<'info>, | ||
} | ||
|
||
|
||
#[account] | ||
pub struct MyAccount { | ||
pub my_account: Pubkey, | ||
pub bump: 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
83 changes: 83 additions & 0 deletions
83
tests/idl-generation/tests/testdata/relations_gen_exp.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,83 @@ | ||
{ | ||
"version": "0.1.0", | ||
"name": "relations_derivation", | ||
"instructions": [ | ||
{ | ||
"name": "initBase", | ||
"accounts": [ | ||
{ | ||
"name": "myAccount", | ||
"isMut": true, | ||
"isSigner": true | ||
}, | ||
{ | ||
"name": "account", | ||
"isMut": true, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "systemProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
} | ||
], | ||
"args": [] | ||
}, | ||
{ | ||
"name": "testRelation", | ||
"accounts": [ | ||
{ | ||
"name": "myAccount", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "account", | ||
"isMut": false, | ||
"isSigner": false, | ||
"relations": [ | ||
"my_account" | ||
] | ||
}, | ||
{ | ||
"name": "nested", | ||
"accounts": [ | ||
{ | ||
"name": "myAccount", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "account", | ||
"isMut": false, | ||
"isSigner": false, | ||
"relations": [ | ||
"my_account" | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"args": [] | ||
} | ||
], | ||
"accounts": [ | ||
{ | ||
"name": "MyAccount", | ||
"full_path": "relations_derivation::MyAccount", | ||
"type": { | ||
"kind": "struct", | ||
"fields": [ | ||
{ | ||
"name": "myAccount", | ||
"type": "publicKey" | ||
}, | ||
{ | ||
"name": "bump", | ||
"type": "u8" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |