rename to get_median
This commit is contained in:
parent
27f15a0c25
commit
26f529d304
|
@ -175,6 +175,15 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flux-aggregator-demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"flux-aggregator",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.12.3"
|
||||
|
@ -567,15 +576,6 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-program-demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"flux-aggregator",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-sdk-macro"
|
||||
version = "1.4.14"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "solana-program-demo"
|
||||
name = "flux-aggregator-demo"
|
||||
version = "0.1.0"
|
||||
authors = ["czl1378 <czl1378@126.com>"]
|
||||
edition = "2018"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
|
||||
use solana_program::{
|
||||
account_info::{next_account_info, AccountInfo},
|
||||
entrypoint,
|
||||
info,
|
||||
account_info::{next_account_info, AccountInfo},
|
||||
entrypoint,
|
||||
msg,
|
||||
entrypoint::ProgramResult,
|
||||
program_error::{ProgramError},
|
||||
pubkey::Pubkey,
|
||||
|
@ -19,18 +19,18 @@ fn process_instruction(
|
|||
accounts: &[AccountInfo], // The account to say hello to
|
||||
_instruction_data: &[u8], // A number to store
|
||||
) -> ProgramResult {
|
||||
|
||||
|
||||
let accounts_iter = &mut accounts.iter();
|
||||
|
||||
// the account to store data
|
||||
let aggregator_info = next_account_info(accounts_iter)?;
|
||||
|
||||
let value = flux_aggregator::get_submission_value(aggregator_info)?;
|
||||
let value = flux_aggregator::get_median(aggregator_info)?;
|
||||
|
||||
// show the value and then return error
|
||||
// to demonstrate we've got the aggregator value
|
||||
info!(&format!("aggregator value: {:?}", value));
|
||||
msg!(&format!("aggregator value: {:?}", value));
|
||||
|
||||
return Err(ProgramError::MissingRequiredSignature);
|
||||
|
||||
|
||||
}
|
|
@ -21,14 +21,14 @@ use error::Error;
|
|||
use state::Aggregator;
|
||||
|
||||
/// Get median value from the aggregator account
|
||||
pub fn get_submission_value(
|
||||
pub fn get_median(
|
||||
aggregator_info: &AccountInfo
|
||||
) -> Result<u64, ProgramError> {
|
||||
let aggregator = Aggregator::unpack_unchecked(&aggregator_info.data.borrow())?;
|
||||
if !aggregator.is_initialized {
|
||||
return Err(Error::NotFoundAggregator.into());
|
||||
}
|
||||
|
||||
|
||||
let submissions = aggregator.submissions;
|
||||
|
||||
let mut values = vec![];
|
||||
|
@ -42,7 +42,7 @@ pub fn get_submission_value(
|
|||
|
||||
// get median value
|
||||
values.sort();
|
||||
|
||||
|
||||
let l = values.len();
|
||||
let i = l / 2;
|
||||
if l % 2 == 0 {
|
||||
|
@ -52,5 +52,5 @@ pub fn get_submission_value(
|
|||
}
|
||||
}
|
||||
|
||||
// Export current sdk types for downstream users building with a different
|
||||
// Export current sdk types for downstream users building with a different
|
||||
pub use solana_program;
|
Loading…
Reference in New Issue