Skip to content

Impl Writeable and Readable for Address#3206

Closed
jbesraa wants to merge 1 commit intolightningdevkit:mainfrom
jbesraa:2024-07-25-ser-address
Closed

Impl Writeable and Readable for Address#3206
jbesraa wants to merge 1 commit intolightningdevkit:mainfrom
jbesraa:2024-07-25-ser-address

Conversation

@jbesraa
Copy link
Copy Markdown
Contributor

@jbesraa jbesraa commented Jul 25, 2024

resolves #3205

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 51.72414% with 14 lines in your changes missing coverage. Please review.

Project coverage is 89.76%. Comparing base (a76ec06) to head (be27855).

Files Patch % Lines
lightning/src/util/ser.rs 51.72% 10 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3206      +/-   ##
==========================================
- Coverage   89.80%   89.76%   -0.05%     
==========================================
  Files         122      122              
  Lines      101621   101650      +29     
  Branches   101621   101650      +29     
==========================================
- Hits        91257    91242      -15     
- Misses       7677     7706      +29     
- Partials     2687     2702      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMatt
Copy link
Copy Markdown
Collaborator

Hmmm, I'm not really a fan of implementing the LDK serialization traits for rust-bitcoin types where rust-lightning doesn't have a use for them. How hard is it to have this logic in ldk-node?

@tnull
Copy link
Copy Markdown
Contributor

tnull commented Jul 29, 2024

Hmmm, I'm not really a fan of implementing the LDK serialization traits for rust-bitcoin types where rust-lightning doesn't have a use for them. How hard is it to have this logic in ldk-node?

Well, we can't as we can't implement foreign traits on foreign objects?

I guess we could create another (or even wrapper type) for it, but Address seems like the type to use for a receiver?

fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let v: WithoutLength<String> = Readable::read(r)?;
match Address::from_str(&v.0) {
Ok(addr) => Ok(WithoutLength(addr.assume_checked())),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, not sure if we should assume_checked here? Kinda defeats the purpose of the network-checking API, but of course on the flip side there's really not much we could practically do to actually check the network...

}
}

impl Writeable for Address {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a need to do both the WithoutLength version and the with?

Comment on lines +972 to +973
(addr_str.len() as u16).write(w)?;
w.write_all(self.to_string().as_bytes())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just write a String directly?

let len = <u16 as Readable>::read(r)? as usize;
let mut buf = vec![0; len];
r.read_exact(&mut buf)?;
match Address::from_str(&String::from_utf8(buf).map_err(|_| DecodeError::InvalidValue)?) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

str, not String.

@tnull
Copy link
Copy Markdown
Contributor

tnull commented Aug 6, 2024

As mentioned over at the LDK Node PR, it was discussed that we'll likely use the receiver's PublicKey instead of an Address. Closing this for now.

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.

Implement Writeable and Readable for bitcoin::Address

3 participants