|
@@ -5,7 +5,7 @@ use crate::config::{
|
|
|
};
|
|
|
use anchor_client::Cluster;
|
|
|
use anchor_lang::idl::{IdlAccount, IdlInstruction, ERASED_AUTHORITY};
|
|
|
-use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize};
|
|
|
+use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize, Discriminator};
|
|
|
use anchor_lang_idl::convert::convert_idl;
|
|
|
use anchor_lang_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTypeDefTy};
|
|
|
use anyhow::{anyhow, Context, Result};
|
|
@@ -2256,7 +2256,7 @@ fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {
|
|
|
}
|
|
|
|
|
|
// Cut off account discriminator.
|
|
|
- let mut d: &[u8] = &account.data[8..];
|
|
|
+ let mut d: &[u8] = &account.data[IdlAccount::DISCRIMINATOR.len()..];
|
|
|
let idl_account: IdlAccount = AnchorDeserialize::deserialize(&mut d)?;
|
|
|
|
|
|
let compressed_len: usize = idl_account.data_len.try_into().unwrap();
|
|
@@ -2900,12 +2900,13 @@ fn account(
|
|
|
};
|
|
|
|
|
|
let data = create_client(cluster.url()).get_account_data(&address)?;
|
|
|
- if data.len() < 8 {
|
|
|
- return Err(anyhow!(
|
|
|
- "The account has less than 8 bytes and is not an Anchor account."
|
|
|
- ));
|
|
|
- }
|
|
|
- let mut data_view = &data[8..];
|
|
|
+ let disc_len = idl
|
|
|
+ .accounts
|
|
|
+ .iter()
|
|
|
+ .find(|acc| acc.name == account_type_name)
|
|
|
+ .map(|acc| acc.discriminator.len())
|
|
|
+ .ok_or_else(|| anyhow!("Account `{account_type_name}` not found in IDL"))?;
|
|
|
+ let mut data_view = &data[disc_len..];
|
|
|
|
|
|
let deserialized_json =
|
|
|
deserialize_idl_defined_type_to_json(&idl, account_type_name, &mut data_view)?;
|
|
@@ -3941,7 +3942,7 @@ fn create_idl_buffer(
|
|
|
|
|
|
// Creates the new buffer account with the system program.
|
|
|
let create_account_ix = {
|
|
|
- let space = 8 + 32 + 4 + serialize_idl(idl)?.len();
|
|
|
+ let space = IdlAccount::DISCRIMINATOR.len() + 32 + 4 + serialize_idl(idl)?.len();
|
|
|
let lamports = client.get_minimum_balance_for_rent_exemption(space)?;
|
|
|
solana_sdk::system_instruction::create_account(
|
|
|
&keypair.pubkey(),
|