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

remove solana-program from spl-pod #7425

Merged
merged 4 commits into from
Oct 31, 2024
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
9 changes: 8 additions & 1 deletion Cargo.lock

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

11 changes: 9 additions & 2 deletions libraries/pod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ borsh = ["dep:borsh"]
borsh = { version = "1.5.1", optional = true }
bytemuck = { version = "1.19.0" }
bytemuck_derive = { version = "1.8.0" }
num-derive = "0.4"
num-traits = "0.2"
serde = { version = "1.0.214", optional = true }
solana-program = "2.1.0"
solana-decode-error = "2.1.0"
solana-msg = "2.1.0"
solana-program-error = "2.1.0"
solana-program-option = "2.1.0"
solana-pubkey = "2.1.0"
solana-zk-sdk = "2.1.0"
spl-program-error = { version = "0.5.0", path = "../program-error" }
thiserror = "1.0"

[dev-dependencies]
serde_json = "1.0.132"
solana-program = "2.1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're only using a particular pubkey in a test, so this should be easy to remove, but it can be done in follow-up work

base64 = { version = "0.22.1" }

[lib]
Expand Down
2 changes: 1 addition & 1 deletion libraries/pod/src/bytemuck.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! wrappers for bytemuck functions

use {bytemuck::Pod, solana_program::program_error::ProgramError};
use {bytemuck::Pod, solana_program_error::ProgramError};

/// On-chain size of a `Pod` type
pub const fn pod_get_packed_len<T: Pod>() -> usize {
Expand Down
44 changes: 42 additions & 2 deletions libraries/pod/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//! 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 spl-pod library.
#[spl_program_error]
#[repr(u32)]
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error, num_derive::FromPrimitive)]
pub enum PodSliceError {
/// Error in checked math operation
#[error("Error in checked math operation")]
Expand All @@ -14,3 +19,38 @@ pub enum PodSliceError {
#[error("Provided byte buffer too large for expected type")]
BufferTooLarge,
}

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

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

impl PrintProgramError for PodSliceError {
fn print<E>(&self)
where
E: 'static
+ std::error::Error
+ DecodeError<E>
+ PrintProgramError
+ num_traits::FromPrimitive,
{
match self {
PodSliceError::CalculationFailure => {
msg!("Error in checked math operation")
}
PodSliceError::BufferTooSmall => {
msg!("Provided byte buffer too small for expected type")
}
PodSliceError::BufferTooLarge => {
msg!("Provided byte buffer too large for expected type")
}
}
}
}
4 changes: 3 additions & 1 deletion libraries/pod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ pub mod slice;

// Export current sdk types for downstream users building with a different sdk
// version
pub use solana_program;
pub use {
solana_decode_error, solana_msg, solana_program_error, solana_program_option, solana_pubkey,
};
8 changes: 3 additions & 5 deletions libraries/pod/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

use {
bytemuck::{Pod, Zeroable},
solana_program::{
program_error::ProgramError,
program_option::COption,
pubkey::{Pubkey, PUBKEY_BYTES},
},
solana_program_error::ProgramError,
solana_program_option::COption,
solana_pubkey::{Pubkey, PUBKEY_BYTES},
};

/// Trait for types that can be `None`.
Expand Down
6 changes: 4 additions & 2 deletions libraries/pod/src/optional_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use {
bytemuck_derive::{Pod, Zeroable},
solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey},
solana_program_error::ProgramError,
solana_program_option::COption,
solana_pubkey::Pubkey,
solana_zk_sdk::encryption::pod::elgamal::PodElGamalPubkey,
};
#[cfg(feature = "serde-traits")]
Expand Down Expand Up @@ -220,7 +222,7 @@ mod tests {
super::*,
crate::bytemuck::pod_from_bytes,
base64::{prelude::BASE64_STANDARD, Engine},
solana_program::pubkey::PUBKEY_BYTES,
solana_pubkey::PUBKEY_BYTES,
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion libraries/pod/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
primitives::PodU32,
},
bytemuck::Pod,
solana_program::program_error::ProgramError,
solana_program_error::ProgramError,
};

const LENGTH_SIZE: usize = std::mem::size_of::<PodU32>();
Expand Down
Loading