mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix(eth-wire): encode p2p message id as valid rlp (#324)
This commit is contained in:
committed by
Georgios Konstantopoulos
parent
4f370e9ada
commit
2b6ef0afcf
@ -549,7 +549,7 @@ impl P2PMessage {
|
||||
/// compressed in the `p2p` subprotocol.
|
||||
impl Encodable for P2PMessage {
|
||||
fn encode(&self, out: &mut dyn bytes::BufMut) {
|
||||
out.put_u8(self.message_id() as u8);
|
||||
(self.message_id() as u8).encode(out);
|
||||
match self {
|
||||
P2PMessage::Hello(msg) => msg.encode(out),
|
||||
P2PMessage::Disconnect(msg) => msg.encode(out),
|
||||
@ -926,6 +926,7 @@ mod tests {
|
||||
let mut hello_encoded = Vec::new();
|
||||
hello.encode(&mut hello_encoded);
|
||||
|
||||
assert_eq!(hello_encoded[0], P2PMessageID::Hello as u8);
|
||||
// zero is encoded as 0x80, the empty string code in RLP
|
||||
assert_eq!(hello_encoded[0], EMPTY_STRING_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ impl FromStr for Bytes {
|
||||
hex::decode(value)
|
||||
}
|
||||
.map(Into::into)
|
||||
.map_err(|e| ParseBytesError(format!("Invalid hex: {}", e)))
|
||||
.map_err(|e| ParseBytesError(format!("Invalid hex: {e}")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user