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

Commit 0189588

Browse files
authored
remove solana-program from spl-pod (#7425)
* remove solana-program from spl-pod * fmt * add back repr(32) * typo
1 parent bd6b05b commit 0189588

File tree

8 files changed

+71
-15
lines changed

8 files changed

+71
-15
lines changed

Cargo.lock

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

libraries/pod/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ borsh = ["dep:borsh"]
1515
borsh = { version = "1.5.1", optional = true }
1616
bytemuck = { version = "1.19.0" }
1717
bytemuck_derive = { version = "1.8.0" }
18+
num-derive = "0.4"
19+
num-traits = "0.2"
1820
serde = { version = "1.0.214", optional = true }
19-
solana-program = "2.1.0"
21+
solana-decode-error = "2.1.0"
22+
solana-msg = "2.1.0"
23+
solana-program-error = "2.1.0"
24+
solana-program-option = "2.1.0"
25+
solana-pubkey = "2.1.0"
2026
solana-zk-sdk = "2.1.0"
21-
spl-program-error = { version = "0.5.0", path = "../program-error" }
27+
thiserror = "1.0"
2228

2329
[dev-dependencies]
2430
serde_json = "1.0.132"
31+
solana-program = "2.1.0"
2532
base64 = { version = "0.22.1" }
2633

2734
[lib]

libraries/pod/src/bytemuck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! wrappers for bytemuck functions
22
3-
use {bytemuck::Pod, solana_program::program_error::ProgramError};
3+
use {bytemuck::Pod, solana_program_error::ProgramError};
44

55
/// On-chain size of a `Pod` type
66
pub const fn pod_get_packed_len<T: Pod>() -> usize {

libraries/pod/src/error.rs

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

48
/// Errors that may be returned by the spl-pod library.
5-
#[spl_program_error]
9+
#[repr(u32)]
10+
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error, num_derive::FromPrimitive)]
611
pub enum PodSliceError {
712
/// Error in checked math operation
813
#[error("Error in checked math operation")]
@@ -14,3 +19,38 @@ pub enum PodSliceError {
1419
#[error("Provided byte buffer too large for expected type")]
1520
BufferTooLarge,
1621
}
22+
23+
impl From<PodSliceError> for ProgramError {
24+
fn from(e: PodSliceError) -> Self {
25+
ProgramError::Custom(e as u32)
26+
}
27+
}
28+
29+
impl<T> solana_decode_error::DecodeError<T> for PodSliceError {
30+
fn type_of() -> &'static str {
31+
"PodSliceError"
32+
}
33+
}
34+
35+
impl PrintProgramError for PodSliceError {
36+
fn print<E>(&self)
37+
where
38+
E: 'static
39+
+ std::error::Error
40+
+ DecodeError<E>
41+
+ PrintProgramError
42+
+ num_traits::FromPrimitive,
43+
{
44+
match self {
45+
PodSliceError::CalculationFailure => {
46+
msg!("Error in checked math operation")
47+
}
48+
PodSliceError::BufferTooSmall => {
49+
msg!("Provided byte buffer too small for expected type")
50+
}
51+
PodSliceError::BufferTooLarge => {
52+
msg!("Provided byte buffer too large for expected type")
53+
}
54+
}
55+
}
56+
}

libraries/pod/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ pub mod slice;
99

1010
// Export current sdk types for downstream users building with a different sdk
1111
// version
12-
pub use solana_program;
12+
pub use {
13+
solana_decode_error, solana_msg, solana_program_error, solana_program_option, solana_pubkey,
14+
};

libraries/pod/src/option.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
99
use {
1010
bytemuck::{Pod, Zeroable},
11-
solana_program::{
12-
program_error::ProgramError,
13-
program_option::COption,
14-
pubkey::{Pubkey, PUBKEY_BYTES},
15-
},
11+
solana_program_error::ProgramError,
12+
solana_program_option::COption,
13+
solana_pubkey::{Pubkey, PUBKEY_BYTES},
1614
};
1715

1816
/// Trait for types that can be `None`.

libraries/pod/src/optional_keys.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
44
use {
55
bytemuck_derive::{Pod, Zeroable},
6-
solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey},
6+
solana_program_error::ProgramError,
7+
solana_program_option::COption,
8+
solana_pubkey::Pubkey,
79
solana_zk_sdk::encryption::pod::elgamal::PodElGamalPubkey,
810
};
911
#[cfg(feature = "serde-traits")]
@@ -220,7 +222,7 @@ mod tests {
220222
super::*,
221223
crate::bytemuck::pod_from_bytes,
222224
base64::{prelude::BASE64_STANDARD, Engine},
223-
solana_program::pubkey::PUBKEY_BYTES,
225+
solana_pubkey::PUBKEY_BYTES,
224226
};
225227

226228
#[test]

libraries/pod/src/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {
99
primitives::PodU32,
1010
},
1111
bytemuck::Pod,
12-
solana_program::program_error::ProgramError,
12+
solana_program_error::ProgramError,
1313
};
1414

1515
const LENGTH_SIZE: usize = std::mem::size_of::<PodU32>();

0 commit comments

Comments
 (0)