Merge pull request #75 from 0xripleys/0xripleys_add_new_fn

Add 'new_from_bytes' function and update dependencies
This commit is contained in:
mgild 2022-12-01 11:47:23 -05:00 committed by GitHub
commit c8d04b0283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 8 deletions

View File

@ -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"

View File

@ -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

View File

@ -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 {