ddk_manager/contract/
signed_contract.rs1use crate::conversion_utils::PROTOCOL_VERSION;
4use crate::utils::get_new_serial_id;
5use crate::ChannelId;
6
7use super::accepted_contract::AcceptedContract;
8use ddk_dlc::dlc_input::DlcInputInfo;
9use ddk_messages::CetAdaptorSignature;
10use ddk_messages::CetAdaptorSignatures;
11use ddk_messages::FundingSignatures;
12use ddk_messages::SignDlc;
13use secp256k1_zkp::ecdsa::Signature;
14use secp256k1_zkp::EcdsaAdaptorSignature;
15
16#[derive(Clone)]
18pub struct SignedContract {
19 pub accepted_contract: AcceptedContract,
21 pub adaptor_signatures: Option<Vec<EcdsaAdaptorSignature>>,
23 pub offer_refund_signature: Signature,
25 pub funding_signatures: FundingSignatures,
27 pub channel_id: Option<ChannelId>,
29}
30
31impl SignedContract {
32 pub(crate) fn get_sign_dlc(
33 &self,
34 cet_adaptor_signatures: Vec<EcdsaAdaptorSignature>,
35 ) -> SignDlc {
36 let contract_id = self.accepted_contract.get_contract_id();
37
38 SignDlc {
39 protocol_version: PROTOCOL_VERSION,
40 contract_id,
41 cet_adaptor_signatures: CetAdaptorSignatures {
42 ecdsa_adaptor_signatures: cet_adaptor_signatures
43 .into_iter()
44 .map(|x| CetAdaptorSignature { signature: x })
45 .collect(),
46 },
47 refund_signature: self.offer_refund_signature,
48 funding_signatures: self.funding_signatures.clone(),
49 }
50 }
51
52 pub(crate) fn get_dlc_input(&self) -> DlcInputInfo {
54 let fund_tx = self.accepted_contract.dlc_transactions.fund.clone();
55
56 let fund_vout = self
57 .accepted_contract
58 .dlc_transactions
59 .get_fund_output_index() as u32;
60 let local_fund_pubkey = self
61 .accepted_contract
62 .offered_contract
63 .offer_params
64 .fund_pubkey;
65 let remote_fund_pubkey = self.accepted_contract.accept_params.fund_pubkey;
66 let fund_amount = self
67 .accepted_contract
68 .dlc_transactions
69 .get_fund_output()
70 .value;
71
72 DlcInputInfo {
73 fund_tx,
74 fund_vout,
75 local_fund_pubkey,
76 remote_fund_pubkey,
77 fund_amount,
78 max_witness_len: 220,
79 input_serial_id: get_new_serial_id(),
80 contract_id: self.accepted_contract.get_contract_id(),
81 }
82 }
83}