From 35c806395a71967d2c7d9272d0b66f430d84ef83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sa=C5=82aban?= Date: Mon, 29 Nov 2021 22:37:46 +0100 Subject: [PATCH] Reformat auxiliary files --- docs/source/conf.py | 73 ++++++++++++++------------ setup.py | 67 ++++++++++++------------ utils/daemoninfo.py | 65 +++++++++++++++++------- utils/pushtx.py | 62 ++++++++++++++++------- utils/transfer.py | 87 ++++++++++++++++++++++--------- utils/walletdump.py | 121 +++++++++++++++++++++++++++++--------------- 6 files changed, 306 insertions(+), 169 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 8c9a292..3b86750 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,7 +19,8 @@ # import os import sys -sys.path.insert(0, os.path.abspath('../..')) + +sys.path.insert(0, os.path.abspath("../..")) # -- General configuration ------------------------------------------------ @@ -31,33 +32,33 @@ sys.path.insert(0, os.path.abspath('../..')) # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.autodoc'] +extensions = ["sphinx.ext.autodoc"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'Monero Python module' -copyright = '2018, Michal Salaban' -author = 'Michal Salaban' +project = "Monero Python module" +copyright = "2018, Michal Salaban" +author = "Michal Salaban" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '0.9' +version = "0.9" # The full version, including alpha/beta/rc tags. -release = '0.9' +release = "0.9" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -72,7 +73,7 @@ language = None exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -83,7 +84,7 @@ todo_include_todos = False # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -94,7 +95,7 @@ html_theme = 'alabaster' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Custom sidebar templates, must be a dictionary that maps document names # to template names. @@ -102,21 +103,18 @@ html_static_path = ['_static'] # This is required for the alabaster theme # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars html_sidebars = { - 'index': [ - 'relations.html', # needs 'show_related': True theme option to display - 'searchbox.html' + "index": [ + "relations.html", # needs 'show_related': True theme option to display + "searchbox.html", ], - '**': [ - 'searchbox.html', - 'globaltoc.html' - ] + "**": ["searchbox.html", "globaltoc.html"], } # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. -htmlhelp_basename = 'MoneroPythonmoduledoc' +htmlhelp_basename = "MoneroPythonmoduledoc" # -- Options for LaTeX output --------------------------------------------- @@ -125,15 +123,12 @@ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -143,8 +138,13 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'MoneroPythonmodule.tex', 'Monero Python module Documentation', - 'Michal Salaban', 'manual'), + ( + master_doc, + "MoneroPythonmodule.tex", + "Monero Python module Documentation", + "Michal Salaban", + "manual", + ), ] @@ -153,8 +153,13 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'moneropythonmodule', 'Monero Python module Documentation', - [author], 1) + ( + master_doc, + "moneropythonmodule", + "Monero Python module Documentation", + [author], + 1, + ) ] @@ -164,7 +169,13 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'MoneroPythonmodule', 'Monero Python module Documentation', - author, 'MoneroPythonmodule', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "MoneroPythonmodule", + "Monero Python module Documentation", + author, + "MoneroPythonmodule", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/setup.py b/setup.py index 510398b..c8caa80 100644 --- a/setup.py +++ b/setup.py @@ -16,47 +16,48 @@ def find_version(*parts): Figure out version number without importing the package. https://packaging.python.org/guides/single-sourcing-package-version/ """ - with codecs.open(os.path.join(here, *parts), 'r', errors='ignore') as fp: + with codecs.open(os.path.join(here, *parts), "r", errors="ignore") as fp: version_file = fp.read() - version_match = re.search(r"^__version__ = ['\"](.*)['\"]", - version_file, re.M) + version_match = re.search(r"^__version__ = ['\"](.*)['\"]", version_file, re.M) if version_match: return version_match.group(1) raise RuntimeError("Unable to find version string.") -version = find_version('monero', '__init__.py') +version = find_version("monero", "__init__.py") setup( - name = 'monero', - version = version, - description = 'A comprehensive Python module for handling Monero cryptocurrency', - url = 'https://github.com/monero-ecosystem/monero-python/', - long_description = open('README.rst', 'rb').read().decode('utf-8'), - install_requires = open('requirements.txt', 'r').read().splitlines(), + name="monero", + version=version, + description="A comprehensive Python module for handling Monero cryptocurrency", + url="https://github.com/monero-ecosystem/monero-python/", + long_description=open("README.rst", "rb").read().decode("utf-8"), + install_requires=open("requirements.txt", "r").read().splitlines(), tests_require=open( - 'test_requirements_py{:d}.txt'.format(sys.version_info.major), - 'r').read().splitlines(), - packages = find_packages('.', exclude=['tests']), - include_package_data = True, - author = 'Michał Sałaban', - author_email = 'michal@salaban.info', - license = 'BSD-3-Clause', - classifiers = [ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Topic :: Software Development :: Libraries :: Python Modules', + "test_requirements_py{:d}.txt".format(sys.version_info.major), "r" + ) + .read() + .splitlines(), + packages=find_packages(".", exclude=["tests"]), + include_package_data=True, + author="Michał Sałaban", + author_email="michal@salaban.info", + license="BSD-3-Clause", + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Topic :: Software Development :: Libraries :: Python Modules", ], - keywords = 'monero cryptocurrency', - test_suite='tests', + keywords="monero cryptocurrency", + test_suite="tests", ) diff --git a/utils/daemoninfo.py b/utils/daemoninfo.py index e26171e..9a71b39 100755 --- a/utils/daemoninfo.py +++ b/utils/daemoninfo.py @@ -7,20 +7,34 @@ import re from monero.backends.jsonrpc import JSONRPCDaemon from monero.daemon import Daemon + def url_data(url): - gs = re.compile( - r'^(?P[^:\s]+)(?::(?P[0-9]+))?$' - ).match(url).groupdict() + gs = re.compile(r"^(?P[^:\s]+)(?::(?P[0-9]+))?$").match(url).groupdict() return dict(filter(operator.itemgetter(1), gs.items())) + def get_daemon(): argsparser = argparse.ArgumentParser(description="Display daemon info") - argsparser.add_argument('daemon_rpc_url', nargs='?', type=url_data, default='127.0.0.1:18081', - help="Daemon RPC URL [host[:port]]") - argsparser.add_argument('-p', dest='proxy_url', nargs='?', type=str, default=None, help="Proxy URL") - argsparser.add_argument('-t', dest='timeout', type=int, default=30, help="Request timeout") - argsparser.add_argument('-v', dest='verbosity', action='count', default=0, - help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG") + argsparser.add_argument( + "daemon_rpc_url", + nargs="?", + type=url_data, + default="127.0.0.1:18081", + help="Daemon RPC URL [host[:port]]", + ) + argsparser.add_argument( + "-p", dest="proxy_url", nargs="?", type=str, default=None, help="Proxy URL" + ) + argsparser.add_argument( + "-t", dest="timeout", type=int, default=30, help="Request timeout" + ) + argsparser.add_argument( + "-v", + dest="verbosity", + action="count", + default=0, + help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG", + ) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: @@ -28,23 +42,36 @@ def get_daemon(): elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") - return Daemon(JSONRPCDaemon(timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url)) + return Daemon( + JSONRPCDaemon( + timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url + ) + ) + d = get_daemon() info = d.info() -print("Net: {net:>20s}net\n" +print( + "Net: {net:>20s}net\n" "Height: {height:15d}\n" "Difficulty: {difficulty:15d}\n" "Alt blocks: {alt_blocks_count:15d}\n".format( - net='test' if info['testnet'] \ - else 'stage' if info['stagenet'] \ - else 'main' if info['mainnet'] else 'unknown', - **info)) + net="test" + if info["testnet"] + else "stage" + if info["stagenet"] + else "main" + if info["mainnet"] + else "unknown", + **info + ) +) print("Last 6 blocks:") -for hdr in reversed(d.headers(info['height']-6, info['height']-1)): - print("{height:10d} {hash} {block_size_kb:6.2f} kB {num_txes:3d} txn(s) " - "v{major_version:d}".format( - block_size_kb=hdr['block_size']/1024.0, **hdr)) +for hdr in reversed(d.headers(info["height"] - 6, info["height"] - 1)): + print( + "{height:10d} {hash} {block_size_kb:6.2f} kB {num_txes:3d} txn(s) " + "v{major_version:d}".format(block_size_kb=hdr["block_size"] / 1024.0, **hdr) + ) mempool = d.mempool() if mempool: print("\n{:d} txn(s) in mempool:".format(len(mempool))) diff --git a/utils/pushtx.py b/utils/pushtx.py index 5374d50..fd3f529 100755 --- a/utils/pushtx.py +++ b/utils/pushtx.py @@ -11,24 +11,46 @@ from monero.daemon import Daemon from monero.transaction import Transaction from monero import exceptions + def url_data(url): - gs = re.compile( - r'^(?P[^:\s]+)(?::(?P[0-9]+))?$' - ).match(url).groupdict() + gs = re.compile(r"^(?P[^:\s]+)(?::(?P[0-9]+))?$").match(url).groupdict() return dict(filter(operator.itemgetter(1), gs.items())) + argsparser = argparse.ArgumentParser(description="Push transaction to network") -argsparser.add_argument('daemon_rpc_url', nargs='?', type=url_data, default='127.0.0.1:18081', - help="Daemon RPC URL [host[:port]]") -argsparser.add_argument('-v', dest='verbosity', action='count', default=0, - help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG") -argsparser.add_argument('-p', dest='proxy_url', nargs='?', type=str, default=None, - help="Proxy URL") -argsparser.add_argument('-t', dest='timeout', type=int, default=30, help="Request timeout") -argsparser.add_argument('-i', dest='tx_filenames', nargs='+', default=None, - help="Files with transaction data. Will read from stdin if not given.") -argsparser.add_argument('--no-relay', dest='relay', action='store_false', - help="Do not relay the transaction (it will stay at the node unless mined or expired)") +argsparser.add_argument( + "daemon_rpc_url", + nargs="?", + type=url_data, + default="127.0.0.1:18081", + help="Daemon RPC URL [host[:port]]", +) +argsparser.add_argument( + "-v", + dest="verbosity", + action="count", + default=0, + help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG", +) +argsparser.add_argument( + "-p", dest="proxy_url", nargs="?", type=str, default=None, help="Proxy URL" +) +argsparser.add_argument( + "-t", dest="timeout", type=int, default=30, help="Request timeout" +) +argsparser.add_argument( + "-i", + dest="tx_filenames", + nargs="+", + default=None, + help="Files with transaction data. Will read from stdin if not given.", +) +argsparser.add_argument( + "--no-relay", + dest="relay", + action="store_false", + help="Do not relay the transaction (it will stay at the node unless mined or expired)", +) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: @@ -37,20 +59,22 @@ elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") if args.tx_filenames: - blobs = [(f, open(f, 'rb').read()) for f in args.tx_filenames] + blobs = [(f, open(f, "rb").read()) for f in args.tx_filenames] else: - blobs = [('transaction', sys.stdin.buffer.read() if six.PY3 else sys.stdin.read())] -d = Daemon(JSONRPCDaemon(timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url)) + blobs = [("transaction", sys.stdin.buffer.read() if six.PY3 else sys.stdin.read())] +d = Daemon( + JSONRPCDaemon(timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url) +) for name, blob in blobs: logging.debug("Sending {}".format(name)) tx = Transaction(blob=blob) try: res = d.send_transaction(tx, relay=args.relay) except exceptions.TransactionBroadcastError as e: - print("{} not sent, reason: {}".format(name, e.details['reason'])) + print("{} not sent, reason: {}".format(name, e.details["reason"])) logging.debug(e.details) continue - if res['not_relayed']: + if res["not_relayed"]: print("{} not relayed".format(name)) else: print("{} successfully sent".format(name)) diff --git a/utils/transfer.py b/utils/transfer.py index 78214b3..66e352f 100755 --- a/utils/transfer.py +++ b/utils/transfer.py @@ -11,31 +11,66 @@ from monero.numbers import as_monero from monero.wallet import Wallet from monero.backends.jsonrpc import JSONRPCWallet + def url_data(url): - gs = re.compile( - r'^(?:(?P[a-z0-9_-]+)?(?::(?P[^@]+))?@)?(?P[^:\s]+)(?::(?P[0-9]+))?$' - ).match(url).groupdict() + gs = ( + re.compile( + r"^(?:(?P[a-z0-9_-]+)?(?::(?P[^@]+))?@)?(?P[^:\s]+)(?::(?P[0-9]+))?$" + ) + .match(url) + .groupdict() + ) return dict(filter(operator.itemgetter(1), gs.items())) + def destpair(s): - addr, amount = s.split(':') + addr, amount = s.split(":") return (address(addr), as_monero(amount)) + argsparser = argparse.ArgumentParser(description="Transfer Monero") -argsparser.add_argument('-v', dest='verbosity', action='count', default=0, - help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG") -argsparser.add_argument('wallet_rpc_url', nargs='?', type=url_data, default='127.0.0.1:18082', - help="Wallet RPC URL [user[:password]@]host[:port]") -argsparser.add_argument('-t', dest='timeout', type=int, default=30, help="Request timeout") -argsparser.add_argument('-a', dest='account', default=0, type=int, help="Source account index") -argsparser.add_argument('-p', dest='prio', - choices=['unimportant', 'normal', 'elevated', 'priority'], - default='normal') -argsparser.add_argument('--save', dest='outdir', nargs='?', default=None, const='.', +argsparser.add_argument( + "-v", + dest="verbosity", + action="count", + default=0, + help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG", +) +argsparser.add_argument( + "wallet_rpc_url", + nargs="?", + type=url_data, + default="127.0.0.1:18082", + help="Wallet RPC URL [user[:password]@]host[:port]", +) +argsparser.add_argument( + "-t", dest="timeout", type=int, default=30, help="Request timeout" +) +argsparser.add_argument( + "-a", dest="account", default=0, type=int, help="Source account index" +) +argsparser.add_argument( + "-p", + dest="prio", + choices=["unimportant", "normal", "elevated", "priority"], + default="normal", +) +argsparser.add_argument( + "--save", + dest="outdir", + nargs="?", + default=None, + const=".", help="Save to file, optionally follow by destination directory (default is .)\n" - "Transaction will be not relayed to the network.") -argsparser.add_argument('destinations', metavar='address:amount', nargs='+', type=destpair, - help="Destination address and amount (one or more pairs)") + "Transaction will be not relayed to the network.", +) +argsparser.add_argument( + "destinations", + metavar="address:amount", + nargs="+", + type=destpair, + help="Destination address and amount (one or more pairs)", +) args = argsparser.parse_args() prio = getattr(monero.const, "PRIO_{:s}".format(args.prio.upper())) @@ -48,16 +83,18 @@ logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") w = Wallet(JSONRPCWallet(timeout=args.timeout, **args.wallet_rpc_url)) txns = w.accounts[args.account].transfer_multiple( - args.destinations, priority=prio, - relay=args.outdir is None) + args.destinations, priority=prio, relay=args.outdir is None +) for tx in txns: - print(u"Transaction {hash}:\nfee: {fee:21.12f}\n" - u"Tx key: {key}\nSize: {size} B".format( - hash=tx.hash, fee=tx.fee, - key=tx.key, size=len(tx.blob) >> 1)) + print( + u"Transaction {hash}:\nfee: {fee:21.12f}\n" + u"Tx key: {key}\nSize: {size} B".format( + hash=tx.hash, fee=tx.fee, key=tx.key, size=len(tx.blob) >> 1 + ) + ) if args.outdir: - outname = os.path.join(args.outdir, tx.hash + '.tx') - outfile = open(outname, 'wb') + outname = os.path.join(args.outdir, tx.hash + ".tx") + outfile = open(outname, "wb") outfile.write(tx.blob) outfile.close() print(u"Transaction saved to {}".format(outname)) diff --git a/utils/walletdump.py b/utils/walletdump.py index 9603367..120e7e7 100755 --- a/utils/walletdump.py +++ b/utils/walletdump.py @@ -8,19 +8,37 @@ from monero import exceptions from monero.backends.jsonrpc import JSONRPCWallet, RPCError from monero.wallet import Wallet + def url_data(url): - gs = re.compile( - r'^(?:(?P[a-z0-9_-]+)?(?::(?P[^@]+))?@)?(?P[^:\s]+)(?::(?P[0-9]+))?$' - ).match(url).groupdict() + gs = ( + re.compile( + r"^(?:(?P[a-z0-9_-]+)?(?::(?P[^@]+))?@)?(?P[^:\s]+)(?::(?P[0-9]+))?$" + ) + .match(url) + .groupdict() + ) return dict(filter(operator.itemgetter(1), gs.items())) + def get_wallet(): argsparser = argparse.ArgumentParser(description="Display wallet contents") - argsparser.add_argument('wallet_rpc_url', nargs='?', type=url_data, default='127.0.0.1:18082', - help="Wallet RPC URL [user[:password]@]host[:port]") - argsparser.add_argument('-v', dest='verbosity', action='count', default=0, - help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG") - argsparser.add_argument('-t', dest='timeout', type=int, default=30, help="Request timeout") + argsparser.add_argument( + "wallet_rpc_url", + nargs="?", + type=url_data, + default="127.0.0.1:18082", + help="Wallet RPC URL [user[:password]@]host[:port]", + ) + argsparser.add_argument( + "-v", + dest="verbosity", + action="count", + default=0, + help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG", + ) + argsparser.add_argument( + "-t", dest="timeout", type=int, default=30, help="Request timeout" + ) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: @@ -30,76 +48,95 @@ def get_wallet(): logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") return Wallet(JSONRPCWallet(timeout=args.timeout, **args.wallet_rpc_url)) -_TXHDR = "timestamp height id/hash " \ - " amount fee {dir:95s} payment_id" + +_TXHDR = ( + "timestamp height id/hash " + " amount fee {dir:95s} payment_id" +) + def pmt2str(pmt): - res = ["{time} {height:7d} {hash} {amount:17.12f} {fee:13.12f} {addr} {payment_id}".format( - time=pmt.timestamp.strftime("%d-%m-%y %H:%M:%S") if getattr(pmt, 'timestamp', None) else None, - height=pmt.transaction.height or 0, - hash=pmt.transaction.hash, - amount=pmt.amount, - fee=pmt.transaction.fee or 0, - payment_id=pmt.payment_id, - addr=getattr(pmt, 'local_address', None) or '')] + res = [ + "{time} {height:7d} {hash} {amount:17.12f} {fee:13.12f} {addr} {payment_id}".format( + time=pmt.timestamp.strftime("%d-%m-%y %H:%M:%S") + if getattr(pmt, "timestamp", None) + else None, + height=pmt.transaction.height or 0, + hash=pmt.transaction.hash, + amount=pmt.amount, + fee=pmt.transaction.fee or 0, + payment_id=pmt.payment_id, + addr=getattr(pmt, "local_address", None) or "", + ) + ] try: for dest in pmt.destinations: - res.append(" {amount:17.12f} to {address}".format(address=dest[0], amount=dest[1])) + res.append( + " {amount:17.12f} to {address}".format( + address=dest[0], amount=dest[1] + ) + ) except AttributeError: pass return "\n".join(res) + def a2str(a): - return "{addr} {label}".format( - addr=a, - label=a.label or "") + return "{addr} {label}".format(addr=a, label=a.label or "") + w = get_wallet() masteraddr = w.address() print( - "Master address: {addr}\n" \ + "Master address: {addr}\n" "Balance: {total:16.12f} ({unlocked:16.12f} unlocked)".format( - addr=a2str(masteraddr), - total=w.balance(), - unlocked=w.balance(unlocked=True))) + addr=a2str(masteraddr), total=w.balance(), unlocked=w.balance(unlocked=True) + ) +) try: seed = w.seed() -except (exceptions.WalletIsNotDeterministic, RPCError): # FIXME: Remove RPCError once PR#4563 is merged in monero - seed = '[--- wallet is not deterministic and has no seed ---]' +except ( + exceptions.WalletIsNotDeterministic, + RPCError, +): # FIXME: Remove RPCError once PR#4563 is merged in monero + seed = "[--- wallet is not deterministic and has no seed ---]" print( - "Keys:\n" \ - " private spend: {ssk}\n" \ - " private view: {svk}\n" \ - " public spend: {psk}\n" \ - " public view: {pvk}\n\n" \ + "Keys:\n" + " private spend: {ssk}\n" + " private view: {svk}\n" + " public spend: {psk}\n" + " public view: {pvk}\n\n" "Seed:\n{seed}".format( ssk=w.spend_key(), svk=w.view_key(), psk=masteraddr.spend_key(), pvk=masteraddr.view_key(), - seed=seed - )) + seed=seed, + ) +) if len(w.accounts) > 1: print("\nWallet has {num} account(s):".format(num=len(w.accounts))) for acc in w.accounts: print("\nAccount {idx:02d}:".format(idx=acc.index)) - print("Balance: {total:16.12f} ({unlocked:16.12f} unlocked)".format( - total=acc.balance(), - unlocked=acc.balance(unlocked=True))) + print( + "Balance: {total:16.12f} ({unlocked:16.12f} unlocked)".format( + total=acc.balance(), unlocked=acc.balance(unlocked=True) + ) + ) addresses = acc.addresses() print("{num:2d} address(es):".format(num=len(addresses))) print("\n".join(map(a2str, addresses))) ins = acc.incoming(unconfirmed=True) if ins: print("\nIncoming transactions:") - print(_TXHDR.format(dir='received by')) + print(_TXHDR.format(dir="received by")) for tx in ins: print(pmt2str(tx)) outs = acc.outgoing(unconfirmed=True) if outs: print("\nOutgoing transactions:") - print(_TXHDR.format(dir='sent from')) + print(_TXHDR.format(dir="sent from")) for tx in outs: print(pmt2str(tx)) else: @@ -109,12 +146,12 @@ else: ins = w.incoming(unconfirmed=True) if ins: print("\nIncoming transactions:") - print(_TXHDR.format(dir='received by')) + print(_TXHDR.format(dir="received by")) for tx in ins: print(pmt2str(tx)) outs = w.outgoing(unconfirmed=True) if outs: print("\nOutgoing transactions:") - print(_TXHDR.format(dir='sent from')) + print(_TXHDR.format(dir="sent from")) for tx in outs: print(pmt2str(tx))