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

Feat: Setup a coder for SystemProgram #1920

Merged
merged 18 commits into from
May 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ com/project-serum/anchor/pull/1841)).
* lang: Add `PartialEq` and `Eq` for `anchor_lang::Error` ([#1544](https://github.com/project-serum/anchor/pull/1544)).
* cli: Add `b` and `t` aliases for `build` and `test` respectively ([#1823](https://github.com/project-serum/anchor/pull/1823)).
* spl: Add `sync_native` token program CPI wrapper function ([#1833](https://github.com/project-serum/anchor/pull/1833)).
* ts: Implement a coder for system program ([#1920](https://github.com/project-serum/anchor/pull/1920)).

### Fixes

Expand Down
1 change: 1 addition & 0 deletions tests/custom-coder/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[programs.localnet]
custom_coder = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
spl_token = "FmpfPa1LHEYRbueNMnwNVd2JvyQ89GXGWdyZEXNNKV8w"
native_system = "9NxAd91hhJ3ZBTHytYP894y4ESRKG7n8VbLgdyYGJFLB"

[registry]
url = "https://anchor.projectserum.com"
Expand Down
4 changes: 4 additions & 0 deletions tests/custom-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
},
"scripts": {
"test": "anchor test"
},
"dependencies": {
"mocha": "^10.0.0",
"ts-mocha": "^10.0.0"
}
}
20 changes: 20 additions & 0 deletions tests/custom-coder/programs/native-system/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "native-system"
version = "0.1.0"
description = "Created with Anchor"
rust-version = "1.56"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "native_system"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = { path = "../../../../lang" }
2 changes: 2 additions & 0 deletions tests/custom-coder/programs/native-system/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
214 changes: 214 additions & 0 deletions tests/custom-coder/programs/native-system/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
use anchor_lang::prelude::*;

declare_id!("9NxAd91hhJ3ZBTHytYP894y4ESRKG7n8VbLgdyYGJFLB");

#[program]
pub mod native_system {
use super::*;

pub fn create_account(
ctx: Context<CreateAccount>,
lamports: u64,
space: u64,
owner: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn assign(ctx: Context<Assign>, owner: Pubkey) -> Result<()> {
Ok(())
}

pub fn transfer(ctx: Context<Transfer>, lamports: u64) -> Result<()> {
Ok(())
}

pub fn create_account_with_seed(
ctx: Context<CreateAccountWithSeed>,
base: Pubkey,
seed: String,
lamports: u64,
space: u64,
owner: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn advance_nonce_account(
ctx: Context<AdvanceNonceAccount>,
authorized: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn withdraw_nonce_account(ctx: Context<WithdrawNonceAccount>, lamports: u64) -> Result<()> {
Ok(())
}

pub fn initialize_nonce_account(
ctx: Context<InitializeNonceAccount>,
authorized: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn authorize_nonce_account(
ctx: Context<AuthorizeNonceAccount>,
authorized: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn allocate(ctx: Context<Allocate>, space: u64) -> Result<()> {
Ok(())
}

pub fn allocate_with_seed(
ctx: Context<AllocateWithSeed>,
base: Pubkey,
seed: String,
space: u64,
owner: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn assign_with_seed(
ctx: Context<AssignWithSeed>,
base: Pubkey,
seed: String,
owner: Pubkey,
) -> Result<()> {
Ok(())
}

pub fn transfer_with_seed(
ctx: Context<TransferWithSeed>,
lamports: u64,
seed: String,
owner: Pubkey,
) -> Result<()> {
Ok(())
}
}

#[derive(Accounts)]
pub struct CreateAccount<'info> {
#[account(mut)]
from: Signer<'info>,
#[account(mut)]
to: Signer<'info>,
}

#[derive(Accounts)]
pub struct Assign<'info> {
#[account(mut)]
pubkey: Signer<'info>,
}

#[derive(Accounts)]
pub struct Transfer<'info> {
#[account(mut)]
from: Signer<'info>,
#[account(mut)]
/// CHECK:
to: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct CreateAccountWithSeed<'info> {
#[account(mut)]
from: Signer<'info>,
#[account(mut)]
/// CHECK:
to: AccountInfo<'info>,
base: Signer<'info>,
}

#[derive(Accounts)]
pub struct AdvanceNonceAccount<'info> {
#[account(mut)]
/// CHECK:
nonce: AccountInfo<'info>,
/// CHECK:
recent_blockhashes: AccountInfo<'info>,
authorized: Signer<'info>,
}

#[derive(Accounts)]
pub struct WithdrawNonceAccount<'info> {
#[account(mut)]
/// CHECK:
nonce: AccountInfo<'info>,
#[account(mut)]
/// CHECK:
to: AccountInfo<'info>,
/// CHECK:
recent_blockhashes: AccountInfo<'info>,
rent: Sysvar<'info, Rent>,
authorized: Signer<'info>,
}

#[derive(Accounts)]
pub struct InitializeNonceAccount<'info> {
#[account(mut)]
nonce: Signer<'info>,
/// CHECK:
recent_blockhashes: AccountInfo<'info>,
rent: Sysvar<'info, Rent>,
}

#[derive(Accounts)]
pub struct AuthorizeNonceAccount<'info> {
#[account(mut)]
/// CHECK:
nonce: AccountInfo<'info>,
authorized: Signer<'info>,
}

#[derive(Accounts)]
pub struct Allocate<'info> {
#[account(mut)]
pubkey: Signer<'info>,
}

#[derive(Accounts)]
pub struct AllocateWithSeed<'info> {
#[account(mut)]
/// CHECK:
account: AccountInfo<'info>,
base: Signer<'info>,
}

#[derive(Accounts)]
pub struct AssignWithSeed<'info> {
#[account(mut)]
/// CHECK:
account: AccountInfo<'info>,
base: Signer<'info>,
}

#[derive(Accounts)]
pub struct TransferWithSeed<'info> {
#[account(mut)]
/// CHECK:
from: AccountInfo<'info>,
base: Signer<'info>,
#[account(mut)]
/// CHECK:
to: AccountInfo<'info>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct FeeCalculator {
pub lamports_per_signature: u64,
}

#[account]
pub struct Nonce {
pub version: u32,
pub state: u32,
pub authorized_pubkey: Pubkey,
pub nonce: Pubkey,
pub fee_calculator: FeeCalculator,
}
Loading