Skip to content
Closed
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
2,079 changes: 977 additions & 1,102 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ fn init(
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("git init failed: {}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("git init failed: {}", e))?;
if !git_result.status.success() {
eprintln!("Failed to automatically initialize a new git repository");
}
Expand All @@ -1069,14 +1069,14 @@ fn install_node_modules(cmd: &str) -> Result<std::process::Output> {
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{} install failed: {}", cmd, e.to_string()))
.map_err(|e| anyhow::format_err!("{} install failed: {}", cmd, e))
} else {
std::process::Command::new(cmd)
.arg("install")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{} install failed: {}", cmd, e.to_string()))
.map_err(|e| anyhow::format_err!("{} install failed: {}", cmd, e))
}
}

Expand Down Expand Up @@ -1262,7 +1262,7 @@ fn expand_program(
.args(cargo_args)
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("{}", e))?;
if !exit.status.success() {
eprintln!("'anchor expand' failed. Perhaps you have not installed 'cargo-expand'? https://github.com/dtolnay/cargo-expand#installation");
std::process::exit(exit.status.code().unwrap_or(1));
Expand All @@ -1271,7 +1271,7 @@ fn expand_program(
let version = cargo.version();
let time = chrono::Utc::now().to_string().replace(' ', "_");
let file_path = program_expansions_path.join(format!("{package_name}-{version}-{time}.rs"));
fs::write(&file_path, &exit.stdout).map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
fs::write(&file_path, &exit.stdout).map_err(|e| anyhow::format_err!("{}", e))?;

println!(
"Expanded {} into file {}\n",
Expand Down Expand Up @@ -1612,7 +1612,7 @@ fn docker_build(
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("Docker build failed: {}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("Docker build failed: {}", e))?;
if !exit.status.success() {
return Err(anyhow!("Failed to build program"));
}
Expand Down Expand Up @@ -1736,7 +1736,7 @@ fn docker_build_bpf(
Some(f) => f.into(),
})
.output()
.map_err(|e| anyhow::format_err!("Docker build failed: {}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("Docker build failed: {}", e))?;
if !exit.status.success() {
return Err(anyhow!("Failed to build program"));
}
Expand Down Expand Up @@ -1768,7 +1768,7 @@ fn docker_build_bpf(
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("{}", e))?;
if !exit.status.success() {
Err(anyhow!(
"Failed to copy binary out of docker. Is the target directory set correctly?"
Expand All @@ -1790,7 +1790,7 @@ fn docker_cleanup(container_name: &str, target_dir: &Path) -> Result<()> {
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("{}", e))?;
if !exit.status.success() {
println!("Unable to remove the docker container");
std::process::exit(exit.status.code().unwrap_or(1));
Expand Down Expand Up @@ -1829,7 +1829,7 @@ fn _build_rust_cwd(
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("{}", e))?;
if !exit.status.success() {
std::process::exit(exit.status.code().unwrap_or(1));
}
Expand Down Expand Up @@ -2178,7 +2178,9 @@ fn idl_set_buffer(
AccountMeta::new(idl_authority, true),
];
let mut data = anchor_lang::idl::IDL_IX_TAG.to_le_bytes().to_vec();
data.append(&mut IdlInstruction::SetBuffer.try_to_vec()?);
data.append(&mut anchor_lang::prelude::borsh::to_vec(
&IdlInstruction::SetBuffer,
)?);
Instruction {
program_id,
accounts,
Expand Down Expand Up @@ -3857,7 +3859,9 @@ fn create_idl_buffer(
AccountMeta::new_readonly(keypair.pubkey(), true),
];
let mut data = anchor_lang::idl::IDL_IX_TAG.to_le_bytes().to_vec();
data.append(&mut IdlInstruction::CreateBuffer.try_to_vec()?);
data.append(&mut anchor_lang::prelude::borsh::to_vec(
&IdlInstruction::CreateBuffer,
)?);
Instruction {
program_id: *program_id,
accounts,
Expand Down Expand Up @@ -4090,7 +4094,7 @@ fn shell(cfg_override: &ConfigOverride) -> Result<()> {
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("{}", e))?;

if !child.wait()?.success() {
println!("Error running node shell");
Expand Down Expand Up @@ -4336,7 +4340,7 @@ fn get_node_version() -> Result<Version> {
.arg("--version")
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("node failed: {}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("node failed: {}", e))?;
let output = std::str::from_utf8(&node_version.stdout)?
.strip_prefix('v')
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion cli/src/rust_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl TestTemplate {
.arg("tests")
.stderr(Stdio::inherit())
.output()
.map_err(|e| anyhow::format_err!("{}", e.to_string()))?;
.map_err(|e| anyhow::format_err!("{}", e))?;
if !exit.status.success() {
eprintln!("'cargo new --lib tests' failed");
std::process::exit(exit.status.code().unwrap_or(1));
Expand Down
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ anyhow = "1"
futures = "0.3"
regex = "1"
serde = { version = "1", features = ["derive"] }
solana-account = "2"
solana-account-decoder = "2"
solana-pubsub-client = "2"
solana-rpc-client = "2"
solana-rpc-client-api = "2"
solana-account = "2"
solana-sdk = "2"
thiserror = "1"
tokio = { version = "1", features = ["rt", "sync"] }
Expand Down
4 changes: 2 additions & 2 deletions lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ anchor-debug = [
"anchor-derive-accounts/anchor-debug",
]
derive = []
event-cpi = ["anchor-attribute-event/event-cpi","anchor-attribute-account/event-cpi"]
event-cpi = ["anchor-attribute-event/event-cpi", "anchor-attribute-account/event-cpi"]
idl-build = [
"anchor-attribute-account/idl-build",
"anchor-attribute-constant/idl-build",
Expand Down Expand Up @@ -54,7 +54,7 @@ anchor-lang-idl = { path = "../idl", version = "0.1.2", optional = true }

base64 = "0.21"
bincode = "1"
borsh = "0.10.3"
borsh = "1.5.7"
bytemuck = { version = "1", features = ["derive"] }
const-crypto = "0.3.0"
solana-account-info = "2"
Expand Down
1 change: 0 additions & 1 deletion lang/derive/serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ lazy-account = []

[dependencies]
anchor-syn = { path = "../../syn", version = "0.32.1" }
borsh-derive-internal = "0.10.3"
proc-macro2 = "1"
quote = "1"
syn = { version = "1", features = ["full"] }
41 changes: 6 additions & 35 deletions lang/derive/serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,12 @@ extern crate proc_macro;
#[cfg(feature = "lazy-account")]
mod lazy;

use borsh_derive_internal::*;
use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use syn::{Ident, Item};
use proc_macro2::{TokenStream as TokenStream2};
use quote::quote;

fn gen_borsh_serialize(input: TokenStream) -> TokenStream2 {
let cratename = Ident::new("borsh", Span::call_site());

let item: Item = syn::parse(input).unwrap();
let res = match item {
Item::Struct(item) => struct_ser(&item, cratename),
Item::Enum(item) => enum_ser(&item, cratename),
Item::Union(item) => union_ser(&item, cratename),
// Derive macros can only be defined on structs, enums, and unions.
_ => unreachable!(),
};

match res {
Ok(res) => res,
Err(err) => err.to_compile_error(),
}
fn gen_borsh_serialize(_input: TokenStream) -> TokenStream2 {
quote! { #[derive(::borsh::BorshSerialize )]}
}

#[proc_macro_derive(AnchorSerialize, attributes(borsh_skip))]
Expand Down Expand Up @@ -56,22 +41,8 @@ pub fn anchor_serialize(input: TokenStream) -> TokenStream {
TokenStream::from(ret)
}

fn gen_borsh_deserialize(input: TokenStream) -> TokenStream2 {
let cratename = Ident::new("borsh", Span::call_site());

let item: Item = syn::parse(input).unwrap();
let res = match item {
Item::Struct(item) => struct_de(&item, cratename),
Item::Enum(item) => enum_de(&item, cratename),
Item::Union(item) => union_de(&item, cratename),
// Derive macros can only be defined on structs, enums, and unions.
_ => unreachable!(),
};

match res {
Ok(res) => res,
Err(err) => err.to_compile_error(),
}
fn gen_borsh_deserialize(_: TokenStream) -> TokenStream2 {
quote! { #[derive(::borsh::BorshDeserialize )]}
}

#[proc_macro_derive(AnchorDeserialize, attributes(borsh_skip, borsh_init))]
Expand Down
2 changes: 1 addition & 1 deletion lang/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::solana_program::{program_error::ProgramError, pubkey::Pubkey};
use anchor_lang::error_code;
use borsh::maybestd::io::Error as BorshIoError;
use borsh::io::Error as BorshIoError;
use std::fmt::{Debug, Display};
use std::num::TryFromIntError;

Expand Down
2 changes: 1 addition & 1 deletion lang/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {

macro_rules! len {
($val: expr) => {
$val.try_to_vec().unwrap().len()
borsh::to_vec(&$val).unwrap().len()
};
}

Expand Down
2 changes: 1 addition & 1 deletion lang/syn/src/parser/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl CrateContext {
ctx.file.canonicalize().unwrap().display(),
span.start().line,
span.start().column,
ident.to_string()
ident
));
};
}
Expand Down
6 changes: 3 additions & 3 deletions lang/tests/generics_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Avoiding AccountInfo deprecated msg in anchor context
#![allow(dead_code, deprecated)]

use anchor_lang::prelude::borsh::maybestd::io::Write;
use anchor_lang::prelude::borsh::io::Write;
use anchor_lang::prelude::*;
use borsh::{BorshDeserialize, BorshSerialize};
use solana_pubkey::Pubkey;
Expand Down Expand Up @@ -45,12 +45,12 @@ where
#[derive(Copy, Clone)]
pub struct WrappedU8Array<const N: usize>(u8);
impl<const N: usize> BorshSerialize for WrappedU8Array<N> {
fn serialize<W: Write>(&self, _writer: &mut W) -> borsh::maybestd::io::Result<()> {
fn serialize<W: Write>(&self, _writer: &mut W) -> borsh::io::Result<()> {
todo!()
}
}
impl<const N: usize> BorshDeserialize for WrappedU8Array<N> {
fn deserialize(_buf: &mut &[u8]) -> borsh::maybestd::io::Result<Self> {
fn deserialize(_buf: &mut &[u8]) -> borsh::io::Result<Self> {
todo!()
}

Expand Down
2 changes: 1 addition & 1 deletion spl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ token_2022_extensions = [

[dependencies]
anchor-lang = { path = "../lang", version = "0.32.1", features = ["derive"] }
borsh = { version = "0.10.3", optional = true }
borsh = { version = "1.5.7", optional = true }
mpl-token-metadata = { version = "5", optional = true }
spl-associated-token-account = { version = "7", features = ["no-entrypoint"], optional = true }
spl-memo = { version = "6", features = ["no-entrypoint"], optional = true }
Expand Down
3 changes: 1 addition & 2 deletions tests/auction-house/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/cpi-returns/programs/caller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod caller {
let cpi_ctx = CpiContext::new(cpi_program_id, cpi_accounts);
let result = callee::cpi::return_u64(cpi_ctx)?;
let solana_return = result.get();
anchor_lang::solana_program::log::sol_log_data(&[&solana_return.try_to_vec().unwrap()]);
anchor_lang::solana_program::log::sol_log_data(&[&borsh::to_vec(&solana_return).unwrap()]);
Ok(())
}

Expand All @@ -35,7 +35,7 @@ pub mod caller {
let cpi_ctx = CpiContext::new(cpi_program_id, cpi_accounts);
let result = callee::cpi::return_struct(cpi_ctx)?;
let solana_return = result.get();
anchor_lang::solana_program::log::sol_log_data(&[&solana_return.try_to_vec().unwrap()]);
anchor_lang::solana_program::log::sol_log_data(&[&borsh::to_vec(&solana_return).unwrap()]);
Ok(())
}

Expand All @@ -47,7 +47,7 @@ pub mod caller {
let cpi_ctx = CpiContext::new(cpi_program_id, cpi_accounts);
let result = callee::cpi::return_vec(cpi_ctx)?;
let solana_return = result.get();
anchor_lang::solana_program::log::sol_log_data(&[&solana_return.try_to_vec().unwrap()]);
anchor_lang::solana_program::log::sol_log_data(&[&borsh::to_vec(&solana_return).unwrap()]);
Ok(())
}

Expand Down
16 changes: 13 additions & 3 deletions tests/events/tests/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ describe("Events", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.Events as anchor.Program<Events>;
const confirmOptions: anchor.web3.ConfirmOptions = {
commitment: "confirmed",
preflightCommitment: "confirmed",
skipPreflight: true,
maxRetries: 3,
};

type Event = anchor.IdlEvents<typeof program["idl"]>;
const getEvent = async <E extends keyof Event>(
Expand Down Expand Up @@ -55,10 +61,14 @@ describe("Events", () => {

it("Works without accounts being specified", async () => {
const tx = await program.methods.testEventCpi().transaction();
const txHash = await program.provider.sendAndConfirm(tx, [], config);
const txHash = await program.provider.sendAndConfirm(
tx,
[],
confirmOptions
);
const txResult = await program.provider.connection.getTransaction(
txHash,
config
{ ...confirmOptions, maxSupportedTransactionVersion: 0 }
);

const ixData = anchor.utils.bytes.bs58.decode(
Expand Down Expand Up @@ -97,7 +107,7 @@ describe("Events", () => {
);

try {
await program.provider.sendAndConfirm(tx, [], config);
await program.provider.sendAndConfirm(tx, [], confirmOptions);
} catch (e) {
if (e.logs.some((log) => log.includes("ConstraintSigner"))) return;
console.log(e);
Expand Down
6 changes: 3 additions & 3 deletions tests/idl/programs/new-idl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,19 @@ pub struct SomeStruct {
const GENERIC_CONST: usize = 8;

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct GenericStruct<T, const N: usize> {
pub struct GenericStruct<T: AnchorSerialize + AnchorDeserialize + Clone, const N: usize> {
arr: [T; N],
sub_field: SubGenericStruct<GENERIC_CONST, T, Vec<Option<T>>>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct SubGenericStruct<const N: usize, T, U> {
pub struct SubGenericStruct<const N: usize, T: AnchorSerialize + AnchorDeserialize + Clone, U: AnchorSerialize + AnchorDeserialize + Clone> {
sub_arr: [T; N],
another: U,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub enum GenericEnum<T> {
pub enum GenericEnum<T: AnchorSerialize + AnchorDeserialize + Clone> {
Unit,
Named { x: T },
Tuple(Vec<T>),
Expand Down
Loading
Loading