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

remove solana-program from tlv-account-resolution #7433

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion libraries/tlv-account-resolution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ test-sbf = []

[dependencies]
bytemuck = { version = "1.19.0", features = ["derive"] }
num-derive = "0.4"
num-traits = "0.2"
serde = { version = "1.0.214", optional = true }
solana-program = "2.1.0"
solana-account-info = "2.1.0"
solana-decode-error = "2.1.0"
solana-instruction = { version = "2.1.0", features = ["std"] }
solana-program-error = "2.1.0"
solana-msg = "2.1.0"
solana-pubkey = "2.1.0"
spl-discriminator = { version = "0.3.0", path = "../discriminator" }
spl-program-error = { version = "0.5.0", path = "../program-error" }
spl-pod = { version = "0.4.0", path = "../pod" }
spl-type-length-value = { version = "0.6.0", path = "../type-length-value" }
thiserror = "1.0"

[dev-dependencies]
futures = "0.3.31"
Expand Down
4 changes: 3 additions & 1 deletion libraries/tlv-account-resolution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ into a TLV entry in an account, you can do the following:

```rust
use {
solana_program::{account_info::AccountInfo, instruction::{AccountMeta, Instruction}, pubkey::Pubkey},
solana_account_info::AccountInfo,
solana_instruction::{AccountMeta, Instruction},
solana_pubkey::Pubkey
spl_discriminator::{ArrayDiscriminator, SplDiscriminate},
spl_tlv_account_resolution::{
account::ExtraAccountMeta,
Expand Down
10 changes: 4 additions & 6 deletions libraries/tlv-account-resolution/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
use {
crate::{error::AccountResolutionError, pubkey_data::PubkeyData, seeds::Seed},
bytemuck::{Pod, Zeroable},
solana_program::{
account_info::AccountInfo,
instruction::AccountMeta,
program_error::ProgramError,
pubkey::{Pubkey, PUBKEY_BYTES},
},
solana_account_info::AccountInfo,
solana_instruction::AccountMeta,
solana_program_error::ProgramError,
solana_pubkey::{Pubkey, PUBKEY_BYTES},
spl_pod::primitives::PodBool,
};

Expand Down
99 changes: 96 additions & 3 deletions libraries/tlv-account-resolution/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
//! Error types

use spl_program_error::*;
use {
solana_decode_error::DecodeError,
solana_msg::msg,
solana_program_error::{PrintProgramError, ProgramError},
};

/// Errors that may be returned by the Account Resolution library.
#[spl_program_error(hash_error_code_start = 2_724_315_840)]
#[repr(u32)]
#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
pub enum AccountResolutionError {
/// Incorrect account provided
#[error("Incorrect account provided")]
IncorrectAccount,
IncorrectAccount = 2_724_315_840,
/// Not enough accounts provided
#[error("Not enough accounts provided")]
NotEnoughAccounts,
Expand Down Expand Up @@ -70,3 +75,91 @@ pub enum AccountResolutionError {
#[error("Tried to pack an invalid pubkey data configuration")]
InvalidPubkeyDataConfig,
}

impl From<AccountResolutionError> for ProgramError {
fn from(e: AccountResolutionError) -> Self {
ProgramError::Custom(e as u32)
}
}

impl<T> DecodeError<T> for AccountResolutionError {
fn type_of() -> &'static str {
"AccountResolutionError"
}
}

impl PrintProgramError for AccountResolutionError {
fn print<E>(&self)
where
E: 'static
+ std::error::Error
+ DecodeError<E>
+ PrintProgramError
+ num_traits::FromPrimitive,
{
match self {
AccountResolutionError::IncorrectAccount => {
msg!("Incorrect account provided")
}
AccountResolutionError::NotEnoughAccounts => {
msg!("Not enough accounts provided")
}
AccountResolutionError::TlvUninitialized => {
msg!("No value initialized in TLV data")
}
AccountResolutionError::TlvInitialized => {
msg!("Some value initialized in TLV data")
}
AccountResolutionError::TooManyPubkeys => {
msg!("Too many pubkeys provided")
}
AccountResolutionError::InvalidPubkey => {
msg!("Failed to parse `Pubkey` from bytes")
}
AccountResolutionError::AccountTypeNotAccountMeta => {
msg!(
"Attempted to deserialize an `AccountMeta` but the underlying type has PDA configs rather than a fixed address",
)
}
AccountResolutionError::SeedConfigsTooLarge => {
msg!("Provided list of seed configurations too large for a validation account",)
}
AccountResolutionError::NotEnoughBytesForSeed => {
msg!("Not enough bytes available to pack seed configuration",)
}
AccountResolutionError::InvalidBytesForSeed => {
msg!("The provided bytes are not valid for a seed configuration",)
}
AccountResolutionError::InvalidSeedConfig => {
msg!("Tried to pack an invalid seed configuration",)
}
AccountResolutionError::InstructionDataTooSmall => {
msg!("Instruction data too small for seed configuration",)
}
AccountResolutionError::AccountNotFound => {
msg!("Could not find account at specified index",)
}
AccountResolutionError::CalculationFailure => {
msg!("Error in checked math operation")
}
AccountResolutionError::AccountDataNotFound => {
msg!("Could not find account data at specified index",)
}
AccountResolutionError::AccountDataTooSmall => {
msg!("Account data too small for requested seed configuration",)
}
AccountResolutionError::AccountFetchFailed => {
msg!("Failed to fetch account")
}
AccountResolutionError::NotEnoughBytesForPubkeyData => {
msg!("Not enough bytes available to pack pubkey data configuration",)
}
AccountResolutionError::InvalidBytesForPubkeyData => {
msg!("The provided bytes are not valid for a pubkey data configuration",)
}
AccountResolutionError::InvalidPubkeyDataConfig => {
msg!("Tried to pack an invalid pubkey data configuration",)
}
}
}
}
5 changes: 4 additions & 1 deletion libraries/tlv-account-resolution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ pub mod state;

// Export current sdk types for downstream users building with a different sdk
// version
pub use solana_program;
pub use {
solana_account_info, solana_decode_error, solana_instruction, solana_msg, solana_program_error,
solana_pubkey,
};
2 changes: 1 addition & 1 deletion libraries/tlv-account-resolution/src/pubkey_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#[cfg(feature = "serde-traits")]
use serde::{Deserialize, Serialize};
use {crate::error::AccountResolutionError, solana_program::program_error::ProgramError};
use {crate::error::AccountResolutionError, solana_program_error::ProgramError};

/// Enum to describe a required key stored in some data.
#[derive(Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion libraries/tlv-account-resolution/src/seeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#[cfg(feature = "serde-traits")]
use serde::{Deserialize, Serialize};
use {crate::error::AccountResolutionError, solana_program::program_error::ProgramError};
use {crate::error::AccountResolutionError, solana_program_error::ProgramError};

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