Skip to content

Commit d556bee

Browse files
committed
add more message for Writeable
1 parent 761649b commit d556bee

File tree

1 file changed

+87
-80
lines changed

1 file changed

+87
-80
lines changed

src/ln/msgs.rs

Lines changed: 87 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,86 @@ impl_writeable!(AcceptChannel, {
17191719
shutdown_scriptpubkey
17201720
});
17211721

1722+
impl_writeable!(AnnouncementSignatures, {
1723+
channel_id,
1724+
short_channel_id,
1725+
node_signature,
1726+
bitcoin_signature
1727+
});
1728+
1729+
impl<W: ::std::io::Write> Writeable<W> for ChannelReestablish {
1730+
fn write(&self, w: &mut Writer<W>) -> Result<(), DecodeError> {
1731+
self.channel_id.write(w)?;
1732+
self.next_local_commitment_number.write(w)?;
1733+
self.next_remote_commitment_number.write(w)?;
1734+
if let Some(ref data_loss_protect) = self.data_loss_protect {
1735+
data_loss_protect.your_last_per_commitment_secret.write(w)?;
1736+
data_loss_protect.my_current_per_commitment_point.write(w)?;
1737+
}
1738+
Ok(())
1739+
}
1740+
}
1741+
1742+
impl<R: ::std::io::Read> Readable<R> for ChannelReestablish{
1743+
fn read(r: &mut Reader<R>) -> Result<Self, DecodeError> {
1744+
Ok(Self {
1745+
channel_id: Readable::read(r)?,
1746+
next_local_commitment_number: Readable::read(r)?,
1747+
next_remote_commitment_number: Readable::read(r)?,
1748+
data_loss_protect: {
1749+
let mut buf = [0; 32+33];
1750+
match r.read_exact(&mut buf) {
1751+
Ok(()) => Some(DataLossProtect {
1752+
your_last_per_commitment_secret: {
1753+
let mut a: [u8; 32] = Default::default();
1754+
a.copy_from_slice(&buf[..32]);
1755+
a
1756+
},
1757+
my_current_per_commitment_point: secp_pubkey!(&Secp256k1::without_caps(), &buf[32..]),
1758+
}),
1759+
Err(DecodeError::ShortRead) => None,
1760+
Err(e) => return Err(e)
1761+
}
1762+
}
1763+
})
1764+
}
1765+
}
1766+
1767+
impl_writeable!(ClosingSigned, {
1768+
channel_id,
1769+
fee_satoshis,
1770+
signature
1771+
});
1772+
1773+
impl_writeable!(CommitmentSigned, {
1774+
channel_id,
1775+
signature,
1776+
htlc_signatures
1777+
});
1778+
1779+
impl_writeable!(DecodedOnionErrorPacket, {
1780+
hmac,
1781+
failuremsg,
1782+
pad
1783+
});
1784+
1785+
impl_writeable!(FundingCreated, {
1786+
temporary_channel_id,
1787+
funding_txid,
1788+
funding_output_index,
1789+
signature
1790+
});
1791+
1792+
impl_writeable!(FundingSigned, {
1793+
channel_id,
1794+
signature
1795+
});
1796+
1797+
impl_writeable!(FundingLocked, {
1798+
channel_id,
1799+
next_per_commitment_point
1800+
});
1801+
17221802
impl_writeable!(OpenChannel, {
17231803
chain_hash,
17241804
temporary_channel_id,
@@ -1741,20 +1821,9 @@ impl_writeable!(OpenChannel, {
17411821
shutdown_scriptpubkey
17421822
});
17431823

1744-
impl_writeable!(FundingCreated, {
1745-
temporary_channel_id,
1746-
funding_txid,
1747-
funding_output_index,
1748-
signature
1749-
});
1750-
1751-
impl_writeable!(FundingSigned, {
1752-
channel_id,
1753-
signature
1754-
});
1755-
1756-
impl_writeable!(FundingLocked, {
1824+
impl_writeable!(RevokeAndACK, {
17571825
channel_id,
1826+
per_commitment_secret,
17581827
next_per_commitment_point
17591828
});
17601829

@@ -1763,16 +1832,10 @@ impl_writeable!(Shutdown, {
17631832
scriptpubkey
17641833
});
17651834

1766-
impl_writeable!(ClosingSigned, {
1767-
channel_id,
1768-
fee_satoshis,
1769-
signature
1770-
});
1771-
1772-
impl_writeable!(UpdateFulfillHTLC, {
1835+
impl_writeable!(UpdateFailHTLC, {
17731836
channel_id,
17741837
htlc_id,
1775-
payment_preimage
1838+
reason
17761839
});
17771840

17781841
impl_writeable!(UpdateFailMalformedHTLC, {
@@ -1782,40 +1845,21 @@ impl_writeable!(UpdateFailMalformedHTLC, {
17821845
failure_code
17831846
});
17841847

1785-
impl_writeable!(CommitmentSigned, {
1786-
channel_id,
1787-
signature,
1788-
htlc_signatures
1789-
});
1790-
1791-
impl_writeable!(RevokeAndACK, {
1792-
channel_id,
1793-
per_commitment_secret,
1794-
next_per_commitment_point
1795-
});
1796-
17971848
impl_writeable!(UpdateFee, {
17981849
channel_id,
17991850
feerate_per_kw
18001851
});
18011852

1802-
impl_writeable!(AnnouncementSignatures, {
1853+
impl_writeable!(UpdateFulfillHTLC, {
18031854
channel_id,
1804-
short_channel_id,
1805-
node_signature,
1806-
bitcoin_signature
1855+
htlc_id,
1856+
payment_preimage
18071857
});
18081858

18091859
impl_writeable!(OnionErrorPacket, {
18101860
data
18111861
});
18121862

1813-
impl_writeable!(UpdateFailHTLC, {
1814-
channel_id,
1815-
htlc_id,
1816-
reason
1817-
});
1818-
18191863
impl<W: ::std::io::Write> Writeable<W> for OnionPacket {
18201864
fn write(&self, w: &mut Writer<W>) -> Result<(), DecodeError> {
18211865
self.version.write(w)?;
@@ -1897,43 +1941,6 @@ impl<R: ::std::io::Read> Readable<R> for Pong {
18971941
}
18981942
}
18991943

1900-
impl<W: ::std::io::Write> Writeable<W> for ChannelReestablish {
1901-
fn write(&self, w: &mut Writer<W>) -> Result<(), DecodeError> {
1902-
self.channel_id.write(w)?;
1903-
self.next_local_commitment_number.write(w)?;
1904-
self.next_remote_commitment_number.write(w)?;
1905-
if let Some(ref data_loss_protect) = self.data_loss_protect {
1906-
data_loss_protect.your_last_per_commitment_secret.write(w)?;
1907-
data_loss_protect.my_current_per_commitment_point.write(w)?;
1908-
}
1909-
Ok(())
1910-
}
1911-
}
1912-
1913-
impl<R: ::std::io::Read> Readable<R> for ChannelReestablish{
1914-
fn read(r: &mut Reader<R>) -> Result<Self, DecodeError> {
1915-
Ok(Self {
1916-
channel_id: Readable::read(r)?,
1917-
next_local_commitment_number: Readable::read(r)?,
1918-
next_remote_commitment_number: Readable::read(r)?,
1919-
data_loss_protect: {
1920-
let mut buf = [0; 32+33];
1921-
match r.read_exact(&mut buf) {
1922-
Ok(()) => Some(DataLossProtect {
1923-
your_last_per_commitment_secret: {
1924-
let mut a: [u8; 32] = Default::default();
1925-
a.copy_from_slice(&buf[..32]);
1926-
a
1927-
},
1928-
my_current_per_commitment_point: secp_pubkey!(&Secp256k1::without_caps(), &buf[32..]),
1929-
}),
1930-
Err(DecodeError::ShortRead) => None,
1931-
Err(e) => return Err(e)
1932-
}
1933-
}
1934-
})
1935-
}
1936-
}
19371944

19381945
#[cfg(test)]
19391946
mod tests {

0 commit comments

Comments
 (0)