-impl_writeable_tlv_based!(CommitmentTransaction, {
- (0, commitment_number, required),
- (2, to_broadcaster_value_sat, required),
- (4, to_countersignatory_value_sat, required),
- (6, feerate_per_kw, required),
- (8, keys, required),
- (10, built, required),
- (12, htlcs, vec_type),
- (14, opt_anchors, option),
- (16, opt_non_zero_fee_anchors, option),
-});
+impl Writeable for CommitmentTransaction {
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ let legacy_deserialization_prevention_marker = legacy_deserialization_prevention_marker_for_channel_type_features(&self.channel_type_features);
+ write_tlv_fields!(writer, {
+ (0, self.commitment_number, required),
+ (1, self.to_broadcaster_delay, option),
+ (2, self.to_broadcaster_value_sat, required),
+ (4, self.to_countersignatory_value_sat, required),
+ (6, self.feerate_per_kw, required),
+ (8, self.keys, required),
+ (10, self.built, required),
+ (12, self.htlcs, required_vec),
+ (14, legacy_deserialization_prevention_marker, option),
+ (15, self.channel_type_features, required),
+ });
+ Ok(())
+ }
+}
+
+impl Readable for CommitmentTransaction {
+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+ _init_and_read_len_prefixed_tlv_fields!(reader, {
+ (0, commitment_number, required),
+ (1, to_broadcaster_delay, option),
+ (2, to_broadcaster_value_sat, required),
+ (4, to_countersignatory_value_sat, required),
+ (6, feerate_per_kw, required),
+ (8, keys, required),
+ (10, built, required),
+ (12, htlcs, required_vec),
+ (14, _legacy_deserialization_prevention_marker, option),
+ (15, channel_type_features, option),
+ });
+
+ let mut additional_features = ChannelTypeFeatures::empty();
+ additional_features.set_anchors_nonzero_fee_htlc_tx_required();
+ chain::package::verify_channel_type_features(&channel_type_features, Some(&additional_features))?;
+
+ Ok(Self {
+ commitment_number: commitment_number.0.unwrap(),
+ to_broadcaster_value_sat: to_broadcaster_value_sat.0.unwrap(),
+ to_countersignatory_value_sat: to_countersignatory_value_sat.0.unwrap(),
+ to_broadcaster_delay,
+ feerate_per_kw: feerate_per_kw.0.unwrap(),
+ keys: keys.0.unwrap(),
+ built: built.0.unwrap(),
+ htlcs,
+ channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
+ })
+ }
+}