From 94bcff28b19715061c38af418afd8f0b979792a8 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Tue, 27 May 2025 13:55:21 +0100 Subject: [PATCH] p2p: Add wrappers for messages that use `Vec` In preparation to move `p2p` to its own crate, any `Vec` that satisfies `T: Encodable` will not trivially implement `Encodable` because of the orphan rule. A type defined within p2p may implement `Encodable`, however, and the simplest possible type is one that simply wraps the vector. Three types that will implement `Encodable` within `p2p` are added here. --- bitcoin/src/p2p/message.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bitcoin/src/p2p/message.rs b/bitcoin/src/p2p/message.rs index bb69ec86d..b464623ef 100644 --- a/bitcoin/src/p2p/message.rs +++ b/bitcoin/src/p2p/message.rs @@ -163,6 +163,18 @@ pub struct V2NetworkMessage { payload: NetworkMessage, } +/// A list of inventory items. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct InventoryPayload(pub Vec); + +/// A list of legacy p2p address messages. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct AddrPayload(pub Vec<(u32, Address)>); + +/// A list of v2 address messages. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct AddrV2Payload(pub Vec); + /// A Network message payload. Proper documentation is available on at /// [Bitcoin Wiki: Protocol Specification](https://en.bitcoin.it/wiki/Protocol_specification) #[derive(Clone, PartialEq, Eq, Debug)]