Skip to content

Commit

Permalink
Reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
algolog committed Jul 18, 2023
1 parent 59377fd commit 770decc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def watch_messages():
result = process_sendtransaction(id_request, parameters[0])
wallet_dapp.reply(call_id, result)
else:
wallet_dapp.reply_error(call_id, "User rejected methods.", 5002)
wallet_dapp.reply_error(call_id, "User rejected request.", 4001)
elif "eth_sign" == method:
approve_ask = input("Approve (y/N)?: ").lower()
if approve_ask == 'y':
Expand Down Expand Up @@ -200,17 +200,17 @@ Send a RPC response to the webapp (through the relay).
*req_id* is the JSON-RPC id of the corresponding query request, where the result belongs to. One must kept track this id from the get_message, up to this reply. So a reply result is given back with its associated call query id.
*result_str* is the result field to provide in the RPC result response.

`.reject( req_id, error_code=5002 )`
Inform the webapp that this request was rejected by the user.
*req_id* is the JSON-RPC id of the corresponding query request.
*error_code* is a rejection code to send to webapp (default 5002).

`.reply_error( req_id, message, error_code )`
Send a RPC error to the webapp (through the relay).
*req_id* is the JSON-RPC id of the corresponding query request.
*message* is a string providing a short description of the error.
*error_code* is a number that indicates the error type that occurred. See [the WalletConnect standard Error Codes](https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes).

`.reject( req_id, error_code=5000 )`
Inform the webapp that this request was rejected by the user.
*req_id* is the JSON-RPC id of the corresponding query request.
*error_code* is a rejection code to send to webapp (default 5000).

`.open_session()`
Start a WalletConnect session : wait for the session call request message.
Must be called right after a WCClient creation.
Expand Down
8 changes: 4 additions & 4 deletions pywalletconnect/client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def reply(self, req_id, result):
"""Send a RPC response to the webapp through the relay."""
self._reply(req_id, result, success=True)

def reject(self, req_id, error_code=5002):
"""Inform the webapp that this request was rejected by the user."""
self.reply_error(req_id, "User rejected.", error_code)

def reply_error(self, req_id, message, error_code):
"""Send a RPC error to the webapp through the relay."""
result = {'code': error_code, 'message': message}
Expand All @@ -134,10 +138,6 @@ def _reply(self, req_id, result, success=True):
)
self.write(datafull)

def reject(self, req_id, error_code=5000):
"""Inform the webapp that this request was rejected by the user."""
self.reply_error(req_id, "User rejected.", error_code)

def subscribe(self, topic_id):
"""Start listening to a given peer."""
logger.debug("Sending a subscription request for %s.", topic_id)
Expand Down
8 changes: 4 additions & 4 deletions pywalletconnect/client_v2irn.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ 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, success=True)

def reject(self, req_id, error_code=5002):
"""Inform the webapp that this request was rejected by the user."""
self.reply_error(req_id, "User rejected.", error_code)

def reply_error(self, req_id, message, error_code):
"""Send a RPC error to the current topic to the webapp through the relay."""
result = {'code': error_code, 'message': message}
Expand All @@ -201,10 +205,6 @@ def _reply(self, topic, req_id, result, tag=0, success=True):
logger.debug("Sending result reply.")
self.publish(topic, msgbp, tag, "Sending result")

def reject(self, req_id, error_code=5000):
"""Inform the webapp that this request was rejected by the user."""
self.reply_error(req_id, "User rejected.", error_code)

def subscribe(self, topic_id):
"""Start listening to a given topic."""
logger.debug("Sending a subscription request for %s.", topic_id)
Expand Down

0 comments on commit 770decc

Please sign in to comment.