mirror of
https://github.com/conduition/dlctix.git
synced 2026-01-30 13:15:11 +01:00
reusable method to check if an outcome is valid
This commit is contained in:
@@ -118,18 +118,9 @@ impl ContractParameters {
|
||||
|
||||
for (outcome, payout_map) in self.outcome_payouts.iter() {
|
||||
// Check for unknown outcomes.
|
||||
match outcome {
|
||||
&Outcome::Attestation(outcome_index) => {
|
||||
if outcome_index >= self.event.outcome_messages.len() {
|
||||
return Err(Error);
|
||||
}
|
||||
}
|
||||
Outcome::Expiry => {
|
||||
if self.event.expiry.is_none() {
|
||||
return Err(Error);
|
||||
}
|
||||
}
|
||||
};
|
||||
if !self.event.is_valid_outcome(outcome) {
|
||||
return Err(Error);
|
||||
}
|
||||
|
||||
// Check for empty payout map.
|
||||
if payout_map.len() == 0 {
|
||||
|
||||
@@ -65,6 +65,15 @@ impl EventAnnouncement {
|
||||
Some(k + e * d)
|
||||
}
|
||||
|
||||
/// Returns true if the given outcome is a valid outcome to wager on
|
||||
/// for this event.
|
||||
pub fn is_valid_outcome(&self, outcome: &Outcome) -> bool {
|
||||
match outcome {
|
||||
&Outcome::Attestation(i) => i < self.outcome_messages.len(),
|
||||
Outcome::Expiry => self.expiry.is_some(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over all possible outcomes in the event.
|
||||
pub fn all_outcomes(&self) -> impl IntoIterator<Item = Outcome> {
|
||||
(0..self.outcome_messages.len())
|
||||
|
||||
Reference in New Issue
Block a user