-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Format * CI * Fixed * Add comment to README * Format config * Fix build * Log time and ema * Fix ema deserialize * Revert format * Add expo * Fix comments * Unused import Co-authored-by: Guillermo Bescos <guibescos>
- Loading branch information
Showing
6 changed files
with
99 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::c_oracle_header::size_t; | ||
use crate::error::OracleError; | ||
use borsh::BorshDeserialize; | ||
use solana_program::account_info::AccountInfo; | ||
use solana_program::program_error::ProgramError; | ||
use std::mem::size_of; | ||
use std::result::Result; | ||
|
||
/// Deserialize field in `source` with offset `offset` | ||
pub fn deserialize_single_field_from_buffer<T: BorshDeserialize>( | ||
source: &[u8], | ||
offset: Option<size_t>, | ||
) -> Result<T, ProgramError> { | ||
let start: usize = offset | ||
.unwrap_or(0) | ||
.try_into() | ||
.map_err(|_| OracleError::IntegerCastingError)?; | ||
|
||
let res: T = T::try_from_slice(&source[start..(start + size_of::<T>())])?; | ||
Ok(res) | ||
} | ||
|
||
/// Deserialize field in `i` rank of `accounts` with offset `offset` | ||
pub fn deserialize_single_field_from_account<T: BorshDeserialize>( | ||
accounts: &[AccountInfo], | ||
i: usize, | ||
offset: Option<size_t>, | ||
) -> Result<T, ProgramError> { | ||
Ok(deserialize_single_field_from_buffer::<T>( | ||
&accounts | ||
.get(i) | ||
.ok_or(ProgramError::NotEnoughAccountKeys)? | ||
.try_borrow_data()?, | ||
offset, | ||
)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod c_oracle_header; | ||
mod deserialize; | ||
mod error; | ||
mod log; | ||
mod processor; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters