46 lines
1.8 KiB
Plaintext
Executable File
46 lines
1.8 KiB
Plaintext
Executable File
#!/usr/bin/env pyston3
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import os.path
|
|
import sys
|
|
import traceback
|
|
|
|
sys.path.insert(0, os.path.abspath(
|
|
os.path.join(os.path.dirname(__file__), '..')))
|
|
import mango # nopep8
|
|
|
|
# We explicitly want argument parsing to be outside the main try-except block because some arguments
|
|
# (like --help) will cause an exit, which our except: block traps.
|
|
parser = argparse.ArgumentParser(description="Display the balances of all grop tokens in the current wallet.")
|
|
mango.Context.add_context_command_line_parameters(parser)
|
|
parser.add_argument("--id-file", type=str, default="id.json",
|
|
help="file containing the JSON-formatted wallet private key")
|
|
parser.add_argument("--log-level", default=logging.WARNING, type=lambda level: getattr(logging, level),
|
|
help="level of verbosity to log (possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL)")
|
|
args = parser.parse_args()
|
|
|
|
logging.getLogger().setLevel(args.log_level)
|
|
logging.warning(mango.WARNING_DISCLAIMER_TEXT)
|
|
|
|
try:
|
|
id_filename = args.id_file
|
|
if not os.path.isfile(id_filename):
|
|
logging.error(f"Wallet file '{id_filename}' is not present.")
|
|
sys.exit(1)
|
|
wallet = mango.Wallet.load(id_filename)
|
|
context = mango.Context.from_context_command_line_parameters(args)
|
|
|
|
logging.info(f"Context: {context}")
|
|
logging.info(f"Wallet address: {wallet.address}")
|
|
|
|
group = mango.Group.load(context)
|
|
balances = group.fetch_balances(context, wallet.address)
|
|
print("Balances:")
|
|
mango.TokenValue.report(print, balances)
|
|
except Exception as exception:
|
|
logging.critical(f"group-balances stopped because of exception: {exception} - {traceback.format_exc()}")
|
|
except:
|
|
logging.critical(f"group-balances stopped because of uncatchable error: {traceback.format_exc()}")
|