Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bindings): base64 payload and key for content topic #2435

Merged
merged 8 commits into from
Feb 20, 2024

Conversation

richard-ramos
Copy link
Member

@richard-ramos richard-ramos commented Feb 14, 2024

Description

Various fixes to the bindings to issues identified while attempting to integrate nwaku with waku-rust-bindings

Changes

  • Stores the userData that's passed when waku_set_event_callback is invoked
  • Adds the messageHash to the response when an event is generated
  • Converts from/to base64 the message payloads
  • Uses the key contentTopic instead of content_topic in the message JSON

Copy link

github-actions bot commented Feb 14, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2435

Built from 3fed8ac

@richard-ramos richard-ramos marked this pull request as ready for review February 16, 2024 18:47
@richard-ramos richard-ramos force-pushed the chore/bindings branch 2 times, most recently from 3b78991 to 0c34551 Compare February 16, 2024 19:42
Copy link
Contributor

@SionoiS SionoiS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

library/events/json_message_event.nim Outdated Show resolved Hide resolved
library/events/json_message_event.nim Outdated Show resolved Hide resolved
Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for it!
Just added a couple of nitpick comments xD

proc toWakuMessage*(self: JsonMessage): WakuMessage =
let payloadRes = base64.decode(self.payload)
if payloadRes.isErr():
raise newException(ValueError, "invalid payload format: " & payloadRes.error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, if possible I'd avoid using exceptions:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced by a Result in a4f7b88

version: uint32(self.version),
timestamp: self.timestamp,
ephemeral: self.ephemeral
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first sight I missed having the rln proof but I believe this is something we will add in the future when we expose some kind of publish_rln function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up adding the proof in a4f7b88 so it's now 'future-ready' for when we include rln functionality to bindings

@@ -43,14 +45,14 @@ const RET_MISSING_CALLBACK: cint = 2
proc relayEventCallback(ctx: ptr Context): WakuRelayHandler =
return proc (pubsubTopic: PubsubTopic, msg: WakuMessage): Future[system.void]{.async.} =
# Callback that hadles the Waku Relay events. i.e. messages or errors.
if not isNil(ctx[].eventCallback):
if not isNil(ctx[].eventCallback) and not isNil(ctx[].eventUserData):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we now have two conditions that should be met, I wonder if we could split the validation in two, and apply some kind of "return early pattern". The following article explains the idea much better:
https://medium.com/swlh/return-early-pattern-3d18a41bba8

lmk what do you think :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I removed the validation from the if and executed those following the 'return early' pattern as described in the article you shared.
a4f7b88

@richard-ramos richard-ramos merged commit d01585e into master Feb 20, 2024
10 checks passed
@richard-ramos richard-ramos deleted the chore/bindings branch February 20, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants