From ba706164b174d4f4e9c0a2329224fad9e0d08546 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 2 Nov 2023 14:33:50 -0400 Subject: [PATCH] fix: pubsub topic is a string --- .github/workflows/codecov.yml | 2 +- .github/workflows/main.yml | 6 +-- examples/Cargo.lock | 4 +- waku-bindings/src/general/mod.rs | 71 +------------------------------- 4 files changed, 8 insertions(+), 75 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 665d811..0e8238f 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -20,7 +20,7 @@ jobs: run: git submodule update --init --recursive - uses: actions/setup-go@v3 # we need go to build go-waku with: - go-version: '1.19' + go-version: '1.20' - uses: actions-rs/toolchain@v1 with: profile: minimal diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1bd790d..9e48daa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: run: git submodule update --init --recursive - uses: actions/setup-go@v3 # we need go to build go-waku with: - go-version: '1.19' + go-version: '1.20' - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -61,7 +61,7 @@ jobs: run: git submodule update --init --recursive - uses: actions/setup-go@v3 # we need go to build go-waku with: - go-version: '1.19' + go-version: '1.20' - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -88,7 +88,7 @@ jobs: run: git submodule update --init --recursive - uses: actions/setup-go@v3 # we need go to build go-waku with: - go-version: '1.19' + go-version: '1.20' - uses: actions-rs/toolchain@v1 with: profile: minimal diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 8195d8a..f287384 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -1497,7 +1497,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waku-bindings" -version = "0.4.0" +version = "0.5.0" dependencies = [ "aes-gcm", "base64 0.21.0", @@ -1518,7 +1518,7 @@ dependencies = [ [[package]] name = "waku-sys" -version = "0.3.0" +version = "0.5.0" dependencies = [ "bindgen", ] diff --git a/waku-bindings/src/general/mod.rs b/waku-bindings/src/general/mod.rs index cfa1659..4214fd1 100644 --- a/waku-bindings/src/general/mod.rs +++ b/waku-bindings/src/general/mod.rs @@ -20,6 +20,8 @@ pub type WakuMessageVersion = usize; pub type PeerId = String; /// Waku message id, hex encoded sha256 digest of the message pub type MessageId = String; +/// Waku pubsub topic +pub type WakuPubSubTopic = String; /// Protocol identifiers #[non_exhaustive] @@ -515,75 +517,6 @@ impl<'de> Deserialize<'de> for WakuContentTopic { } } -/// A waku pubsub topic in the form of `/waku/v2/{topic_name}/{encoding}` -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct WakuPubSubTopic { - pub topic_name: Cow<'static, str>, - pub encoding: Encoding, -} - -impl WakuPubSubTopic { - pub const fn new(topic_name: &'static str, encoding: Encoding) -> Self { - Self { - topic_name: Cow::Borrowed(topic_name), - encoding, - } - } - - pub fn with_topic_name(topic_name: String, encoding: Encoding) -> Self { - Self { - topic_name: Cow::Owned(topic_name), - encoding, - } - } -} - -impl FromStr for WakuPubSubTopic { - type Err = String; - - fn from_str(s: &str) -> std::result::Result { - if let Ok((topic_name, encoding)) = scanf!(s, "/waku/2/{}/{:/.+?/}", String, Encoding) { - Ok(WakuPubSubTopic { - topic_name: Cow::Owned(topic_name), - encoding, - }) - } else { - Err( - format!( - "Wrong pub-sub topic format. Should be `/waku/2/{{topic-name}}/{{encoding}}`. Got: {s}" - ) - ) - } - } -} - -impl Display for WakuPubSubTopic { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "/waku/2/{}/{}", self.topic_name, self.encoding) - } -} - -impl Serialize for WakuPubSubTopic { - fn serialize(&self, serializer: S) -> std::result::Result - where - S: Serializer, - { - self.to_string().serialize(serializer) - } -} - -impl<'de> Deserialize<'de> for WakuPubSubTopic { - fn deserialize(deserializer: D) -> std::result::Result - where - D: Deserializer<'de>, - { - let as_string: String = String::deserialize(deserializer)?; - as_string - .parse::() - .map_err(D::Error::custom) - } -} - mod base64_serde { use base64::Engine; use serde::de::Error;