dlc_manager/channel/
ser.rs

1//! # Serialization implementation for DLC channel related structures.
2use super::accepted_channel::AcceptedChannel;
3use super::offered_channel::OfferedChannel;
4use super::party_points::PartyBasePoints;
5use super::signed_channel::{SignedChannel, SignedChannelState};
6use super::{ClosedChannel, ClosedPunishedChannel, ClosingChannel, FailedAccept, FailedSign};
7
8use dlc_messages::ser_impls::{
9    read_ecdsa_adaptor_signature, read_string, write_ecdsa_adaptor_signature, write_string,
10};
11use lightning::ln::msgs::DecodeError;
12use lightning::util::ser::{Readable, Writeable, Writer};
13
14impl_dlc_writeable!(PartyBasePoints, { (own_basepoint, writeable), (publish_basepoint, writeable), (revocation_basepoint, writeable) });
15impl_dlc_writeable!(OfferedChannel, { (offered_contract_id, writeable), (temporary_channel_id, writeable), (party_points, writeable), (per_update_point, writeable), (offer_per_update_seed, writeable), (is_offer_party, writeable), (counter_party, writeable), (cet_nsequence, writeable) });
16impl_dlc_writeable!(AcceptedChannel, {
17    (accepted_contract_id, writeable),
18    (offer_base_points, writeable),
19    (accept_base_points, writeable),
20    (offer_per_update_point, writeable),
21    (accept_per_update_point, writeable),
22    (buffer_transaction, writeable),
23    (buffer_script_pubkey, writeable),
24    (temporary_channel_id, writeable),
25    (channel_id, writeable),
26    (accept_per_update_seed, writeable),
27    (accept_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}),
28    (counter_party, writeable)
29});
30impl_dlc_writeable!(SignedChannel, {
31    (channel_id, writeable),
32    (counter_party, writeable),
33    (temporary_channel_id, writeable),
34    (fund_output_index, usize),
35    (own_points, writeable),
36    (own_params, { cb_writeable, dlc_messages::ser_impls::party_params::write, dlc_messages::ser_impls::party_params::read }),
37    (own_per_update_point, writeable),
38    (counter_points, writeable),
39    (counter_per_update_point, writeable),
40    (counter_params, { cb_writeable, dlc_messages::ser_impls::party_params::write, dlc_messages::ser_impls::party_params::read }),
41    (state, writeable),
42    (update_idx, writeable),
43    (fund_tx, writeable),
44    (fund_script_pubkey, writeable),
45    (roll_back_state, option),
46    (own_per_update_seed, writeable),
47    (counter_party_commitment_secrets, writeable),
48    (fee_rate_per_vb, writeable)
49});
50
51impl_dlc_writeable_enum!(
52    SignedChannelState,;
53    (0, Established, {(signed_contract_id, writeable), (own_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (counter_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (buffer_transaction, writeable), (is_offer, writeable), (total_collateral, writeable), (keys_id, writeable)}),
54    (1, SettledOffered, {(counter_payout, writeable), (next_per_update_point, writeable), (timeout, writeable), (keys_id, writeable)}),
55    (2, SettledReceived, {(own_payout, writeable), (counter_payout, writeable), (counter_next_per_update_point, writeable), (keys_id, writeable)}),
56    (3, SettledAccepted, {(counter_next_per_update_point, writeable), (own_next_per_update_point, writeable), (settle_tx, writeable), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable), (counter_payout, writeable), (keys_id, writeable)}),
57    (4, SettledConfirmed, {(settle_tx, writeable), (counter_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (counter_next_per_update_point, writeable), (own_next_per_update_point, writeable), (timeout, writeable), (own_payout, writeable), (counter_payout, writeable), (keys_id, writeable) }),
58    (5, Settled, {(settle_tx, writeable), (counter_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_payout, writeable), (counter_payout, writeable), (keys_id, writeable)}),
59    (6, RenewOffered, {(offered_contract_id, writeable), (counter_payout, writeable), (is_offer, writeable), (offer_next_per_update_point, writeable), (timeout, writeable), (keys_id, writeable)}),
60    (7, RenewAccepted, {(contract_id, writeable), (offer_per_update_point, writeable), (accept_per_update_point, writeable), (buffer_transaction, writeable), (buffer_script_pubkey, writeable), (timeout, writeable), (own_payout, writeable), (keys_id, writeable)}),
61    (8, RenewConfirmed, {(contract_id, writeable), (offer_per_update_point, writeable), (accept_per_update_point, writeable), (buffer_transaction, writeable), (buffer_script_pubkey, writeable), (offer_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable), (total_collateral, writeable), (keys_id, writeable)}),
62    (10, RenewFinalized, {(contract_id, writeable), (prev_offer_per_update_point, writeable), (buffer_transaction, writeable), (buffer_script_pubkey, writeable), (offer_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (accept_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable), (total_collateral, writeable), (keys_id, writeable)}),
63    (9, Closing, {(buffer_transaction, writeable), (contract_id, writeable), (keys_id, writeable), (is_initiator, writeable)}),
64    (11, CollaborativeCloseOffered, { (counter_payout, writeable), (offer_signature, writeable), (close_tx, writeable), (timeout, writeable), (keys_id, writeable) })
65    ;;
66);
67
68impl_dlc_writeable!(FailedAccept, {(temporary_channel_id, writeable), (error_message, {cb_writeable, write_string, read_string}), (accept_message, writeable), (counter_party, writeable)});
69impl_dlc_writeable!(FailedSign, {(channel_id, writeable), (error_message, {cb_writeable, write_string, read_string}), (sign_message, writeable), (counter_party, writeable)});
70
71impl_dlc_writeable!(ClosingChannel, {
72    (channel_id, writeable),
73    (counter_party, writeable),
74    (temporary_channel_id, writeable),
75    (rollback_state, option),
76    (buffer_transaction, writeable),
77    (contract_id, writeable),
78    (is_closer, writeable)
79
80});
81impl_dlc_writeable!(ClosedChannel, {(channel_id, writeable), (counter_party, writeable), (temporary_channel_id, writeable)});
82impl_dlc_writeable!(ClosedPunishedChannel, {(channel_id, writeable), (counter_party, writeable), (temporary_channel_id, writeable), (punish_txid, writeable)});