Skip to content

Commit

Permalink
lang, spl, cli: Refactor to preserve span information (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante authored May 30, 2021
1 parent 2f5a7d2 commit 6b5ed78
Show file tree
Hide file tree
Showing 39 changed files with 3,680 additions and 3,078 deletions.
38 changes: 22 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ incremented for features.

## [Unreleased]

## Features
### Features

* ts: Address metadata is now optional for `anchor.workspace` clients ([#310](https://github.com/project-serum/anchor/pull/310)).
* cli: Add global options for override Anchor.toml values ([#313](https://github.com/project-serum/anchor/pull/313)).
* spl: Add `SetAuthority` instruction ([#307](https://github.com/project-serum/anchor/pull/307/files)).
* lang: `constraint = <expression>` added as a replacement for (the now deprecated) string literal constraints ([#341](https://github.com/project-serum/anchor/pull/341)).
* lang: Span information is now preserved, providing informative compiler error messages ([#341](https://github.com/project-serum/anchor/pull/341)).
* ts: Address metadata is now optional for `anchor.workspace` clients ([#310](https://github.com/project-serum/anchor/pull/310)).

## Breaking Changes
### Breaking Changes

* ts: Retrieving deserialized accounts from the `<program>.account.<my-account>` and `<program>.state` namespaces now require explicitly invoking the `fetch` API. For example, `program.account.myAccount(<adddress>)` and `program.state()` is now `program.account.myAccount.fetch(<address>)` and `program.state.fetch()` ([#322](https://github.com/project-serum/anchor/pull/322)).
* lang: `#[account(associated)]` now requires `init` to be provided to create an associated account. If not provided, then the address will be assumed to exist, and a constraint will be added to ensure its correctness ([#318](https://github.com/project-serum/anchor/pull/318)).
* lang: `#[account(associated)]` now requires `init` to be provided to create an associated account. If not provided, then the address will be assumed to exist, and a constraint will be added to ensure the correctness of the address ([#318](https://github.com/project-serum/anchor/pull/318)).
* lang, ts: Change account discriminator pre-image of the `#[state]` account discriminator to be namespaced by "state:" ([#320](https://github.com/project-serum/anchor/pull/320)).
* lang, ts: Change domain delimiters for the pre-image of the instruciton sighash to be a single colon `:` to be consistent with accounts ([#321](https://github.com/project-serum/anchor/pull/321)).
* lang: Associated constraints no longer automatically implement `mut` ([#341](https://github.com/project-serum/anchor/pull/341)).
* lang: Associated `space` constraints must now be literal integers instead of literal strings ([#341](https://github.com/project-serum/anchor/pull/341)).

### Fixes

## [0.6.0] - 2021-05-23

## Features
### Features

* ts: Add `program.simulate` namespace ([#266](https://github.com/project-serum/anchor/pull/266)).
* ts: Introduce `Address` type, allowing one to use Base 58 encoded strings in public APIs ([#304](https://github.com/project-serum/anchor/pull/304)).
Expand All @@ -36,21 +42,21 @@ incremented for features.
* cli: Add `--skip-build` flag to test command ([301](https://github.com/project-serum/anchor/pull/301)).
* cli: Add `anchor shell` command to spawn a node shell populated with an Anchor.toml based environment ([#303](https://github.com/project-serum/anchor/pull/303)).

## Breaking Changes
### Breaking Changes

* cli: The Anchor.toml's `wallet` and `cluster` settings must now be under the `[provider]` table ([#305](https://github.com/project-serum/anchor/pull/305)).
* ts: Event coder `decode` API changed to decode strings directly instead of buffers ([#292](https://github.com/project-serum/anchor/pull/292)).
* ts: Event coder `encode` API removed ([#292](https://github.com/project-serum/anchor/pull/292)).

## [0.5.0] - 2021-05-07

## Features
### Features

* client: Adds support for state instructions ([#248](https://github.com/project-serum/anchor/pull/248)).
* lang: Add `anchor-debug` feature flag for logging ([#253](https://github.com/project-serum/anchor/pull/253)).
* ts: Add support for u16 ([#255](https://github.com/project-serum/anchor/pull/255)).

## Breaking
### Breaking Changes

* client: Renames `RequestBuilder::new` to `RequestBuilder::from` ([#248](https://github.com/project-serum/anchor/pull/248)).
* lang: Renames the generated `instruction::state::Ctor` struct to `instruction::state::New` ([#248](https://github.com/project-serum/anchor/pull/248)).
Expand All @@ -61,7 +67,7 @@ incremented for features.

## [0.4.4] - 2021-04-18

## Features
### Features

* lang: Allows one to specify multiple `with` targets when creating associated acconts ([#197](https://github.com/project-serum/anchor/pull/197)).
* lang, ts: Add array support ([#202](https://github.com/project-serum/anchor/pull/202)).
Expand All @@ -70,19 +76,19 @@ incremented for features.

## [0.4.3] - 2021-04-13

## Features
### Features

* lang: CPI clients for program state instructions ([#43](https://github.com/project-serum/anchor/pull/43)).
* lang: Add `#[account(owner = <program>)]` constraint ([#178](https://github.com/project-serum/anchor/pull/178)).
* lang, cli, ts: Add `#[account(associated = <target>)]` and `#[associated]` attributes for creating associated program accounts within programs. The TypeScript package can fetch these accounts with a new `<program>.account.<account-name>.associated` (and `associatedAddress`) method ([#186](https://github.com/project-serum/anchor/pull/186)).

## Fixes
### Fixes

* lang: Unused `#[account]`s are now parsed into the IDL correctly ([#177](https://github.com/project-serum/anchor/pull/177)).

## [0.4.2] - 2021-04-10

## Features
### Features

* cli: Fund Anchor.toml configured wallet when testing ([#164](https://github.com/project-serum/anchor/pull/164)).
* spl: Add initialize_account instruction for spl tokens ([#166](https://github.com/project-serum/anchor/pull/166)).
Expand All @@ -93,7 +99,7 @@ incremented for features.

## [0.4.0] - 2021-04-04

## Features
### Features

* cli: Specify test files to run ([#118](https://github.com/project-serum/anchor/pull/118)).
* lang: Allow overriding the `#[state]` account's size ([#121](https://github.com/project-serum/anchor/pull/121)).
Expand All @@ -102,15 +108,15 @@ incremented for features.
* cli: TypeScript migrations ([#132](https://github.com/project-serum/anchor/pull/132)).
* lang: Add `#[account(executable)]` attribute ([#140](https://github.com/project-serum/anchor/pull/140)).

## Breaking Changes
### Breaking Changes

* client: Replace url str with `Cluster` struct when constructing clients ([#89](https://github.com/project-serum/anchor/pull/89)).
* lang: Changes the account discriminator of `IdlAccount` to be namespaced by `"internal"` ([#128](https://github.com/project-serum/anchor/pull/128)).
* lang, spl, cli: Upgrade solana toolchain to 1.6.3, a major version upgrade even though only the minor version is incremented. This allows for the removal of `-#![feature(proc_macro_hygiene)]`. ([#139](https://github.com/project-serum/anchor/pull/139)).

## [0.3.0] - 2021-03-12

## Features
### Features

* ts: Allow preloading instructions for state rpc transactions ([cf9c84](https://github.com/project-serum/anchor/commit/cf9c847e4144989b5bc1936149d171e90204777b)).
* ts: Export sighash coder function ([734c75](https://github.com/project-serum/anchor/commit/734c751882f43beec7ea3f0f4d988b502e3f24e4)).
Expand All @@ -124,7 +130,7 @@ incremented for features.

* lang: Removes `IdlInstruction::Clear` ([#107](https://github.com/project-serum/anchor/pull/107)).

## Fixes
### Fixes

* cli: Propagates mocha test exit status on error ([79b791](https://github.com/project-serum/anchor/commit/79b791ffa85ffae5b6163fa853562aa568650f21)).

Expand Down
2 changes: 1 addition & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn read_all_programs() -> Result<Vec<Program>> {
let mut r = vec![];
for f in files {
let path = f?.path();
let idl = anchor_syn::parser::file::parse(path.join("src/lib.rs"))?;
let idl = anchor_syn::idl::file::parse(path.join("src/lib.rs"))?;
let lib_name = extract_lib_name(&path.join("Cargo.toml"))?;
r.push(Program {
lib_name,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {

fn extract_idl(file: &str) -> Result<Idl> {
let file = shellexpand::tilde(file);
anchor_syn::parser::file::parse(&*file)
anchor_syn::idl::file::parse(&*file)
}

fn idl(cfg_override: &ConfigOverride, subcmd: IdlCommand) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/programs/chat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod chat {

#[derive(Accounts)]
pub struct CreateUser<'info> {
#[account(init, associated = authority, space = "312")]
#[account(init, associated = authority, space = 312)]
user: ProgramAccount<'info, User>,
#[account(signer)]
authority: AccountInfo<'info>,
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/programs/misc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub struct TestInitAssociatedAccount<'info> {

#[derive(Accounts)]
pub struct TestAssociatedAccount<'info> {
#[account(associated = authority, with = state, with = data)]
#[account(mut, associated = authority, with = state, with = data)]
my_account: ProgramAccount<'info, TestData>,
#[account(mut, signer)]
authority: AccountInfo<'info>,
Expand Down
2 changes: 1 addition & 1 deletion lang/attribute/interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub fn interface(
}
};

let sighash_arr = anchor_syn::codegen::program::sighash(&trait_name, &method_name.to_string());
let sighash_arr = anchor_syn::codegen::program::common::sighash(&trait_name, &method_name.to_string());
let sighash_tts: proc_macro2::TokenStream =
format!("{:?}", sighash_arr).parse().unwrap();
quote! {
Expand Down
9 changes: 4 additions & 5 deletions lang/attribute/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern crate proc_macro;

use anchor_syn::codegen::program as program_codegen;
use anchor_syn::parser::program as program_parser;
use quote::ToTokens;
use syn::parse_macro_input;

/// The `#[program]` attribute defines the module containing all instruction
Expand All @@ -11,7 +10,7 @@ pub fn program(
_args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let program_mod = parse_macro_input!(input as syn::ItemMod);
let code = program_codegen::generate(program_parser::parse(program_mod));
proc_macro::TokenStream::from(code)
parse_macro_input!(input as anchor_syn::Program)
.to_token_stream()
.into()
}
9 changes: 4 additions & 5 deletions lang/derive/accounts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate proc_macro;

use anchor_syn::codegen::accounts as accounts_codegen;
use anchor_syn::parser::accounts as accounts_parser;
use proc_macro::TokenStream;
use quote::ToTokens;
use syn::parse_macro_input;

/// Implements an [`Accounts`](./trait.Accounts.html) deserializer on the given
Expand Down Expand Up @@ -54,7 +53,7 @@ use syn::parse_macro_input;
// on absurdly long lines?
#[proc_macro_derive(Accounts, attributes(account))]
pub fn derive_anchor_deserialize(item: TokenStream) -> TokenStream {
let strct = parse_macro_input!(item as syn::ItemStruct);
let tts = accounts_codegen::generate(accounts_parser::parse(&strct));
proc_macro::TokenStream::from(tts)
parse_macro_input!(item as anchor_syn::AccountsStruct)
.to_token_stream()
.into()
}
2 changes: 1 addition & 1 deletion lang/src/ctor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Accounts, Sysvar};
use crate::{Accounts, Sysvar, ToAccountInfo};
use solana_program::account_info::AccountInfo;
use solana_program::sysvar::rent::Rent;

Expand Down
8 changes: 4 additions & 4 deletions lang/src/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub type IdlCreateAccounts<'info> = crate::ctor::Ctor<'info>;
pub struct IdlAccounts<'info> {
#[account(mut, has_one = authority)]
pub idl: ProgramAccount<'info, IdlAccount>,
#[account(signer, "authority.key != &Pubkey::new_from_array([0u8; 32])")]
#[account(signer, constraint = authority.key != &Pubkey::new_from_array([0u8; 32]))]
pub authority: AccountInfo<'info>,
}

Expand All @@ -58,7 +58,7 @@ pub struct IdlAccounts<'info> {
pub struct IdlCreateBuffer<'info> {
#[account(init)]
pub buffer: ProgramAccount<'info, IdlAccount>,
#[account(signer, "authority.key != &Pubkey::new_from_array([0u8; 32])")]
#[account(signer, constraint = authority.key != &Pubkey::new_from_array([0u8; 32]))]
pub authority: AccountInfo<'info>,
pub rent: Sysvar<'info, Rent>,
}
Expand All @@ -67,12 +67,12 @@ pub struct IdlCreateBuffer<'info> {
#[derive(Accounts)]
pub struct IdlSetBuffer<'info> {
// The buffer with the new idl data.
#[account(mut, "buffer.authority == idl.authority")]
#[account(mut, constraint = buffer.authority == idl.authority)]
pub buffer: ProgramAccount<'info, IdlAccount>,
// The idl account to be updated with the buffer's data.
#[account(mut, has_one = authority)]
pub idl: ProgramAccount<'info, IdlAccount>,
#[account(signer, "authority.key != &Pubkey::new_from_array([0u8; 32])")]
#[account(signer, constraint = authority.key != &Pubkey::new_from_array([0u8; 32]))]
pub authority: AccountInfo<'info>,
}

Expand Down
Loading

0 comments on commit 6b5ed78

Please sign in to comment.