Merge pull request #75 from 0xripleys/0xripleys_add_new_fn
Add 'new_from_bytes' function and update dependencies
This commit is contained in:
commit
c8d04b0283
|
@ -22,10 +22,10 @@ cpi = ["no-entrypoint"]
|
|||
devnet = []
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = "0.25.0"
|
||||
anchor-spl = "0.25.0"
|
||||
rust_decimal = { version = "1.18.0" }
|
||||
solana-program = "~1.10.29"
|
||||
anchor-lang = { git = "https://github.com/coral-xyz/anchor.git" }
|
||||
anchor-spl = { git = "https://github.com/coral-xyz/anchor.git" }
|
||||
rust_decimal = "1.26.0"
|
||||
solana-program = "1.10"
|
||||
bytemuck = "1.7.2"
|
||||
superslice = "1"
|
||||
spl-token = "3.3.1"
|
||||
spl-token = "3.3"
|
||||
|
|
|
@ -175,6 +175,34 @@ impl AggregatorAccountData {
|
|||
bytemuck::from_bytes(&data[8..std::mem::size_of::<AggregatorAccountData>() + 8])
|
||||
}))
|
||||
}
|
||||
|
||||
/// Returns the deserialized Switchboard Aggregator account
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `data` - A Solana AccountInfo's data buffer
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// use switchboard_v2::AggregatorAccountData;
|
||||
///
|
||||
/// let data_feed = AggregatorAccountData::new(feed_account_info.try_borrow_data()?)?;
|
||||
/// ```
|
||||
pub fn new_from_bytes(data: &[u8]) -> anchor_lang::Result<&AggregatorAccountData> {
|
||||
if data.len() < AggregatorAccountData::discriminator().len() {
|
||||
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
|
||||
}
|
||||
|
||||
let mut disc_bytes = [0u8; 8];
|
||||
disc_bytes.copy_from_slice(&data[..8]);
|
||||
if disc_bytes != AggregatorAccountData::discriminator() {
|
||||
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
|
||||
}
|
||||
|
||||
Ok(bytemuck::from_bytes(&data[8..std::mem::size_of::<AggregatorAccountData>() + 8]))
|
||||
}
|
||||
|
||||
/// If sufficient oracle responses, returns the latest on-chain result in SwitchboardDecimal format
|
||||
///
|
||||
/// # Examples
|
||||
|
|
|
@ -101,9 +101,7 @@ impl BufferRelayerAccountData {
|
|||
}
|
||||
}
|
||||
impl Discriminator for BufferRelayerAccountData {
|
||||
fn discriminator() -> [u8; 8] {
|
||||
[50, 35, 51, 115, 169, 219, 158, 52]
|
||||
}
|
||||
const DISCRIMINATOR: [u8; 8] = [50, 35, 51, 115, 169, 219, 158, 52];
|
||||
}
|
||||
impl Owner for BufferRelayerAccountData {
|
||||
fn owner() -> solana_program::pubkey::Pubkey {
|
||||
|
|
Loading…
Reference in New Issue