Skip to content

Commit

Permalink
more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Apr 2, 2019
1 parent 6797ab2 commit 44451c1
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions graphenecommon/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,18 @@ def verify(self, **kwargs):
:returns: True if the message is verified successfully
:raises InvalidMessageSignature if the signature is not ok
"""
assert isinstance(self.message, dict)
assert isinstance(self.message, dict), "Message must be dictionary"

payload = self.message.get("payload")
assert payload
assert payload, "Missing payload"
payload_dict = {k[0]: k[1] for k in zip(payload[::2], payload[1::2])}
signature = self.message.get("signature")

account_name = payload_dict.get("from").strip()
memo_key = payload_dict.get("key").strip()

assert account_name
assert memo_key
assert account_name, "Missing account name 'from'"
assert memo_key, "missing 'key'"

try:
self.publickey_class(memo_key, prefix=self.blockchain.prefix)
Expand Down Expand Up @@ -294,7 +294,9 @@ def verify(self, **kwargs):
)

# Ensure payload and signed match
assert json.dumps(self.message.get("payload")) == self.message.get("signed")
assert json.dumps(
self.message.get("payload"), separators=(",", ":")
) == self.message.get("signed"), "payload doesn't match signed message"

# Reformat message
enc_message = self.message.get("signed")
Expand Down Expand Up @@ -332,23 +334,37 @@ def __init__(self, message, *args, **kwargs):
return
except self.valid_exceptions as e:
raise e
except Exception:
pass
except Exception as e:
log.warning(
"{}: Couldn't init: {}: {}".format(
_format.__name__, e.__class__.__name__, str(e)
)
)

def verify(self, **kwargs):
for _format in self.supported_formats:
try:
return _format.verify(self, **kwargs)
except self.valid_exceptions as e:
raise e
except Exception:
pass
except Exception as e:
log.warning(
"{}: Couldn't verify: {}: {}".format(
_format.__name__, e.__class__.__name__, str(e)
)
)
raise ValueError("No Decoder accepted the message")

def sign(self, account=None, **kwargs):
for _format in self.supported_formats:
try:
return _format.sign(self, account=None, **kwargs)
except self.valid_exceptions as e:
raise e
except Exception:
pass
except Exception as e:
log.warning(
"{}: Couldn't sign: {}: {}".format(
_format.__name__, e.__class__.__name__, str(e)
)
)
raise ValueError("No Decoder accepted the message")

0 comments on commit 44451c1

Please sign in to comment.