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

Commit bd6b05b

Browse files
authored
remove solana-program from spl-type-length-value (#7428)
* remove solana-program from spl-type-length-value * remove solana_program references from SplBorshVariableLenPackBuilder
1 parent f382eab commit bd6b05b

File tree

11 files changed

+72
-27
lines changed

11 files changed

+72
-27
lines changed

Cargo.lock

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/type-length-value-derive-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99

1010
[dev-dependencies]
1111
borsh = "1.5.1"
12-
solana-program = "2.1.0"
12+
solana-borsh = "2.1.0"
1313
spl-discriminator = { version = "0.3.0", path = "../discriminator" }
1414
spl-type-length-value = { version = "0.6.0", path = "../type-length-value", features = [
1515
"derive",

libraries/type-length-value-derive-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pub mod test {
88
use {
99
borsh::{BorshDeserialize, BorshSerialize},
10-
solana_program::borsh1::{get_instance_packed_len, try_from_slice_unchecked},
10+
solana_borsh::v1::{get_instance_packed_len, try_from_slice_unchecked},
1111
spl_discriminator::SplDiscriminate,
1212
spl_type_length_value::{variable_len_pack::VariableLenPack, SplBorshVariableLenPack},
1313
};

libraries/type-length-value/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ derive = ["dep:spl-type-length-value-derive"]
1313

1414
[dependencies]
1515
bytemuck = { version = "1.19.0", features = ["derive"] }
16-
solana-program = "2.1.0"
16+
num-derive = "0.4"
17+
num-traits = "0.2"
18+
solana-account-info = "2.1.0"
19+
solana-decode-error = "2.1.0"
20+
solana-msg = "2.1.0"
21+
solana-program-error = "2.1.0"
1722
spl-discriminator = { version = "0.3.0", path = "../discriminator" }
18-
spl-program-error = { version = "0.5.0", path = "../program-error" }
1923
spl-type-length-value-derive = { version = "0.1", path = "./derive", optional = true }
2024
spl-pod = { version = "0.4.0", path = "../pod" }
25+
thiserror = "1.0"
2126

2227
[lib]
2328
crate-type = ["cdylib", "lib"]

libraries/type-length-value/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let account_size = TlvStateMut::get_base_len()
5151
+ TlvStateMut::get_base_len()
5252
+ std::mem::size_of::<MyOtherPodValue>();
5353

54-
// Buffer likely comes from a Solana `solana_program::account_info::AccountInfo`,
54+
// Buffer likely comes from a Solana `solana_account_info::AccountInfo`,
5555
// but this example just uses a vector.
5656
let mut buffer = vec![0; account_size];
5757

@@ -146,10 +146,8 @@ trait on your type.
146146
```rust
147147
use {
148148
borsh::{BorshDeserialize, BorshSerialize},
149-
solana_program::{
150-
borsh1::{get_instance_packed_len, try_from_slice_unchecked},
151-
program_error::ProgramError,
152-
},
149+
solana_borsh::v1::{get_instance_packed_len, try_from_slice_unchecked},
150+
solana_program_error::ProgramError,
153151
spl_discriminator::{ArrayDiscriminator, SplDiscriminate},
154152
spl_type_length_value::{
155153
state::{TlvState, TlvStateMut},
@@ -181,7 +179,7 @@ let initial_data = "This is a pretty cool test!";
181179
let tlv_size = 4 + initial_data.len();
182180
let account_size = TlvStateMut::get_base_len() + tlv_size;
183181

184-
// Buffer likely comes from a Solana `solana_program::account_info::AccountInfo`,
182+
// Buffer likely comes from a Solana `solana_account_info::AccountInfo`,
185183
// but this example just uses a vector.
186184
let mut buffer = vec![0; account_size];
187185
let mut state = TlvStateMut::unpack(&mut buffer).unwrap();

libraries/type-length-value/derive/src/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ impl From<&SplBorshVariableLenPackBuilder> for TokenStream {
7474
let where_clause = &builder.where_clause;
7575
quote! {
7676
impl #generics spl_type_length_value::variable_len_pack::VariableLenPack for #ident #generics #where_clause {
77-
fn pack_into_slice(&self, dst: &mut [u8]) -> Result<(), spl_type_length_value::solana_program::program_error::ProgramError> {
77+
fn pack_into_slice(&self, dst: &mut [u8]) -> Result<(), spl_type_length_value::solana_program_error::ProgramError> {
7878
borsh::to_writer(&mut dst[..], self).map_err(Into::into)
7979
}
8080

81-
fn unpack_from_slice(src: &[u8]) -> Result<Self, spl_type_length_value::solana_program::program_error::ProgramError> {
82-
solana_program::borsh1::try_from_slice_unchecked(src).map_err(Into::into)
81+
fn unpack_from_slice(src: &[u8]) -> Result<Self, spl_type_length_value::solana_program_error::ProgramError> {
82+
solana_borsh::v1::try_from_slice_unchecked(src).map_err(Into::into)
8383
}
8484

85-
fn get_packed_len(&self) -> Result<usize, spl_type_length_value::solana_program::program_error::ProgramError> {
86-
solana_program::borsh1::get_instance_packed_len(self).map_err(Into::into)
85+
fn get_packed_len(&self) -> Result<usize, spl_type_length_value::solana_program_error::ProgramError> {
86+
solana_borsh::v1::get_instance_packed_len(self).map_err(Into::into)
8787
}
8888
}
8989
}
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
11
//! Error types
2-
3-
use spl_program_error::*;
2+
use {
3+
solana_decode_error::DecodeError,
4+
solana_msg::msg,
5+
solana_program_error::{PrintProgramError, ProgramError},
6+
};
47

58
/// Errors that may be returned by the Token program.
6-
#[spl_program_error(hash_error_code_start = 1_202_666_432)]
9+
#[repr(u32)]
10+
#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
711
pub enum TlvError {
812
/// Type not found in TLV data
913
#[error("Type not found in TLV data")]
10-
TypeNotFound,
14+
TypeNotFound = 1_202_666_432,
1115
/// Type already exists in TLV data
1216
#[error("Type already exists in TLV data")]
1317
TypeAlreadyExists,
1418
}
19+
20+
impl From<TlvError> for ProgramError {
21+
fn from(e: TlvError) -> Self {
22+
ProgramError::Custom(e as u32)
23+
}
24+
}
25+
26+
impl<T> DecodeError<T> for TlvError {
27+
fn type_of() -> &'static str {
28+
"TlvError"
29+
}
30+
}
31+
32+
impl PrintProgramError for TlvError {
33+
fn print<E>(&self)
34+
where
35+
E: 'static
36+
+ std::error::Error
37+
+ DecodeError<E>
38+
+ PrintProgramError
39+
+ num_traits::FromPrimitive,
40+
{
41+
match self {
42+
TlvError::TypeNotFound => {
43+
msg!("Type not found in TLV data")
44+
}
45+
TlvError::TypeAlreadyExists => {
46+
msg!("Type already exists in TLV data")
47+
}
48+
}
49+
}
50+
}

libraries/type-length-value/src/length.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Module for the length portion of a Type-Length-Value structure
22
use {
33
bytemuck::{Pod, Zeroable},
4-
solana_program::program_error::ProgramError,
4+
solana_program_error::ProgramError,
55
spl_pod::primitives::PodU32,
66
};
77

libraries/type-length-value/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod variable_len_pack;
1212

1313
// Export current sdk types for downstream users building with a different sdk
1414
// version
15-
pub use solana_program;
1615
// Expose derive macro on feature flag
1716
#[cfg(feature = "derive")]
1817
pub use spl_type_length_value_derive::SplBorshVariableLenPack;
18+
pub use {solana_account_info, solana_decode_error, solana_program_error};

libraries/type-length-value/src/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use {
44
crate::{error::TlvError, length::Length, variable_len_pack::VariableLenPack},
55
bytemuck::Pod,
6-
solana_program::{account_info::AccountInfo, program_error::ProgramError},
6+
solana_account_info::AccountInfo,
7+
solana_program_error::ProgramError,
78
spl_discriminator::{ArrayDiscriminator, SplDiscriminate},
89
spl_pod::bytemuck::{pod_from_bytes, pod_from_bytes_mut},
910
std::{cmp::Ordering, mem::size_of},

0 commit comments

Comments
 (0)