Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose impl_writeable_msg #1976

Merged

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Jan 20, 2023

By user request, we expose the impl_writeable_msg macro which can be useful for implementing custom message types.

@tnull tnull force-pushed the 2023-01-expose-impl-writeable-msg branch 4 times, most recently from 6a338ac to 8e41db0 Compare January 21, 2023 00:03
@tnull tnull force-pushed the 2023-01-expose-impl-writeable-msg branch from 8e41db0 to 99fe52e Compare January 21, 2023 01:04
@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2023

Codecov Report

Base: 90.71% // Head: 90.71% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (99fe52e) compared to base (153b048).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1976   +/-   ##
=======================================
  Coverage   90.71%   90.71%           
=======================================
  Files          97       97           
  Lines       50677    50676    -1     
  Branches    50677    50676    -1     
=======================================
+ Hits        45971    45972    +1     
+ Misses       4706     4704    -2     
Impacted Files Coverage Δ
lightning/src/util/ser_macros.rs 87.03% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs 89.48% <0.00%> (+0.21%) ⬆️
lightning/src/util/events.rs 30.73% <0.00%> (+0.22%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@valentinewallace
Copy link
Contributor

It seems like it would be an improvement to support serializing TLV fields as other than just $optional, but if others think this is fine for now then I'm ACK

/// [`Readable`]: crate::util::ser::Readable
/// [`Writeable`]: crate::util::ser::Writeable
/// [`CustomMessageReader`]: crate::ln::wire::CustomMessageReader
#[macro_export]
macro_rules! impl_writeable_msg {
($st:ident, {$($field:ident),* $(,)*}, {$(($type: expr, $tlvfield: ident, $fieldty: tt)),* $(,)*}) => {
impl $crate::util::ser::Writeable for $st {
fn write<W: $crate::util::ser::Writer>(&self, w: &mut W) -> Result<(), $crate::io::Error> {
$( self.$field.write(w)?; )*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a use $crate::util::ser::Writeable, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, doesn't seem so for the doctest, and also seems to work in a trivial freestanding example?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, in your example you have an explicit use lightning::util::ser::Writeable;, my point was that if there isn't one in the file in question it needs to be in the macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. a) the example builds fine without the import, it is only needed for the my_custom_msg.write call. Initial version with just the impl works just fine b) If I add the use statement to the macro it's immediately marked as unused. 🤷‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's...very surprising to me. Whatever, then.

@TheBlueMatt
Copy link
Collaborator

I agree we should make it support non-Option, but we dont have to do it here.

@TheBlueMatt TheBlueMatt merged commit 3bd395f into lightningdevkit:main Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants