Merge branch 'master' into armani/versioning

This commit is contained in:
Armani Ferrante 2022-02-10 16:23:44 -05:00 committed by GitHub
commit 5d03706171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 88 additions and 100 deletions

View File

@ -11,6 +11,10 @@ incremented for features.
## [Unreleased]
### Fixes
* ts: Allow nullable types for `Option<T>` mapped types ([#1428](https://github.com/project-serum/anchor/pull/1428)).
### Breaking
* lang: Enforce that the payer for an init-ed account be marked `mut` ([#1271](https://github.com/project-serum/anchor/pull/1271)).

View File

@ -55,11 +55,17 @@ pub fn use_version(version: &Version) -> Result<()> {
"anchor-cli {} is not installed, would you like to install it? (y/n)",
version
))
.with_initial_text("y")
.default("n".into())
.interact_text()?;
if matches!(input.as_str(), "y" | "yy" | "Y" | "yes" | "Yes") {
install_version(version)?;
} else {
println!(
"Version {} is not installed, staying on version {}.",
version,
current_version()?
);
return Ok(());
}
}

View File

@ -14,8 +14,6 @@ Open a pull request to add your project to the [list](https://github.com/project
* [Cyclos](https://cyclos.io/)
* [Solend](https://solend.fi)
* [Drift](https://www.drift.trade/)
* [SpringBoard](https://springboard.finance/)
* [Unk](https://unk.finance/)
* [Fabric](https://stake.fsynth.io/)
* [Jet Protocol](https://jetprotocol.io/)
* [Quarry](https://quarry.so/)

View File

@ -156,7 +156,7 @@ pub fn account(
}
let given_disc = anchor_lang::accounts::header::read_discriminator(&buf);
if &#discriminator != given_disc {
return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorMismatch.into());
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.into());
}
Self::try_deserialize_unchecked(buf)
}
@ -184,7 +184,7 @@ pub fn account(
self,
writer
)
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?;
Ok(())
}
}
@ -193,11 +193,11 @@ pub fn account(
impl #impl_gen anchor_lang::AccountDeserialize for #account_name #type_gen #where_clause {
fn try_deserialize(buf: &mut &[u8]) -> std::result::Result<Self, ProgramError> {
if buf.len() < #discriminator.len() {
return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorNotFound.into());
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
}
let given_disc = anchor_lang::accounts::header::read_discriminator(&buf);
if &#discriminator != given_disc {
return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorMismatch.into());
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.into());
}
Self::try_deserialize_unchecked(buf)
}
@ -205,7 +205,7 @@ pub fn account(
fn try_deserialize_unchecked(buf: &mut &[u8]) -> std::result::Result<Self, ProgramError> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize.into())
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}

View File

@ -208,7 +208,7 @@ pub fn interface(
#(#args_no_tys),*
};
let mut ix_data = anchor_lang::AnchorSerialize::try_to_vec(&ix)
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotSerialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;
let mut data = #sighash_tts.to_vec();
data.append(&mut ix_data);
let accounts = ctx.to_account_metas(None);

View File

@ -45,7 +45,7 @@ pub fn state(
fn size(&self) -> std::result::Result<u64, anchor_lang::solana_program::program_error::ProgramError> {
Ok(8 + self
.try_to_vec()
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?
.len() as u64)
}
}

View File

@ -96,7 +96,9 @@ use syn::parse_macro_input;
/// Creates the account via a CPI to the system program and
/// initializes it (sets its account discriminator).<br>
/// Marks the account as mutable and is mutually exclusive with <code>mut</code>.<br>
/// Makes the account rent exempt unless skipped with `rent_exempt = skip`.<br>
/// Makes the account rent exempt unless skipped with <code>rent_exempt = skip</code>.<br><br>
/// Use <code>#[account(zero)]</code> for accounts larger than 10 Kibibyte.<br><br>
/// <code>init</code> has to be used with additional constraints:
/// <ul>
/// <li>
/// Requires the <code>payer</code> constraint to also be on the account.
@ -371,7 +373,14 @@ use syn::parse_macro_input;
/// </td>
/// <td>
/// Checks the account discriminator is zero.<br>
/// Enforces rent exemption unless skipped with <code>rent_exempt = skip</code><br><br>
/// Enforces rent exemption unless skipped with <code>rent_exempt = skip</code>.<br><br>
/// Use this constraint if you want to create an account in a previous instruction
/// and then initialize it in your instruction instead of using <code>init</code>.
/// This is necessary for accounts that are larger than 10 Kibibyte because those
/// accounts cannot be created via a CPI (which is what <code>init</code> would do).<br><br>
/// Anchor adds internal data to the account when using <code>zero</code> just like it
/// does with <code>init</code> which is why <code>zero</code> implies <code>mut</code>.
/// <br><br>
/// Example:
/// <pre><code>
/// #[account(zero)]

