From 35ed57ae23c6c9dea6d806ba0998527e719286b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kalbarczyk?= Date: Fri, 4 Oct 2024 13:18:53 +0200 Subject: [PATCH] to_vec --- src/core/config_validation.sw | 47 +++++++++++++++++++---------------- src/core/errors.sw | 10 +++----- src/core/processor.sw | 1 - 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/core/config_validation.sw b/src/core/config_validation.sw index dc7ec3b..423516d 100644 --- a/src/core/config_validation.sw +++ b/src/core/config_validation.sw @@ -9,13 +9,19 @@ trait Validation { fn validate_timestamps(self, payload: Payload) -> u64; fn validate_signer_count(self, values: Vec>); fn validate_signer(self, data_package: DataPackage, index: u64) -> u64; - } impl Validation for Config { - fn check_parameters(self) { assert_signers(self.signers, self.signer_count_threshold); + + require(self.feed_ids.len() > 0, RedStoneError::EmptyFeedIds); + require( + self.feed_ids + .find_duplicate() + .is_none(), + RedStoneError::DuplicatedFeedId, + ) } fn validate_timestamps(self, payload: Payload) -> u64 { @@ -61,27 +67,26 @@ impl Validation for Config { s.unwrap() } - } - fn assert_signers(allowed_signers: Vec, signer_count_threshold: u64) { - require( - allowed_signers - .len() > 0, - RedStoneError::EmptyAllowedSigners, - ); - require( - allowed_signers - .len() >= signer_count_threshold, - RedStoneError::SignerCountThresholdToSmall, - ); - require( - allowed_signers - .find_duplicate() - .is_none(), - RedStoneError::DuplicateSignerFound, - ); - } +fn assert_signers(allowed_signers: Vec, signer_count_threshold: u64) { + require( + allowed_signers + .len() > 0, + RedStoneError::EmptyAllowedSigners, + ); + require( + allowed_signers + .len() >= signer_count_threshold, + RedStoneError::SignerCountThresholdToSmall, + ); + require( + allowed_signers + .find_duplicate() + .is_none(), + RedStoneError::DuplicatedSigner, + ); +} #[test] fn test_validate_one_signer() { diff --git a/src/core/errors.sw b/src/core/errors.sw index 6958100..f642331 100644 --- a/src/core/errors.sw +++ b/src/core/errors.sw @@ -15,12 +15,10 @@ pub const SIGNER_NOT_RECOGNIZED = 0x4e20_0000; /// convert 3_276_800_000 + signer_count * feed_index + signer_index pub const DUPLICATED_VALUE_FOR_SIGNER = 0xc350_0000; - - pub enum RedStoneError { EmptyAllowedSigners: (), + EmptyFeedIds: (), SignerCountThresholdToSmall: (), - DuplicateSignerFound: (), - SenderIsNotTheOwner: (Identity, Option), - TimestampMustBeGreaterThanBefore: (u64, u64), -} \ No newline at end of file + DuplicatedSigner: (), + DuplicatedFeedId: (), +} diff --git a/src/core/processor.sw b/src/core/processor.sw index 5e8a148..c155cfe 100644 --- a/src/core/processor.sw +++ b/src/core/processor.sw @@ -27,7 +27,6 @@ pub fn process_input(bytes: Bytes, config: Config) -> (Vec, u64) { let results = get_feed_values(matrix, config); config.validate_signer_count(results); - (results.aggregated(), timestamp) }