Skip to content

Commit c56265d

Browse files
committed
Convert SpendableOutputDescriptor to new TLV-based serialization
1 parent 3c93967 commit c56265d

File tree

1 file changed

+25
-56
lines changed

1 file changed

+25
-56
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ impl DelayedPaymentOutputDescriptor {
7373
pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1;
7474
}
7575

76+
impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
77+
(0, outpoint),
78+
(2, per_commitment_point),
79+
(4, to_self_delay),
80+
(6, output),
81+
(8, revocation_pubkey),
82+
(10, channel_keys_id),
83+
(12, channel_value_satoshis),
84+
}, {}, {});
85+
7686
/// Information about a spendable output to our "payment key". See
7787
/// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
7888
#[derive(Clone, Debug, PartialEq)]
@@ -94,6 +104,12 @@ impl StaticPaymentOutputDescriptor {
94104
// redeemscript push length.
95105
pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 34;
96106
}
107+
impl_writeable_tlv_based!(StaticPaymentOutputDescriptor, {
108+
(0, outpoint),
109+
(2, output),
110+
(4, channel_keys_id),
111+
(6, channel_value_satoshis),
112+
}, {}, {});
97113

98114
/// When on-chain outputs are created by rust-lightning (which our counterparty is not able to
99115
/// claim at any point in the future) an event is generated which you must track and be able to
@@ -152,62 +168,15 @@ pub enum SpendableOutputDescriptor {
152168
StaticPaymentOutput(StaticPaymentOutputDescriptor),
153169
}
154170

155-
impl Writeable for SpendableOutputDescriptor {
156-
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
157-
match self {
158-
&SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output } => {
159-
0u8.write(writer)?;
160-
outpoint.write(writer)?;
161-
output.write(writer)?;
162-
},
163-
&SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => {
164-
1u8.write(writer)?;
165-
descriptor.outpoint.write(writer)?;
166-
descriptor.per_commitment_point.write(writer)?;
167-
descriptor.to_self_delay.write(writer)?;
168-
descriptor.output.write(writer)?;
169-
descriptor.revocation_pubkey.write(writer)?;
170-
descriptor.channel_keys_id.write(writer)?;
171-
descriptor.channel_value_satoshis.write(writer)?;
172-
},
173-
&SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => {
174-
2u8.write(writer)?;
175-
descriptor.outpoint.write(writer)?;
176-
descriptor.output.write(writer)?;
177-
descriptor.channel_keys_id.write(writer)?;
178-
descriptor.channel_value_satoshis.write(writer)?;
179-
},
180-
}
181-
Ok(())
182-
}
183-
}
184-
185-
impl Readable for SpendableOutputDescriptor {
186-
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
187-
match Readable::read(reader)? {
188-
0u8 => Ok(SpendableOutputDescriptor::StaticOutput {
189-
outpoint: Readable::read(reader)?,
190-
output: Readable::read(reader)?,
191-
}),
192-
1u8 => Ok(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
193-
outpoint: Readable::read(reader)?,
194-
per_commitment_point: Readable::read(reader)?,
195-
to_self_delay: Readable::read(reader)?,
196-
output: Readable::read(reader)?,
197-
revocation_pubkey: Readable::read(reader)?,
198-
channel_keys_id: Readable::read(reader)?,
199-
channel_value_satoshis: Readable::read(reader)?,
200-
})),
201-
2u8 => Ok(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
202-
outpoint: Readable::read(reader)?,
203-
output: Readable::read(reader)?,
204-
channel_keys_id: Readable::read(reader)?,
205-
channel_value_satoshis: Readable::read(reader)?,
206-
})),
207-
_ => Err(DecodeError::InvalidValue),
208-
}
209-
}
210-
}
171+
impl_writeable_tlv_based_enum!(SpendableOutputDescriptor,
172+
(0, StaticOutput) => {
173+
(0, outpoint),
174+
(2, output),
175+
}, {}, {},
176+
;
177+
(1, DelayedPaymentOutput),
178+
(2, StaticPaymentOutput),
179+
);
211180

212181
/// A trait to sign lightning channel transactions as described in BOLT 3.
213182
///

0 commit comments

Comments
 (0)