Skip to content

Commit

Permalink
to_vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz2891 committed Oct 4, 2024
1 parent 1195335 commit 35ed57a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
47 changes: 26 additions & 21 deletions src/core/config_validation.sw
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ trait Validation {
fn validate_timestamps(self, payload: Payload) -> u64;
fn validate_signer_count(self, values: Vec<Vec<u256>>);
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 {
Expand Down Expand Up @@ -61,27 +67,26 @@ impl Validation for Config {

s.unwrap()
}

}

fn assert_signers(allowed_signers: Vec<b256>, 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<b256>, 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() {
Expand Down
10 changes: 4 additions & 6 deletions src/core/errors.sw
Original file line number Diff line number Diff line change
Expand Up @@ -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<Identity>),
TimestampMustBeGreaterThanBefore: (u64, u64),
}
DuplicatedSigner: (),
DuplicatedFeedId: (),
}
1 change: 0 additions & 1 deletion src/core/processor.sw
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub fn process_input(bytes: Bytes, config: Config) -> (Vec<u256>, u64) {
let results = get_feed_values(matrix, config);

config.validate_signer_count(results);

(results.aggregated(), timestamp)
}

Expand Down

0 comments on commit 35ed57a

Please sign in to comment.