Skip to content

Commit e4cbe81

Browse files
committed
f Switch event serialization to use upstream macro
1 parent fa1a3f8 commit e4cbe81

File tree

2 files changed

+35
-82
lines changed

2 files changed

+35
-82
lines changed

Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ description = "A ready-to-go node implementation based on LDK."
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
lightning = { version = "0.0.114", features = ["max_level_trace", "std"] }
13-
lightning-invoice = { version = "0.22" }
14-
lightning-net-tokio = { version = "0.0.114" }
15-
lightning-persister = { version = "0.0.114" }
16-
lightning-background-processor = { version = "0.0.114" }
17-
lightning-rapid-gossip-sync = { version = "0.0.114" }
18-
lightning-transaction-sync = { version = "0.0.114", features = ["esplora-async"] }
12+
#lightning = { version = "0.0.114", features = ["max_level_trace", "std"] }
13+
#lightning-invoice = { version = "0.22" }
14+
#lightning-net-tokio = { version = "0.0.114" }
15+
#lightning-persister = { version = "0.0.114" }
16+
#lightning-background-processor = { version = "0.0.114" }
17+
#lightning-rapid-gossip-sync = { version = "0.0.114" }
18+
#lightning-transaction-sync = { version = "0.0.114", features = ["esplora-async"] }
1919

2020
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
2121
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
@@ -25,13 +25,13 @@ lightning-transaction-sync = { version = "0.0.114", features = ["esplora-async"]
2525
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
2626
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }
2727

28-
#lightning = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase", features = ["max_level_trace", "std"] }
29-
#lightning-invoice = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase" }
30-
#lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase" }
31-
#lightning-persister = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase" }
32-
#lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase" }
33-
#lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase" }
34-
#lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", branch="2022-11-add-transaction-sync-crate-pre-rebase", features = ["esplora-async"] }
28+
lightning = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common", features = ["max_level_trace", "std"] }
29+
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
30+
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
31+
lightning-persister = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
32+
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
33+
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
34+
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common", features = ["esplora-async"] }
3535

3636
#lightning = { path = "../rust-lightning/lightning", features = ["max_level_trace", "std"] }
3737
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }

src/event.rs

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
use crate::logger::{log_error, log_info, Logger};
77

88
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
9+
use lightning::impl_writeable_tlv_based_enum;
910
use lightning::ln::PaymentHash;
1011
use lightning::routing::gossip::NodeId;
1112
use lightning::util::errors::APIError;
@@ -63,74 +64,26 @@ pub enum Event {
6364
},
6465
}
6566

66-
// TODO: Figure out serialization more concretely - see issue #30
67-
impl Readable for Event {
68-
fn read<R: lightning::io::Read>(
69-
reader: &mut R,
70-
) -> Result<Self, lightning::ln::msgs::DecodeError> {
71-
match Readable::read(reader)? {
72-
0u8 => {
73-
let payment_hash: PaymentHash = Readable::read(reader)?;
74-
Ok(Self::PaymentSuccessful { payment_hash })
75-
}
76-
1u8 => {
77-
let payment_hash: PaymentHash = Readable::read(reader)?;
78-
Ok(Self::PaymentFailed { payment_hash })
79-
}
80-
2u8 => {
81-
let payment_hash: PaymentHash = Readable::read(reader)?;
82-
let amount_msat: u64 = Readable::read(reader)?;
83-
Ok(Self::PaymentReceived { payment_hash, amount_msat })
84-
}
85-
3u8 => {
86-
let channel_id: [u8; 32] = Readable::read(reader)?;
87-
let user_channel_id: u128 = Readable::read(reader)?;
88-
Ok(Self::ChannelReady { channel_id, user_channel_id })
89-
}
90-
4u8 => {
91-
let channel_id: [u8; 32] = Readable::read(reader)?;
92-
let user_channel_id: u128 = Readable::read(reader)?;
93-
Ok(Self::ChannelClosed { channel_id, user_channel_id })
94-
}
95-
_ => Err(lightning::ln::msgs::DecodeError::InvalidValue),
96-
}
97-
}
98-
}
99-
100-
impl Writeable for Event {
101-
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), lightning::io::Error> {
102-
match self {
103-
Self::PaymentSuccessful { payment_hash } => {
104-
0u8.write(writer)?;
105-
payment_hash.write(writer)?;
106-
Ok(())
107-
}
108-
Self::PaymentFailed { payment_hash } => {
109-
1u8.write(writer)?;
110-
payment_hash.write(writer)?;
111-
Ok(())
112-
}
113-
Self::PaymentReceived { payment_hash, amount_msat } => {
114-
2u8.write(writer)?;
115-
payment_hash.write(writer)?;
116-
amount_msat.write(writer)?;
117-
Ok(())
118-
}
119-
Self::ChannelReady { channel_id, user_channel_id } => {
120-
3u8.write(writer)?;
121-
channel_id.write(writer)?;
122-
user_channel_id.write(writer)?;
123-
Ok(())
124-
}
125-
Self::ChannelClosed { channel_id, user_channel_id } => {
126-
4u8.write(writer)?;
127-
channel_id.write(writer)?;
128-
user_channel_id.write(writer)?;
129-
Ok(())
130-
}
131-
}
132-
}
133-
}
67+
impl_writeable_tlv_based_enum!(Event,
68+
(0, PaymentSuccessful) => {
69+
(0, payment_hash, required),
70+
},
71+
(1, PaymentFailed) => {
72+
(0, payment_hash, required),
73+
},
74+
(2, PaymentReceived) => {
75+
(0, payment_hash, required),
76+
(1, amount_msat, required),
77+
},
78+
(3, ChannelReady) => {
79+
(0, channel_id, required),
80+
(1, user_channel_id, required),
81+
},
82+
(4, ChannelClosed) => {
83+
(0, channel_id, required),
84+
(1, user_channel_id, required),
85+
};
86+
);
13487

13588
pub(crate) struct EventQueue<K: Deref>
13689
where

0 commit comments

Comments
 (0)