From dbce9fc0d56c31bb72496d035e5e7c86d6a33860 Mon Sep 17 00:00:00 2001 From: conduition Date: Sun, 10 Mar 2024 06:05:10 +0000 Subject: [PATCH] add OutcomeIndex alias for outcome indexes --- src/contract/mod.rs | 6 +++++- src/contract/outcome.rs | 6 +++--- src/lib.rs | 11 +++++++---- src/oracles.rs | 4 +++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/contract/mod.rs b/src/contract/mod.rs index 79b8be6..7b87a05 100644 --- a/src/contract/mod.rs +++ b/src/contract/mod.rs @@ -19,6 +19,10 @@ use std::collections::{BTreeMap, BTreeSet}; /// index in the sorted set of players. pub type PlayerIndex = usize; +/// A type alias for clarity. Players in the DLC are often referred to by their +/// index in the sorted set of players. +pub type OutcomeIndex = usize; + /// Represents a mapping of player to payout weight for a given outcome. /// /// A player's payout under an outcome is proportional to the size of their payout weight @@ -82,7 +86,7 @@ pub struct ContractParameters { #[derive(Clone, Copy, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)] pub enum Outcome { /// Indicates the oracle attested to a particular outcome of the given index. - Attestation(usize), + Attestation(OutcomeIndex), /// Indicates the oracle failed to attest to any outcome, and the event expiry /// timelock was reached. diff --git a/src/contract/outcome.rs b/src/contract/outcome.rs index 6d009a2..5b6ee60 100644 --- a/src/contract/outcome.rs +++ b/src/contract/outcome.rs @@ -8,7 +8,7 @@ use secp::{Point, Scalar}; use std::collections::{BTreeMap, BTreeSet}; use crate::{ - contract::{ContractParameters, Outcome}, + contract::{ContractParameters, Outcome, OutcomeIndex}, errors::Error, spend_info::{FundingSpendInfo, OutcomeSpendInfo}, }; @@ -226,7 +226,7 @@ pub(crate) fn verify_outcome_tx_partial_signatures( pub(crate) struct OutcomeSignatures { /// A set of adaptor signatures which can be unlocked by the oracle's attestation /// for each outcome. - pub(crate) outcome_tx_signatures: BTreeMap, + pub(crate) outcome_tx_signatures: BTreeMap, /// The complete signature on the expiry transaction. This is `None` if the /// [`ContractParameters::outcome_payouts`] field does not contain an @@ -312,7 +312,7 @@ pub(crate) fn verify_outcome_tx_aggregated_signatures( params: &ContractParameters, our_pubkey: Point, outcome_build_out: &OutcomeTransactionBuildOutput, - outcome_tx_signatures: &BTreeMap, + outcome_tx_signatures: &BTreeMap, expiry_tx_signature: Option, ) -> Result<(), Error> { let funding_spend_info = &outcome_build_out.funding_spend_info; diff --git a/src/lib.rs b/src/lib.rs index 7118690..5f26e1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, }; -pub use contract::{ContractParameters, Outcome, PlayerIndex, SigMap, WinCondition}; +pub use contract::{ContractParameters, Outcome, OutcomeIndex, PlayerIndex, SigMap, WinCondition}; pub use oracles::EventAnnouncement; pub use parties::{MarketMaker, Player}; @@ -420,7 +420,7 @@ pub struct ContractSignatures { /// [`EventAnnouncement::outcome_messages`]. Each adaptor signature can be decrypted /// by the [`EventAnnouncement`]'s oracle producing an attestation signature using /// [`EventAnnouncement::attestation_secret`]. - pub outcome_tx_signatures: BTreeMap, + pub outcome_tx_signatures: BTreeMap, /// A set of signatures needed for broadcasting split transactions. Each signature /// is specific to a certain combination of player and outcome. pub split_tx_signatures: BTreeMap, @@ -492,7 +492,10 @@ impl SignedContract { } /// Return an unsigned outcome transaction. - pub fn unsigned_outcome_tx<'a>(&'a self, outcome_index: usize) -> Option<&'a Transaction> { + pub fn unsigned_outcome_tx<'a>( + &'a self, + outcome_index: OutcomeIndex, + ) -> Option<&'a Transaction> { self.dlc .outcome_tx_build .outcome_txs() @@ -503,7 +506,7 @@ impl SignedContract { /// to a specific outcome. pub fn signed_outcome_tx( &self, - outcome_index: usize, + outcome_index: OutcomeIndex, attestation: impl Into, ) -> Result { let attestation = attestation.into(); diff --git a/src/oracles.rs b/src/oracles.rs index be0f69f..171fc07 100644 --- a/src/oracles.rs +++ b/src/oracles.rs @@ -1,5 +1,7 @@ use secp::{MaybePoint, MaybeScalar, Point, Scalar}; +use crate::OutcomeIndex; + /// An oracle's announcement of a future event. #[derive(Debug, Clone)] pub struct EventAnnouncement { @@ -18,7 +20,7 @@ pub struct EventAnnouncement { impl EventAnnouncement { /// Computes the oracle's locking point for the given outcome index. - pub fn attestation_lock_point(&self, index: usize) -> Option { + pub fn attestation_lock_point(&self, index: OutcomeIndex) -> Option { let msg = &self.outcome_messages.get(index)?; let e: MaybeScalar = musig2::compute_challenge_hash_tweak(