1#![allow(missing_docs)]
18#![allow(deprecated)]
19
20use std::fmt::Display;
21
22#[deprecated(since = "1.0.0", note = "Use crate::Error instead")]
28#[derive(Debug, PartialEq)]
29pub struct SolanaError {
30 error_msg: String,
31 error_name: String,
32 #[allow(unused)]
33 error_code_number: u32,
34 #[allow(unused)]
35 error_origin: Option<String>,
36 #[allow(unused)]
37 compared_values: Option<String>
38}
39
40impl Display for SolanaError {
41 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
42 write!(f, "Error: {} - {}", self.error_name, self.error_msg)
43 }
44}
45
46impl std::error::Error for SolanaError {}
47
48#[deprecated(since = "1.0.0", note = "Use crate::Error variants instead")]
54pub fn err(msg: &str) -> SolanaError {
55 SolanaError {
56 error_msg: msg.to_string(),
57 error_name: "Exception".to_string(),
58 error_code_number: 0,
59 error_origin: None,
60 compared_values: None
61 }
62}
63
64#[deprecated(since = "1.0.0", note = "Use crate::encoding::hex_utils::bytes_to_u128 instead")]
74pub fn vec_to_u128(vec: &[u8]) -> u128 {
75 let mut array = [0u8; 16];
76 array.copy_from_slice(vec);
77 u128::from_be_bytes(array)
78}
79
80#[deprecated(since = "1.0.0", note = "Will be removed in 2.0")]
86pub fn bytes_to_binary(i: &[u8; 32], r: &mut Vec<u8>) {
87 for m in i.iter() {
88 format!("{:8b}", m).chars().for_each(|b| if b == '1' { r.push(1); } else { r.push(0) } );
89 }
90}
91
92impl From<SolanaError> for crate::Error {
94 fn from(err: SolanaError) -> Self {
95 crate::Error::ParseError(err.error_msg)
96 }
97}