diff --git a/src/contract/mod.rs b/src/contract/mod.rs index 823d74f..faf90bb 100644 --- a/src/contract/mod.rs +++ b/src/contract/mod.rs @@ -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 { diff --git a/src/oracles.rs b/src/oracles.rs index e0efb72..927c023 100644 --- a/src/oracles.rs +++ b/src/oracles.rs @@ -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 { (0..self.outcome_messages.len())