Merge rust-bitcoin/rust-bitcoin#1120: Use `u16::to_be_bytes`

3c2869465b Use to_be_bytes (Tobin C. Harding)

Pull request description:

  Now that MSRV is > 1.32 we can use `u16::to_be_bytes` to ensure network byte order when encoding the port number of a `AddrV2Message`.

  Remove the TODO and use `to_be_bytes` as suggested.

ACKs for top commit:
  Kixunil:
    ACK 3c2869465b
  apoelstra:
    ACK 3c2869465b

Tree-SHA512: b5dd9b0f43257f84defb9e9ecf9d02469f1959669367c5ad02cfb43003b780cf07ea344579b52a75c424fd85f8fa02dee3713b967c9b3a33eec6b7aa914763cd
This commit is contained in:
Andrew Poelstra 2022-07-25 15:25:49 +00:00
commit cf8c5819c2
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 3 deletions

View File

@ -259,9 +259,9 @@ impl Encodable for AddrV2Message {
len += VarInt(self.services.to_u64()).consensus_encode(w)?; len += VarInt(self.services.to_u64()).consensus_encode(w)?;
len += self.addr.consensus_encode(w)?; len += self.addr.consensus_encode(w)?;
// consensus_encode always encodes in LE, and we want to encode in BE. w.write_all(&self.port.to_be_bytes())?;
//TODO `len += io::Write::write(w, &self.port.to_be_bytes())?;` when MSRV >= 1.32 len += 2; // port u16 is two bytes.
len += self.port.swap_bytes().consensus_encode(w)?;
Ok(len) Ok(len)
} }
} }