From b8c3b282eee5d6387a9cf2f64af0253e764c1172 Mon Sep 17 00:00:00 2001 From: Alexander Shishenko Date: Mon, 5 Sep 2022 07:31:13 +0300 Subject: [PATCH] protocols/gossipsub: Allow publishing to anything that implements `Into` (#2862) --- protocols/gossipsub/CHANGELOG.md | 4 ++++ protocols/gossipsub/src/behaviour.rs | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 48993c987fb..7fa96a4748f 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -2,6 +2,10 @@ - Update to `libp2p-swarm` `v0.39.0`. +- Allow publishing with any `impl Into` as a topic. See [PR 2862]. + +[PR 2862]: https://github.com/libp2p/rust-libp2p/pull/2862 + # 0.40.0 - Update prost requirement from 0.10 to 0.11 which no longer installs the protoc Protobuf compiler. diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 900e1b43be4..954c68ae24b 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -587,19 +587,20 @@ where } /// Publishes a message with multiple topics to the network. - pub fn publish( + pub fn publish( &mut self, - topic: Topic, + topic: impl Into, data: impl Into>, ) -> Result { let data = data.into(); + let topic = topic.into(); // Transform the data before building a raw_message. let transformed_data = self .data_transform - .outbound_transform(&topic.hash(), data.clone())?; + .outbound_transform(&topic, data.clone())?; - let raw_message = self.build_raw_message(topic.into(), transformed_data)?; + let raw_message = self.build_raw_message(topic, transformed_data)?; // calculate the message id from the un-transformed data let msg_id = self.config.message_id(&GossipsubMessage {