2018-05-22 09:20:10 +00:00
|
|
|
#!/usr/bin/python
|
2017-12-26 19:25:49 +00:00
|
|
|
import argparse
|
|
|
|
import logging
|
2018-01-06 21:19:09 +00:00
|
|
|
import operator
|
|
|
|
import re
|
2017-12-26 19:25:49 +00:00
|
|
|
|
2017-12-26 21:02:17 +00:00
|
|
|
from monero.backends.jsonrpc import JSONRPCWallet
|
2018-01-18 02:02:20 +00:00
|
|
|
from monero.wallet import Wallet
|
2017-12-26 19:25:49 +00:00
|
|
|
|
2018-01-06 21:19:09 +00:00
|
|
|
def url_data(url):
|
|
|
|
gs = re.compile(
|
|
|
|
r'^(?:(?P<user>[a-z0-9_-]+)?(?::(?P<password>[^@]+))?@)?(?P<host>[^:\s]+)(?::(?P<port>[0-9]+))?$'
|
|
|
|
).match(url).groupdict()
|
|
|
|
return dict(filter(operator.itemgetter(1), gs.items()))
|
|
|
|
|
2017-12-26 19:25:49 +00:00
|
|
|
def get_wallet():
|
|
|
|
argsparser = argparse.ArgumentParser(description="Display wallet contents")
|
2018-01-14 22:37:54 +00:00
|
|
|
argsparser.add_argument('wallet_rpc_url', nargs='?', type=url_data, default='127.0.0.1:18082',
|
|
|
|
help="Wallet RPC URL [user[:password]@]host[:port]")
|
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")
|
2018-01-14 22:37:54 +00:00
|
|
|
return Wallet(JSONRPCWallet(**args.wallet_rpc_url))
|
2017-12-26 19:25:49 +00:00
|
|
|
|
|
|
|
_TXHDR = "timestamp height id/hash " \
|
2018-01-06 22:12:42 +00:00
|
|
|
" amount fee {dir:95s} payment_id"
|
2017-12-26 19:25:49 +00:00
|
|
|
|
2018-01-25 07:50:09 +00:00
|
|
|
def pmt2str(pmt):
|
2018-01-22 02:57:50 +00:00
|
|
|
return "{time} {height:7d} {hash} {amount:17.12f} {fee:13.12f} {addr} {payment_id}".format(
|
2018-01-25 07:50:09 +00:00
|
|
|
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 '')
|
2017-12-26 19:25:49 +00:00
|
|
|
|
2018-01-11 22:17:34 +00:00
|
|
|
def a2str(a):
|
|
|
|
return "{addr} {label}".format(
|
|
|
|
addr=a,
|
|
|
|
label=a.label or "")
|
|
|
|
|
2017-12-26 19:25:49 +00:00
|
|
|
w = get_wallet()
|
2018-01-28 15:11:27 +00:00
|
|
|
masteraddr = w.address()
|
2017-12-26 19:25:49 +00:00
|
|
|
print(
|
|
|
|
"Master address: {addr}\n" \
|
|
|
|
"Balance: {total:16.12f} ({unlocked:16.12f} unlocked)".format(
|
2018-01-14 05:28:28 +00:00
|
|
|
addr=a2str(masteraddr),
|
2018-01-28 15:11:27 +00:00
|
|
|
total=w.balance(),
|
|
|
|
unlocked=w.balance(unlocked=True)))
|
2018-01-14 05:28:28 +00:00
|
|
|
print(
|
|
|
|
"Keys:\n" \
|
2018-01-28 12:04:47 +00:00
|
|
|
" private spend: {ssk}\n" \
|
2018-01-14 05:28:28 +00:00
|
|
|
" private view: {svk}\n" \
|
|
|
|
" public spend: {psk}\n" \
|
|
|
|
" public view: {pvk}\n\n" \
|
|
|
|
"Seed:\n{seed}".format(
|
2018-01-28 15:11:27 +00:00
|
|
|
ssk=w.spend_key(),
|
|
|
|
svk=w.view_key(),
|
|
|
|
psk=masteraddr.spend_key(),
|
|
|
|
pvk=masteraddr.view_key(),
|
|
|
|
seed=w.seed()
|
2018-01-14 05:28:28 +00:00
|
|
|
))
|
2017-12-26 19:25:49 +00:00
|
|
|
|
|
|
|
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(
|
2018-01-28 15:11:27 +00:00
|
|
|
total=acc.balance(),
|
|
|
|
unlocked=acc.balance(unlocked=True)))
|
|
|
|
addresses = acc.addresses()
|
2017-12-26 19:25:49 +00:00
|
|
|
print("{num:2d} address(es):".format(num=len(addresses)))
|
2018-01-11 22:17:34 +00:00
|
|
|
print("\n".join(map(a2str, addresses)))
|
2018-01-29 14:11:53 +00:00
|
|
|
ins = acc.incoming(unconfirmed=True)
|
2017-12-26 19:25:49 +00:00
|
|
|
if ins:
|
2017-12-27 00:49:59 +00:00
|
|
|
print("\nIncoming transactions:")
|
2018-01-06 15:44:38 +00:00
|
|
|
print(_TXHDR.format(dir='received by'))
|
2017-12-26 19:25:49 +00:00
|
|
|
for tx in ins:
|
2018-01-25 07:50:09 +00:00
|
|
|
print(pmt2str(tx))
|
2018-01-29 14:11:53 +00:00
|
|
|
outs = acc.outgoing(unconfirmed=True)
|
2017-12-26 19:25:49 +00:00
|
|
|
if outs:
|
2017-12-27 00:49:59 +00:00
|
|
|
print("\nOutgoing transactions:")
|
2018-01-06 15:44:38 +00:00
|
|
|
print(_TXHDR.format(dir='sent from'))
|
2017-12-26 19:25:49 +00:00
|
|
|
for tx in outs:
|
2018-01-25 07:50:09 +00:00
|
|
|
print(pmt2str(tx))
|
2017-12-26 19:25:49 +00:00
|
|
|
else:
|
2018-01-29 14:11:53 +00:00
|
|
|
ins = w.incoming(unconfirmed=True)
|
2017-12-26 19:25:49 +00:00
|
|
|
if ins:
|
2017-12-27 00:49:59 +00:00
|
|
|
print("\nIncoming transactions:")
|
2018-01-06 15:44:38 +00:00
|
|
|
print(_TXHDR.format(dir='received by'))
|
2017-12-26 19:25:49 +00:00
|
|
|
for tx in ins:
|
2018-01-25 07:50:09 +00:00
|
|
|
print(pmt2str(tx))
|
2018-01-29 14:11:53 +00:00
|
|
|
outs = w.outgoing(unconfirmed=True)
|
2017-12-26 19:25:49 +00:00
|
|
|
if outs:
|
2017-12-27 00:49:59 +00:00
|
|
|
print("\nOutgoing transactions:")
|
2018-01-06 15:44:38 +00:00
|
|
|
print(_TXHDR.format(dir='sent from'))
|
2017-12-26 19:25:49 +00:00
|
|
|
for tx in outs:
|
2018-01-25 07:50:09 +00:00
|
|
|
print(pmt2str(tx))
|