event expiry is optional

This commit is contained in:
conduition
2024-03-17 21:27:34 +00:00
parent e80bec45e0
commit 71334d99f9
3 changed files with 24 additions and 9 deletions

View File

@@ -118,11 +118,18 @@ impl ContractParameters {
for (outcome, payout_map) in self.outcome_payouts.iter() {
// Check for unknown outcomes.
if let &Outcome::Attestation(outcome_index) = outcome {
if outcome_index >= self.event.outcome_messages.len() {
return Err(Error);
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);
}
}
};
// Check for empty payout map.
if payout_map.len() == 0 {

View File

@@ -80,7 +80,7 @@ pub(crate) fn build_outcome_txs(
};
let lock_time = match outcome {
Outcome::Expiry => LockTime::from_consensus(params.event.expiry),
Outcome::Expiry => LockTime::from_consensus(params.event.expiry.ok_or(Error)?),
Outcome::Attestation(_) => LockTime::ZERO, // Normal outcome transaction
};
@@ -91,9 +91,9 @@ pub(crate) fn build_outcome_txs(
output: vec![outcome_output],
};
(outcome, outcome_tx)
Ok((outcome, outcome_tx))
})
.collect();
.collect::<Result<_, Error>>()?;
let funding_spend_info =
FundingSpendInfo::new(&params.market_maker, &params.players, params.funding_value)?;

View File

@@ -1,7 +1,7 @@
use secp::{MaybePoint, MaybeScalar, Point, Scalar};
use serde::{Deserialize, Serialize};
use crate::{serialization, OutcomeIndex};
use crate::{serialization, Outcome, OutcomeIndex};
/// An oracle's announcement of a future event.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -17,7 +17,8 @@ pub struct EventAnnouncement {
pub outcome_messages: Vec<Vec<u8>>,
/// The unix timestamp beyond which the oracle is considered to have gone AWOL.
pub expiry: u32,
/// If set to `None`, the event has no expected expiry.
pub expiry: Option<u32>,
}
impl EventAnnouncement {
@@ -63,4 +64,11 @@ impl EventAnnouncement {
);
Some(k + e * d)
}
/// Returns an iterator over all possible outcomes in the event.
pub fn all_outcomes(&self) -> impl IntoIterator<Item = Outcome> {
(0..self.outcome_messages.len())
.map(|i| Outcome::Attestation(i))
.chain(self.expiry.map(|_| Outcome::Expiry))
}
}