Skip to content

Commit

Permalink
refactor(target_chains/solana): add format_matches to all accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed Sep 5, 2024
1 parent 4df7172 commit 9db80bb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
use bytemuck::from_bytes;

pub mod buffer;
pub mod config;
pub mod errors;
pub mod publisher_config;
pub mod buffer;

fn format(data: &[u8]) -> Option<u32> {
if data.len() < size_of::<u32>() {
return None;
}
let format: &u32 = from_bytes(&data[..size_of::<u32>()]);
Some(*format)
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ impl BufferedPrice {
}

pub fn format_matches(data: &[u8]) -> bool {
if data.len() < size_of::<u32>() {
return false;
}
let format: &u32 = from_bytes(&data[..size_of::<u32>()]);
*format == FORMAT
super::format(data).map_or(false, |f| f == FORMAT)
}

pub fn read(data: &[u8]) -> Result<(&BufferHeader, &[BufferedPrice]), ReadAccountError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use super::errors::ReadAccountError;
/// Account Magic to avoid Account Confusiong
const FORMAT: u32 = 1505352794;

pub fn format_matches(data: &[u8]) -> bool {
super::format(data).map_or(false, |f| f == FORMAT)
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Zeroable, Pod)]
#[repr(C, packed)]
pub struct Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use super::errors::ReadAccountError;
/// Account Magic to avoid Account Confusiong
const FORMAT: u32 = 2258188348;

pub fn format_matches(data: &[u8]) -> bool {
super::format(data).map_or(false, |f| f == FORMAT)
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Zeroable, Pod)]
#[repr(C, packed)]
pub struct PublisherConfig {
Expand Down

0 comments on commit 9db80bb

Please sign in to comment.