wownero-python/utils/walletdump.py

91 lines
3.2 KiB
Python
Raw Normal View History

2017-12-26 19:25:49 +00:00
import argparse
from decimal import Decimal
import logging
import pprint
import random
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
2017-12-26 21:02:17 +00:00
from monero.backends.jsonrpc import JSONRPCWallet
2017-12-26 19:25:49 +00:00
from monero import exceptions
from monero import Address, Wallet, as_monero
def get_wallet():
argsparser = argparse.ArgumentParser(description="Display wallet contents")
argsparser.add_argument('--host', dest='host', default='127.0.0.1', help="Wallet RPC host")
argsparser.add_argument('--port', dest='port', default='18082', help="Wallet RPC port")
argsparser.add_argument('-u', dest='user', default='', help="Wallet RPC user")
argsparser.add_argument('-p', dest='password', default='', help="Wallet RPC password")
2017-12-26 21:14:05 +00:00
argsparser.add_argument('-v', dest='verbosity', action='count', default=0,
help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG")
2017-12-26 19:25:49 +00:00
args = argsparser.parse_args()
2017-12-26 21:14:05 +00:00
level = logging.WARNING
if args.verbosity == 1:
level = logging.INFO
elif args.verbosity > 1:
level = logging.DEBUG
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
2017-12-26 21:02:17 +00:00
return Wallet(JSONRPCWallet(
2017-12-26 19:25:49 +00:00
host=args.host, port=args.port,
user=args.user,
password=args.password))
_TXHDR = "timestamp height id/hash " \
" amount fee payment_id"
def tx2str(tx):
2017-12-27 00:49:59 +00:00
return "{time} {height} {hash} {amount:17.12f} {fee:13.12f} {payment_id} {addr}".format(
time=tx.timestamp.strftime("%d-%m-%y %H:%M:%S") if getattr(tx, 'timestamp', None) else None,
height=tx.height,
hash=tx.hash,
amount=tx.amount,
fee=tx.fee or 0,
payment_id=tx.payment_id,
addr=getattr(tx, 'receiving_address', None) or '')
2017-12-26 19:25:49 +00:00
w = get_wallet()
print(
"Master address: {addr}\n" \
"Balance: {total:16.12f} ({unlocked:16.12f} unlocked)".format(
addr=w.get_address(),
total=w.get_balance(),
unlocked=w.get_balance(unlocked=True)))
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.get_balance(),
unlocked=acc.get_balance(unlocked=True)))
addresses = acc.get_addresses()
print("{num:2d} address(es):".format(num=len(addresses)))
print("\n".join(map(str, addresses)))
2017-12-27 00:49:59 +00:00
ins = acc.get_transactions_in()
2017-12-26 19:25:49 +00:00
if ins:
2017-12-27 00:49:59 +00:00
print("\nIncoming transactions:")
2017-12-26 19:25:49 +00:00
print(_TXHDR)
for tx in ins:
print(tx2str(tx))
2017-12-27 00:49:59 +00:00
outs = acc.get_transactions_out()
2017-12-26 19:25:49 +00:00
if outs:
2017-12-27 00:49:59 +00:00
print("\nOutgoing transactions:")
2017-12-26 19:25:49 +00:00
print(_TXHDR)
for tx in outs:
print(tx2str(tx))
else:
2017-12-27 00:49:59 +00:00
ins = w.get_transactions_in()
2017-12-26 19:25:49 +00:00
if ins:
2017-12-27 00:49:59 +00:00
print("\nIncoming transactions:")
2017-12-26 19:25:49 +00:00
print(_TXHDR)
for tx in ins:
print(tx2str(tx))
2017-12-27 00:49:59 +00:00
outs = w.get_transactions_out()
2017-12-26 19:25:49 +00:00
if outs:
2017-12-27 00:49:59 +00:00
print("\nOutgoing transactions:")
2017-12-26 19:25:49 +00:00
print(_TXHDR)
for tx in outs:
print(tx2str(tx))