Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit da49357

Browse files
authored
remove solana-program from tlv-account-resolution (#7433)
1 parent d0f238f commit da49357

File tree

9 files changed

+162
-52
lines changed

9 files changed

+162
-52
lines changed

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/tlv-account-resolution/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ test-sbf = []
1313

1414
[dependencies]
1515
bytemuck = { version = "1.19.0", features = ["derive"] }
16+
num-derive = "0.4"
17+
num-traits = "0.2"
1618
serde = { version = "1.0.214", optional = true }
17-
solana-program = "2.1.0"
19+
solana-account-info = "2.1.0"
20+
solana-decode-error = "2.1.0"
21+
solana-instruction = { version = "2.1.0", features = ["std"] }
22+
solana-program-error = "2.1.0"
23+
solana-msg = "2.1.0"
24+
solana-pubkey = "2.1.0"
1825
spl-discriminator = { version = "0.3.0", path = "../discriminator" }
1926
spl-program-error = { version = "0.5.0", path = "../program-error" }
2027
spl-pod = { version = "0.4.0", path = "../pod" }
2128
spl-type-length-value = { version = "0.6.0", path = "../type-length-value" }
29+
thiserror = "1.0"
2230

2331
[dev-dependencies]
2432
futures = "0.3.31"

libraries/tlv-account-resolution/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ into a TLV entry in an account, you can do the following:
1010

1111
```rust
1212
use {
13-
solana_program::{account_info::AccountInfo, instruction::{AccountMeta, Instruction}, pubkey::Pubkey},
13+
solana_account_info::AccountInfo,
14+
solana_instruction::{AccountMeta, Instruction},
15+
solana_pubkey::Pubkey
1416
spl_discriminator::{ArrayDiscriminator, SplDiscriminate},
1517
spl_tlv_account_resolution::{
1618
account::ExtraAccountMeta,

libraries/tlv-account-resolution/src/account.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
use {
77
crate::{error::AccountResolutionError, pubkey_data::PubkeyData, seeds::Seed},
88
bytemuck::{Pod, Zeroable},
9-
solana_program::{
10-
account_info::AccountInfo,
11-
instruction::AccountMeta,
12-
program_error::ProgramError,
13-
pubkey::{Pubkey, PUBKEY_BYTES},
14-
},
9+
solana_account_info::AccountInfo,
10+
solana_instruction::AccountMeta,
11+
solana_program_error::ProgramError,
12+
solana_pubkey::{Pubkey, PUBKEY_BYTES},
1513
spl_pod::primitives::PodBool,
1614
};
1715

libraries/tlv-account-resolution/src/error.rs

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
//! Error types
22
3-
use spl_program_error::*;
3+
use {
4+
solana_decode_error::DecodeError,
5+
solana_msg::msg,
6+
solana_program_error::{PrintProgramError, ProgramError},
7+
};
48

59
/// Errors that may be returned by the Account Resolution library.
6-
#[spl_program_error(hash_error_code_start = 2_724_315_840)]
10+
#[repr(u32)]
11+
#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
712
pub enum AccountResolutionError {
813
/// Incorrect account provided
914
#[error("Incorrect account provided")]
10-
IncorrectAccount,
15+
IncorrectAccount = 2_724_315_840,
1116
/// Not enough accounts provided
1217
#[error("Not enough accounts provided")]
1318
NotEnoughAccounts,
@@ -70,3 +75,91 @@ pub enum AccountResolutionError {
7075
#[error("Tried to pack an invalid pubkey data configuration")]
7176
InvalidPubkeyDataConfig,
7277
}
78+
79+
impl From<AccountResolutionError> for ProgramError {
80+
fn from(e: AccountResolutionError) -> Self {
81+
ProgramError::Custom(e as u32)
82+
}
83+
}
84+
85+
impl<T> DecodeError<T> for AccountResolutionError {
86+
fn type_of() -> &'static str {
87+
"AccountResolutionError"
88+
}
89+
}
90+
91+
impl PrintProgramError for AccountResolutionError {
92+
fn print<E>(&self)
93+
where
94+
E: 'static
95+
+ std::error::Error
96+
+ DecodeError<E>
97+
+ PrintProgramError
98+
+ num_traits::FromPrimitive,
99+
{
100+
match self {
101+
AccountResolutionError::IncorrectAccount => {
102+
msg!("Incorrect account provided")
103+
}
104+
AccountResolutionError::NotEnoughAccounts => {
105+
msg!("Not enough accounts provided")
106+
}
107+
AccountResolutionError::TlvUninitialized => {
108+
msg!("No value initialized in TLV data")
109+
}
110+
AccountResolutionError::TlvInitialized => {
111+
msg!("Some value initialized in TLV data")
112+
}
113+
AccountResolutionError::TooManyPubkeys => {
114+
msg!("Too many pubkeys provided")
115+
}
116+
AccountResolutionError::InvalidPubkey => {
117+
msg!("Failed to parse `Pubkey` from bytes")
118+
}
119+
AccountResolutionError::AccountTypeNotAccountMeta => {
120+
msg!(
121+
"Attempted to deserialize an `AccountMeta` but the underlying type has PDA configs rather than a fixed address",
122+
)
123+
}
124+
AccountResolutionError::SeedConfigsTooLarge => {
125+
msg!("Provided list of seed configurations too large for a validation account",)
126+
}
127+
AccountResolutionError::NotEnoughBytesForSeed => {
128+
msg!("Not enough bytes available to pack seed configuration",)
129+
}
130+
AccountResolutionError::InvalidBytesForSeed => {
131+
msg!("The provided bytes are not valid for a seed configuration",)
132+
}
133+
AccountResolutionError::InvalidSeedConfig => {
134+
msg!("Tried to pack an invalid seed configuration",)
135+
}
136+
AccountResolutionError::InstructionDataTooSmall => {
137+
msg!("Instruction data too small for seed configuration",)
138+
}
139+
AccountResolutionError::AccountNotFound => {
140+
msg!("Could not find account at specified index",)
141+
}
142+
AccountResolutionError::CalculationFailure => {
143+
msg!("Error in checked math operation")
144+
}
145+
AccountResolutionError::AccountDataNotFound => {
146+
msg!("Could not find account data at specified index",)
147+
}
148+
AccountResolutionError::AccountDataTooSmall => {
149+
msg!("Account data too small for requested seed configuration",)
150+
}
151+
AccountResolutionError::AccountFetchFailed => {
152+
msg!("Failed to fetch account")
153+
}
154+
AccountResolutionError::NotEnoughBytesForPubkeyData => {
155+
msg!("Not enough bytes available to pack pubkey data configuration",)
156+
}
157+
AccountResolutionError::InvalidBytesForPubkeyData => {
158+
msg!("The provided bytes are not valid for a pubkey data configuration",)
159+
}
160+
AccountResolutionError::InvalidPubkeyDataConfig => {
161+
msg!("Tried to pack an invalid pubkey data configuration",)
162+
}
163+
}
164+
}
165+
}

libraries/tlv-account-resolution/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ pub mod state;
1515

1616
// Export current sdk types for downstream users building with a different sdk
1717
// version
18-
pub use solana_program;
18+
pub use {
19+
solana_account_info, solana_decode_error, solana_instruction, solana_msg, solana_program_error,
20+
solana_pubkey,
21+
};

libraries/tlv-account-resolution/src/pubkey_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
#[cfg(feature = "serde-traits")]
88
use serde::{Deserialize, Serialize};
9-
use {crate::error::AccountResolutionError, solana_program::program_error::ProgramError};
9+
use {crate::error::AccountResolutionError, solana_program_error::ProgramError};
1010

1111
/// Enum to describe a required key stored in some data.
1212
#[derive(Clone, Debug, PartialEq)]

libraries/tlv-account-resolution/src/seeds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
3030
#[cfg(feature = "serde-traits")]
3131
use serde::{Deserialize, Serialize};
32-
use {crate::error::AccountResolutionError, solana_program::program_error::ProgramError};
32+
use {crate::error::AccountResolutionError, solana_program_error::ProgramError};
3333

3434
/// Enum to describe a required seed for a Program-Derived Address
3535
#[derive(Clone, Debug, PartialEq)]

0 commit comments

Comments
 (0)