1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use anchor_lang::{
prelude::*,
solana_program::{msg, program_error::ProgramError},
};
use bytemuck::PodCastError;
use spl_concurrent_merkle_tree::error::ConcurrentMerkleTreeError;
use std::any::type_name;
use std::mem::size_of;
#[error_code]
pub enum AccountCompressionError {
#[msg("Incorrect leaf length. Expected vec of 32 bytes")]
IncorrectLeafLength,
#[msg("Concurrent merkle tree error")]
ConcurrentMerkleTreeError,
#[msg("Issue zero copying concurrent merkle tree data")]
ZeroCopyError,
#[msg("An unsupported max depth or max buffer size constant was provided")]
ConcurrentMerkleTreeConstantsError,
#[msg("Expected a different byte length for the merkle tree canopy")]
CanopyLengthMismatch,
#[msg("Provided authority does not match expected tree authority")]
IncorrectAuthority,
#[msg("Account is owned by a different program, expected it to be owned by this program")]
IncorrectAccountOwner,
#[msg("Account provided has incorrect account type")]
IncorrectAccountType,
}
impl From<&ConcurrentMerkleTreeError> for AccountCompressionError {
fn from(_error: &ConcurrentMerkleTreeError) -> Self {
AccountCompressionError::ConcurrentMerkleTreeError
}
}
pub fn error_msg<T>(data_len: usize) -> impl Fn(PodCastError) -> ProgramError {
move |_: PodCastError| -> ProgramError {
msg!(
"Failed to load {}. Size is {}, expected {}",
type_name::<T>(),
data_len,
size_of::<T>(),
);
ProgramError::InvalidAccountData
}
}