diff options
| author | Yuval Adam <_@yuv.al> | 2022-01-17 15:26:17 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2022-01-17 15:26:17 +0200 |
| commit | f7ca1b91577ffd2bfe94ee3cda41131cd7aec7cf (patch) | |
| tree | e82d5c802d2ca15c92e8fa21cfcca83a3d4b20a6 /nostr/bip340.py | |
| parent | fcfc9410654d366640dac7b6b1c612c8eda2beba (diff) | |
Cleanup test_vectors code
Diffstat (limited to 'nostr/bip340.py')
| -rw-r--r-- | nostr/bip340.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/nostr/bip340.py b/nostr/bip340.py index 7712500..f9758d9 100644 --- a/nostr/bip340.py +++ b/nostr/bip340.py @@ -168,3 +168,37 @@ def schnorr_verify(msg: bytes, pubkey: bytes, sig: bytes) -> bool: return False debug_print_vars() return True + + +# +# The following code is only used for debugging +# +import inspect + + +def pretty(v: Any) -> Any: + if isinstance(v, bytes): + return "0x" + v.hex() + if isinstance(v, int): + return pretty(bytes_from_int(v)) + if isinstance(v, tuple): + return tuple(map(pretty, v)) + return v + + +def debug_print_vars() -> None: + if DEBUG: + current_frame = inspect.currentframe() + assert current_frame is not None + frame = current_frame.f_back + assert frame is not None + print( + " Variables in function ", + frame.f_code.co_name, + " at line ", + frame.f_lineno, + ":", + sep="", + ) + for var_name, var_val in frame.f_locals.items(): + print(" " + var_name.rjust(11, " "), "==", pretty(var_val)) |
