Skip to content

Commit

Permalink
Add WCv2 IRN tag
Browse files Browse the repository at this point in the history
  • Loading branch information
bitlogik committed Feb 9, 2023
1 parent 6973cdc commit ef97996
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pywalletconnect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def close(self):
"secure_channel"
].encrypt_payload(json_encode(sess_delete))
logger.debug("Delete session message.")
self.publish(self.wallet_id, msgsessdel, "Session deletion")
self.publish(self.wallet_id, msgsessdel, 1112, "Session deletion")
except Exception:
pass

Expand Down
15 changes: 8 additions & 7 deletions pywalletconnect/client_v2irn.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def get_message(self):
req = json_rpc_unpack(rcvd_data)
# Auto session ping reply
if req[1] == "wc_sessionPing":
self._reply(self.wallet_id, req[0], True)
self._reply(self.wallet_id, req[0], True, 1115)
return (req[0], "", [])
return req
return (None, "", [])
Expand All @@ -188,13 +188,13 @@ def reply(self, req_id, result):
"""Send a RPC response to the current topic to the webapp through the relay."""
self._reply(self.wallet_id, req_id, result)

def _reply(self, topic, req_id, result):
def _reply(self, topic, req_id, result, tag=0):
"""Send a RPC response to the webapp through the relay."""
logger.debug("Sending response result : %s , %s", req_id, result)
payload_bin = json_rpc_pack_response(req_id, result)
msgbp = self.topics[topic]["secure_channel"].encrypt_payload(payload_bin, None)
logger.debug("Sending result reply.")
self.publish(topic, msgbp, "Sending result")
self.publish(topic, msgbp, tag, "Sending result")

def subscribe(self, topic_id):
"""Start listening to a given topic."""
Expand All @@ -216,11 +216,11 @@ def unsubscribe(self, topic_id):
self.wait_for_response("Topic leaving")
del self.topics[topic_id]

def publish(self, topic, message, log_msg=""):
def publish(self, topic, message, tag=0, log_msg=""):
"""Send a message into a topic id channel."""
logger.debug("Sending a publish request for %s.", topic)
data = rpc_query(
"irn_publish", {"topic": topic, "message": message, "ttl": 86400}
"irn_publish", {"topic": topic, "message": message, "ttl": 300, "tag": tag}
)
self.write(data)
self.wait_for_response(log_msg)
Expand Down Expand Up @@ -285,7 +285,7 @@ def reject_session_request(self, msg_id):
respo_neg, None
)
logger.debug("Replying the session rejection.")
self.publish(self.proposal_topic, msgbn, "Session rejection")
self.publish(self.proposal_topic, msgbn, 1109, "Session rejection")

def reply_session_request(self, msg_id, chain_id, account_address):
"""Send the sessionRequest approval."""
Expand All @@ -309,6 +309,7 @@ def reply_session_request(self, msg_id, chain_id, account_address):
},
"responderPublicKey": pubkey.hex(),
},
1101,
)

# Unsubscribe the old propose pairing topic
Expand Down Expand Up @@ -359,7 +360,7 @@ def reply_session_request(self, msg_id, chain_id, account_address):
raise WCClientException("session ack timeout")

# Finally send the session approve
self.publish(self.wallet_id, msgb, "sessionSettle post")
self.publish(self.wallet_id, msgb, 1102, "sessionSettle post")

logger.debug("Waiting for sessionSettle post ack.")
cyclew = 0
Expand Down

0 comments on commit ef97996

Please sign in to comment.