diff --git a/CHANGELOG.md b/CHANGELOG.md index 908f279371..6d6f694bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,16 +20,17 @@ incremented for features. ### Features * lang: Add `programdata_address: Option` field to `Program` account. Will be populated if account is a program owned by the upgradable bpf loader ([#1125](https://github.com/project-serum/anchor/pull/1125)) -* lang,ts,ci,cli,docs: update solana toolchain to version 1.8.5([#1133](https://github.com/project-serum/anchor/pull/1133)) -* ts: Add optional commitment argument to `fetch` and `fetchMultiple` ([#1171](https://github.com/project-serum/anchor/pull/1171)) -* lang: Add `set_inner` method to `Account<'a, T>` to enable easy updates ([#1177](https://github.com/project-serum/anchor/pull/1177)) +* lang,ts,ci,cli,docs: update solana toolchain to version 1.8.5([#1133](https://github.com/project-serum/anchor/pull/1133)). +* lang: Account wrappers for non-Anchor programs no longer have to implement the `serialize` function because it has a default impl now. Similarly, they no longer have to implement `try_deserialize` which now delegates to `try_deserialize_unchecked` by default([#1156](https://github.com/project-serum/anchor/pull/1156)). +* lang: Add `set_inner` method to `Account<'a, T>` to enable easy updates ([#1177](https://github.com/project-serum/anchor/pull/1177)). * lang: Handle arrays with const as length ([#968](https://github.com/project-serum/anchor/pull/968)). +* ts: Add optional commitment argument to `fetch` and `fetchMultiple` ([#1171](https://github.com/project-serum/anchor/pull/1171)). ### Breaking * client: Client::new and Client::new_with_options now accept `Rc` instead of `Keypair` ([#975](https://github.com/project-serum/anchor/pull/975)). * lang, ts: Change error enum name and message for 'wrong program ownership' account validation ([#1154](https://github.com/project-serum/anchor/pull/1154)). - lang: Change from `#[repr(packed)]` to `#[repr(C)]` for zero copy accounts ([#1106](https://github.com/project-serum/anchor/pull/1106)). +* lang: Change from `#[repr(packed)]` to `#[repr(C)]` for zero copy accounts ([#1106](https://github.com/project-serum/anchor/pull/1106)). ## [0.19.0] - 2021-12-08 diff --git a/lang/src/lib.rs b/lang/src/lib.rs index 4cda3d4247..6903667701 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -158,7 +158,9 @@ pub trait ToAccountInfo<'info> { /// [`#[account]`](./attr.account.html) attribute. pub trait AccountSerialize { /// Serializes the account data into `writer`. - fn try_serialize(&self, writer: &mut W) -> Result<(), ProgramError>; + fn try_serialize(&self, _writer: &mut W) -> Result<(), ProgramError> { + Ok(()) + } } /// A data structure that can be deserialized and stored into account storage, @@ -173,7 +175,9 @@ pub trait AccountDeserialize: Sized { /// For example, if the SPL token program were to implement this trait, /// it should be impossible to deserialize a `Mint` account into a token /// `Account`. - fn try_deserialize(buf: &mut &[u8]) -> Result; + fn try_deserialize(buf: &mut &[u8]) -> Result { + Self::try_deserialize_unchecked(buf) + } /// Deserializes account data without checking the account discriminator. /// This should only be used on account initialization, when the bytes of diff --git a/spl/src/token.rs b/spl/src/token.rs index 4d4a5a2e5e..4dee5fed71 100644 --- a/spl/src/token.rs +++ b/spl/src/token.rs @@ -5,7 +5,6 @@ use anchor_lang::solana_program::program_error::ProgramError; use anchor_lang::solana_program::program_pack::Pack; use anchor_lang::solana_program::pubkey::Pubkey; use anchor_lang::{Accounts, CpiContext}; -use std::io::Write; use std::ops::Deref; pub use spl_token::ID; @@ -311,21 +310,12 @@ impl TokenAccount { } impl anchor_lang::AccountDeserialize for TokenAccount { - fn try_deserialize(buf: &mut &[u8]) -> Result { - TokenAccount::try_deserialize_unchecked(buf) - } - fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result { spl_token::state::Account::unpack(buf).map(TokenAccount) } } -impl anchor_lang::AccountSerialize for TokenAccount { - fn try_serialize(&self, _writer: &mut W) -> Result<(), ProgramError> { - // no-op - Ok(()) - } -} +impl anchor_lang::AccountSerialize for TokenAccount {} impl anchor_lang::Owner for TokenAccount { fn owner() -> Pubkey { @@ -349,21 +339,12 @@ impl Mint { } impl anchor_lang::AccountDeserialize for Mint { - fn try_deserialize(buf: &mut &[u8]) -> Result { - Mint::try_deserialize_unchecked(buf) - } - fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result { spl_token::state::Mint::unpack(buf).map(Mint) } } -impl anchor_lang::AccountSerialize for Mint { - fn try_serialize(&self, _writer: &mut W) -> Result<(), ProgramError> { - // no-op - Ok(()) - } -} +impl anchor_lang::AccountSerialize for Mint {} impl anchor_lang::Owner for Mint { fn owner() -> Pubkey { @@ -383,10 +364,6 @@ impl Deref for Mint { pub struct Token; impl anchor_lang::AccountDeserialize for Token { - fn try_deserialize(buf: &mut &[u8]) -> Result { - Token::try_deserialize_unchecked(buf) - } - fn try_deserialize_unchecked(_buf: &mut &[u8]) -> Result { Ok(Token) }