dlc_manager/contract/
signed_contract.rs

1//! #SignedContract
2
3use crate::conversion_utils::PROTOCOL_VERSION;
4use crate::ChannelId;
5
6use super::accepted_contract::AcceptedContract;
7use dlc_messages::CetAdaptorSignature;
8use dlc_messages::CetAdaptorSignatures;
9use dlc_messages::FundingSignatures;
10use dlc_messages::SignDlc;
11use secp256k1_zkp::ecdsa::Signature;
12use secp256k1_zkp::EcdsaAdaptorSignature;
13
14/// Contain information about a contract that was fully signed.
15#[derive(Clone)]
16pub struct SignedContract {
17    /// The accepted contract that was signed.
18    pub accepted_contract: AcceptedContract,
19    /// The adaptor signatures of the offering party (None if offering party).
20    pub adaptor_signatures: Option<Vec<EcdsaAdaptorSignature>>,
21    /// The refund signature of the offering party.
22    pub offer_refund_signature: Signature,
23    /// The signatures for the funding inputs of the offering party.
24    pub funding_signatures: FundingSignatures,
25    /// The [`ChannelId`] to which the contract was associated if any.
26    pub channel_id: Option<ChannelId>,
27}
28
29impl SignedContract {
30    pub(crate) fn get_sign_dlc(
31        &self,
32        cet_adaptor_signatures: Vec<EcdsaAdaptorSignature>,
33    ) -> SignDlc {
34        let contract_id = self.accepted_contract.get_contract_id();
35
36        SignDlc {
37            protocol_version: PROTOCOL_VERSION,
38            contract_id,
39            cet_adaptor_signatures: CetAdaptorSignatures {
40                ecdsa_adaptor_signatures: cet_adaptor_signatures
41                    .into_iter()
42                    .map(|x| CetAdaptorSignature { signature: x })
43                    .collect(),
44            },
45            refund_signature: self.offer_refund_signature,
46            funding_signatures: self.funding_signatures.clone(),
47        }
48    }
49}