View File

@ -1,5 +1,8 @@
use crate::error;
/// The starting point for user defined error codes.
pub const ERROR_CODE_OFFSET: u32 = 6000;
/// Error codes that can be returned by internal framework code.
///
/// - &gt;= 100 Instruction error codes
@ -10,7 +13,7 @@ use crate::error;
/// - = 5000 deprecated error code
///
/// The starting point for user-defined errors is defined
/// by the [ERROR_CODE_OFFSET](crate::__private::ERROR_CODE_OFFSET).
/// by the [ERROR_CODE_OFFSET](crate::error::ERROR_CODE_OFFSET).
#[error(offset = 0)]
pub enum ErrorCode {
// Instructions

View File

@ -274,20 +274,11 @@ pub mod prelude {
/// Internal module used by macros and unstable apis.
#[doc(hidden)]
pub mod __private {
// Modules with useful information for users
// don't use #[doc(hidden)] on these
pub use crate::error::ErrorCode;
/// The discriminator anchor uses to mark an account as closed.
pub const CLOSED_ACCOUNT_DISCRIMINATOR: [u8; 8] = [255, 255, 255, 255, 255, 255, 255, 255];
/// The starting point for user defined error codes.
pub const ERROR_CODE_OFFSET: u32 = 6000;
pub use crate::ctor::Ctor;
pub use crate::error::Error;
pub use anchor_attribute_account::ZeroCopyAccessor;
pub use anchor_attribute_event::EventIndex;

View File

@ -177,7 +177,7 @@ pub fn generate_constraint_close(f: &Field, c: &ConstraintClose) -> proc_macro2:
let target = &c.sol_dest;
quote! {
if #field.key() == #target.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintClose.into());
return Err(anchor_lang::error::ErrorCode::ConstraintClose.into());
}
}
}
@ -240,7 +240,7 @@ pub fn generate_constraint_literal(c: &ConstraintLiteral) -> proc_macro2::TokenS
};
quote! {
if !(#lit) {
return Err(anchor_lang::__private::ErrorCode::Deprecated.into());
return Err(anchor_lang::error::ErrorCode::Deprecated.into());
}
}
}
@ -278,7 +278,7 @@ pub fn generate_constraint_rent_exempt(
ConstraintRentExempt::Skip => quote! {},
ConstraintRentExempt::Enforce => quote! {
if !__anchor_rent.is_exempt(#info.lamports(), #info.try_data_len()?) {
return Err(anchor_lang::__private::ErrorCode::ConstraintRentExempt.into());
return Err(anchor_lang::error::ErrorCode::ConstraintRentExempt.into());
}
},
}
@ -375,10 +375,10 @@ fn generate_constraint_init(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::
let pa: #ty_decl = #from_account_info;
if #if_needed {
if pa.mint != #mint.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintTokenMint.into());
return Err(anchor_lang::error::ErrorCode::ConstraintTokenMint.into());
}
if pa.owner != #owner.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintTokenOwner.into());
return Err(anchor_lang::error::ErrorCode::ConstraintTokenOwner.into());
}
}
pa
@ -410,14 +410,14 @@ fn generate_constraint_init(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::
let pa: #ty_decl = #from_account_info;
if #if_needed {
if pa.mint != #mint.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintTokenMint.into());
return Err(anchor_lang::error::ErrorCode::ConstraintTokenMint.into());
}
if pa.owner != #owner.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintTokenOwner.into());
return Err(anchor_lang::error::ErrorCode::ConstraintTokenOwner.into());
}
if pa.key() != anchor_spl::associated_token::get_associated_token_address(&#owner.key(), &#mint.key()) {
return Err(anchor_lang::__private::ErrorCode::AccountNotAssociatedTokenAccount.into());
return Err(anchor_lang::error::ErrorCode::AccountNotAssociatedTokenAccount.into());
}
}
pa
@ -463,16 +463,16 @@ fn generate_constraint_init(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::
let pa: #ty_decl = #from_account_info;
if #if_needed {
if pa.mint_authority != anchor_lang::solana_program::program_option::COption::Some(#owner.key()) {
return Err(anchor_lang::__private::ErrorCode::ConstraintMintMintAuthority.into());
return Err(anchor_lang::error::ErrorCode::ConstraintMintMintAuthority.into());
}
if pa.freeze_authority
.as_ref()
.map(|fa| #freeze_authority.as_ref().map(|expected_fa| fa != *expected_fa).unwrap_or(true))
.unwrap_or(#freeze_authority.is_some()) {
return Err(anchor_lang::__private::ErrorCode::ConstraintMintFreezeAuthority.into());
return Err(anchor_lang::error::ErrorCode::ConstraintMintFreezeAuthority.into());
}
if pa.decimals != #decimals {
return Err(anchor_lang::__private::ErrorCode::ConstraintMintDecimals.into());
return Err(anchor_lang::error::ErrorCode::ConstraintMintDecimals.into());
}
}
pa
@ -575,17 +575,17 @@ fn generate_constraint_init(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::
// Assert the account was created correctly.
if #if_needed {
if space != actual_field.data_len() {
return Err(anchor_lang::__private::ErrorCode::ConstraintSpace.into());
return Err(anchor_lang::error::ErrorCode::ConstraintSpace.into());
}
if actual_owner != #owner {
return Err(anchor_lang::__private::ErrorCode::ConstraintOwner.into());
return Err(anchor_lang::error::ErrorCode::ConstraintOwner.into());
}
{
let required_lamports = __anchor_rent.minimum_balance(space);
if pa.to_account_info().lamports() < required_lamports {
return Err(anchor_lang::__private::ErrorCode::ConstraintRentExempt.into());
return Err(anchor_lang::error::ErrorCode::ConstraintRentExempt.into());
}
}
}
@ -627,10 +627,10 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
let b = c.bump.as_ref().unwrap();
quote! {
if #name.key() != __pda_address {
return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
}
if __bump != #b {
return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
}
}
}
@ -642,7 +642,7 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
else if c.is_init {
quote! {
if #name.key() != __pda_address {
return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
}
}
}
@ -665,7 +665,7 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
let __pda_address = Pubkey::create_program_address(
&[#maybe_seeds_plus_comma &[#b][..]],
&#deriving_program_id,
).map_err(|_| anchor_lang::__private::ErrorCode::ConstraintSeeds)?;
).map_err(|_| anchor_lang::error::ErrorCode::ConstraintSeeds)?;
},
};
quote! {
@ -674,7 +674,7 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
// Check it.
if #name.key() != __pda_address {
return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
}
}
}
@ -689,11 +689,11 @@ fn generate_constraint_associated_token(
let spl_token_mint_address = &c.mint;
quote! {
if #name.owner != #wallet_address.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintTokenOwner.into());
return Err(anchor_lang::error::ErrorCode::ConstraintTokenOwner.into());
}
let __associated_token_address = anchor_spl::associated_token::get_associated_token_address(&#wallet_address.key(), &#spl_token_mint_address.key());
if #name.key() != __associated_token_address {
return Err(anchor_lang::__private::ErrorCode::ConstraintAssociated.into());
return Err(anchor_lang::error::ErrorCode::ConstraintAssociated.into());
}
}
}
@ -788,7 +788,7 @@ pub fn generate_constraint_executable(
let name = &f.ident;
quote! {
if !#name.to_account_info().executable {
return Err(anchor_lang::__private::ErrorCode::ConstraintExecutable.into());
return Err(anchor_lang::error::ErrorCode::ConstraintExecutable.into());
}
}
}
@ -804,10 +804,10 @@ pub fn generate_constraint_state(f: &Field, c: &ConstraintState) -> proc_macro2:
// Checks the given state account is the canonical state account for
// the target program.
if #ident.key() != anchor_lang::accounts::cpi_state::CpiState::<#account_ty>::address(&#program_target.key()) {
return Err(anchor_lang::__private::ErrorCode::ConstraintState.into());
return Err(anchor_lang::error::ErrorCode::ConstraintState.into());
}
if #ident.as_ref().owner != &#program_target.key() {
return Err(anchor_lang::__private::ErrorCode::ConstraintState.into());
return Err(anchor_lang::error::ErrorCode::ConstraintState.into());
}
}
}
@ -818,6 +818,6 @@ fn generate_custom_error(
) -> proc_macro2::TokenStream {
match custom_error {
Some(error) => quote! { #error.into() },
None => quote! { anchor_lang::__private::ErrorCode::#error.into() },
None => quote! { anchor_lang::error::ErrorCode::#error.into() },
}
}

View File

@ -79,7 +79,7 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
let __Args {
#(#field_names),*
} = __Args::deserialize(&mut ix_data)
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
}
}
};

