Skip to content

Commit

Permalink
Merge branch 'master' into account-subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
AdithyaNarayan authored Jun 2, 2022
2 parents 6ca7fd6 + a5dbc7b commit 340a495
Show file tree
Hide file tree
Showing 39 changed files with 2,589 additions and 16 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ The minor version will be incremented upon a breaking change and the patch versi

### Features

* lang: Add `PartialEq` and `Eq` for `anchor_lang::Error` ([#1544](https://github.com/project-serum/anchor/pull/1544)).
* cli: Add `--skip-build` to `anchor publish` ([#1786](https://github.
com/project-serum/anchor/pull/1841)).
* cli: Add `--program-keypair` to `anchor deploy` ([#1786](https://github.com/project-serum/anchor/pull/1786)).
* spl: Add more derived traits to `TokenAccount` to `Mint` ([#1818](https://github.com/project-serum/anchor/pull/1818)).
* cli: Add compilation optimizations to cli template ([#1807](https://github.com/project-serum/anchor/pull/1807)).
* cli: `build` now adds docs to idl. This can be turned off with `--no-docs` ([#1561](https://github.com/project-serum/anchor/pull/1561)).
* 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 more derived traits to `TokenAccount` to `Mint` ([#1818](https://github.com/project-serum/anchor/pull/1818)).
* spl: Add `sync_native` token program CPI wrapper function ([#1833](https://github.com/project-serum/anchor/pull/1833)).
* cli: Allow passing arguments to an underlying script with `anchor run` ([#1914](https://github.com/project-serum/anchor/pull/1914)).
* ts: Implement a coder for system program ([#1920](https://github.com/project-serum/anchor/pull/1920)).
* ts: Add `program.coder.types` for encoding/decoding user-defined types ([#1931](https://github.com/project-serum/anchor/pull/1931)).
* client: Add send_with_spinner_and_config function to RequestBuilder ([#1926](https://github.com/project-serum/anchor/pull/1926)).
* ts: Implement a coder for SPL associated token program ([#1939](https://github.com/project-serum/anchor/pull/1939)).
* cli: Add `account` subcommand to cli ([#1923](https://github.com/project-serum/anchor/pull/1923))

### Fixes
Expand Down
18 changes: 15 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ pub enum Command {
Run {
/// The name of the script to run.
script: String,
/// Argument to pass to the underlying script.
#[clap(
required = false,
takes_value = true,
multiple_values = true,
last = true
)]
script_args: Vec<String>,
},
/// Saves an api token from the registry locally.
Login {
Expand Down Expand Up @@ -479,7 +487,10 @@ pub fn entry(opts: Opts) -> Result<()> {
Command::Airdrop { .. } => airdrop(&opts.cfg_override),
Command::Cluster { subcmd } => cluster(subcmd),
Command::Shell => shell(&opts.cfg_override),
Command::Run { script } => run(&opts.cfg_override, script),
Command::Run {
script,
script_args,
} => run(&opts.cfg_override, script, script_args),
Command::Login { token } => login(&opts.cfg_override, token),
Command::Publish {
program,
Expand Down Expand Up @@ -2890,16 +2901,17 @@ fn shell(cfg_override: &ConfigOverride) -> Result<()> {
})
}

fn run(cfg_override: &ConfigOverride, script: String) -> Result<()> {
fn run(cfg_override: &ConfigOverride, script: String, script_args: Vec<String>) -> Result<()> {
with_workspace(cfg_override, |cfg| {
let url = cluster_url(cfg, &cfg.test_validator);
let script = cfg
.scripts
.get(&script)
.ok_or_else(|| anyhow!("Unable to find script"))?;
let script_with_args = format!("{script} {}", script_args.join(" "));
let exit = std::process::Command::new("bash")
.arg("-c")
.arg(&script)
.arg(&script_with_args)
.env("ANCHOR_PROVIDER_URL", url)
.env("ANCHOR_WALLET", cfg.provider.wallet.to_string())
.stdout(Stdio::inherit())
Expand Down
34 changes: 32 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use solana_client::client_error::ClientError as SolanaClientError;
use solana_client::pubsub_client::{PubsubClient, PubsubClientError, PubsubClientSubscription};
use solana_client::rpc_client::RpcClient;
use solana_client::rpc_config::{
RpcAccountInfoConfig, RpcProgramAccountsConfig, RpcTransactionLogsConfig,
RpcTransactionLogsFilter,
RpcAccountInfoConfig, RpcProgramAccountsConfig, RpcSendTransactionConfig,
RpcTransactionLogsConfig, RpcTransactionLogsFilter,
};
use solana_client::rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType};
use solana_client::rpc_response::{Response as RpcResponse, RpcLogsResponse};
Expand Down Expand Up @@ -556,6 +556,36 @@ impl<'a> RequestBuilder<'a> {
.send_and_confirm_transaction(&tx)
.map_err(Into::into)
}

pub fn send_with_spinner_and_config(
self,
config: RpcSendTransactionConfig,
) -> Result<Signature, ClientError> {
let instructions = self.instructions()?;

let mut signers = self.signers;
signers.push(&*self.payer);

let rpc_client = RpcClient::new_with_commitment(self.cluster, self.options);

let tx = {
let latest_hash = rpc_client.get_latest_blockhash()?;
Transaction::new_signed_with_payer(
&instructions,
Some(&self.payer.pubkey()),
&signers,
latest_hash,
)
};

rpc_client
.send_and_confirm_transaction_with_spinner_and_config(
&tx,
rpc_client.commitment(),
config,
)
.map_err(Into::into)
}
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions tests/custom-coder/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[programs.localnet]
custom_coder = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
spl_token = "FmpfPa1LHEYRbueNMnwNVd2JvyQ89GXGWdyZEXNNKV8w"
native_system = "9NxAd91hhJ3ZBTHytYP894y4ESRKG7n8VbLgdyYGJFLB"
spl_associated_token = "4dUGnkre6uBhX1abB4ofkoecGN4aDXdiWSaWLUjVw6bh"

[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,
}
22 changes: 22 additions & 0 deletions tests/custom-coder/programs/spl-associated-token/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "spl-associated-token"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

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

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

[profile.release]
overflow-checks = true

[dependencies]
anchor-lang = "0.24.2"
Loading

0 comments on commit 340a495

Please sign in to comment.