View File

@ -33,7 +33,7 @@ pub fn generate(error: Error) -> proc_macro2::TokenStream {
.collect();
let offset = match error.args {
None => quote! { anchor_lang::__private::ERROR_CODE_OFFSET},
None => quote! { anchor_lang::error::ERROR_CODE_OFFSET},
Some(args) => {
let offset = &args.offset;
quote! { #offset }

View File

@ -78,7 +78,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
let ix = {
let ix = instruction::#ix_variant;
let mut ix_data = AnchorSerialize::try_to_vec(&ix)
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotSerialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;
let mut data = #sighash_tts.to_vec();
data.append(&mut ix_data);
let accounts = ctx.to_account_metas(None);

View File

@ -114,7 +114,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
})
.collect();
let fallback_fn = gen_fallback(program).unwrap_or(quote! {
Err(anchor_lang::__private::ErrorCode::InstructionFallbackNotFound.into())
Err(anchor_lang::error::ErrorCode::InstructionFallbackNotFound.into())
});
quote! {
/// Performs method dispatch.

View File

@ -6,7 +6,7 @@ use quote::quote;
pub fn generate(program: &Program) -> proc_macro2::TokenStream {
let name: proc_macro2::TokenStream = program.name.to_string().to_camel_case().parse().unwrap();
let fallback_maybe = dispatch::gen_fallback(program).unwrap_or(quote! {
Err(anchor_lang::__private::ErrorCode::InstructionMissing.into());
Err(anchor_lang::error::ErrorCode::InstructionMissing.into());
});
quote! {
#[cfg(not(feature = "no-entrypoint"))]

View File

@ -21,7 +21,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
let mut data: &[u8] = idl_ix_data;
let ix = anchor_lang::idl::IdlInstruction::deserialize(&mut data)
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
match ix {
anchor_lang::idl::IdlInstruction::Create { data_len } => {
@ -66,7 +66,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
#[inline(never)]
#[cfg(feature = "no-idl")]
pub fn __idl_dispatch(program_id: &Pubkey, accounts: &[AccountInfo], idl_ix_data: &[u8]) -> ProgramResult {
Err(anchor_lang::__private::ErrorCode::IdlInstructionStub.into())
Err(anchor_lang::error::ErrorCode::IdlInstructionStub.into())
}
// One time IDL account initializer. Will faill on subsequent
@ -81,7 +81,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
anchor_lang::prelude::msg!("Instruction: IdlCreateAccount");
if program_id != accounts.program.key {
return Err(anchor_lang::__private::ErrorCode::IdlInstructionInvalidProgram.into());
return Err(anchor_lang::error::ErrorCode::IdlInstructionInvalidProgram.into());
}
// Create the IDL's account.
let from = accounts.from.key;
@ -223,7 +223,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Deserialize instruction data.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;
let mut __bumps = std::collections::BTreeMap::new();
@ -305,7 +305,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Deserialize instruction data.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;
let mut __bumps = std::collections::BTreeMap::new();
@ -417,7 +417,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Deserialize instruction.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;
// Bump collector.
@ -426,7 +426,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Load state.
let mut remaining_accounts: &[AccountInfo] = accounts;
if remaining_accounts.is_empty() {
return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
}
let loader: anchor_lang::accounts::loader::Loader<#mod_name::#name> = anchor_lang::accounts::loader::Loader::try_accounts(program_id, &mut remaining_accounts, &[], &mut __bumps)?;
@ -473,7 +473,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Deserialize instruction.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;
// Bump collector.
@ -482,7 +482,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Load state.
let mut remaining_accounts: &[AccountInfo] = accounts;
if remaining_accounts.is_empty() {
return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
}
let mut state: anchor_lang::accounts::state::ProgramState<#state_ty> = anchor_lang::accounts::state::ProgramState::try_accounts(
program_id,
@ -585,7 +585,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
let deserialize_instruction = quote! {
#args_struct
let ix = Args::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
let Args {
#(#ix_arg_names),*
} = ix;
@ -611,7 +611,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Deserialize the program state account.
let mut remaining_accounts: &[AccountInfo] = accounts;
if remaining_accounts.is_empty() {
return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
}
let mut state: anchor_lang::accounts::state::ProgramState<#state_ty> = anchor_lang::accounts::state::ProgramState::try_accounts(
program_id,
@ -725,7 +725,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
// Deserialize data.
let ix = instruction::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::#variant_arm = ix;
// Bump collector.

View File

@ -11,9 +11,9 @@ macro_rules! vote_weight_record {
let mut data = buf;
let vwr: spl_governance_addin_api::voter_weight::VoterWeightRecord =
anchor_lang::AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize)?;
if !solana_program::program_pack::IsInitialized::is_initialized(&vwr) {
return Err(anchor_lang::__private::ErrorCode::AccountDidNotSerialize.into());
return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
}
Ok(VoterWeightRecord(vwr))
}
@ -24,7 +24,7 @@ macro_rules! vote_weight_record {
let mut data = buf;
let vwr: spl_governance_addin_api::voter_weight::VoterWeightRecord =
anchor_lang::AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize)?;
Ok(VoterWeightRecord(vwr))
}
}
@ -35,7 +35,7 @@ macro_rules! vote_weight_record {
writer: &mut W,
) -> std::result::Result<(), ProgramError> {
anchor_lang::AnchorSerialize::serialize(&self.0, writer)
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?;
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?;
Ok(())
}
}

View File

@ -13,8 +13,11 @@ export type Idl = {
events?: IdlEvent[];
errors?: IdlErrorCode[];
constants?: IdlConstant[];
metadata?: IdlMetadata;
};
export type IdlMetadata = any;
export type IdlConstant = {
name: string;
type: IdlType;

View File

@ -107,7 +107,7 @@ export type DecodeType<T extends IdlType, Defined> = T extends keyof TypeMap
: T extends { option: { defined: keyof Defined } }
? Defined[T["option"]["defined"]] | null
: T extends { option: keyof TypeMap }
? TypeMap[T["option"]]
? TypeMap[T["option"]] | null
: T extends { vec: keyof TypeMap }
? TypeMap[T["vec"]][]
: T extends { array: [defined: keyof TypeMap, size: number] }

View File

@ -3525,11 +3525,6 @@ lodash.memoize@4.x:
resolved "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz"
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
lodash.template@^4.0.2:
version "4.5.0"
resolved "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz"
@ -3751,18 +3746,13 @@ node-addon-api@^2.0.0:
resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz"
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==
node-fetch@2.6.7:
node-fetch@2.6.7, node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"
node-fetch@^2.6.1:
version "2.6.1"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
node-gyp-build@^4.2.0:
version "4.2.3"
resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz"
@ -4695,13 +4685,6 @@ tough-cookie@^4.0.0:
punycode "^2.1.1"
universalify "^0.1.2"
tr46@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.0.2.tgz#03273586def1595ae08fedb38d7733cee91d2479"
integrity sha512-3n1qG+/5kg+jrbTzwAykB5yRYtQCTqOGKq5U5PE3b0a1/mzo6snDhjGS0zJVJunO0NrT3Dg1MLy5TjWP/UJppg==
dependencies:
punycode "^2.1.1"
tr46@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240"
@ -4725,9 +4708,9 @@ trim-newlines@^3.0.0:
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==
trim-off-newlines@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz"
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=
version "1.0.3"
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.3.tgz#8df24847fcb821b0ab27d58ab6efec9f2fe961a1"
integrity sha512-kh6Tu6GbeSNMGfrrZh6Bb/4ZEHV1QlB4xNDBeog8Y9/QwFlKTRyWvY3Fs9tRDAMZliVUwieMgEdIeL/FtqjkJg==
ts-jest-resolver@^2.0.0:
version "2.0.0"
@ -4983,16 +4966,7 @@ whatwg-url@^5.0.0:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
whatwg-url@^8.0.0:
version "8.4.0"
resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.4.0.tgz"
integrity sha512-vwTUFf6V4zhcPkWp/4CQPr1TW9Ml6SF4lVyaIMBdJw5i6qUUJ1QWM4Z6YYVkfka0OUIzVo/0aNtGVGk256IKWw==
dependencies:
lodash.sortby "^4.7.0"
tr46 "^2.0.2"
webidl-conversions "^6.1.0"
whatwg-url@^8.5.0:
whatwg-url@^8.0.0, whatwg-url@^8.5.0:
version "8.7.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77"
integrity sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==