Reorganize payments and transactions

This commit is contained in:
Michał Sałaban 2018-01-25 08:50:09 +01:00
parent 8ae386904a
commit a16ae37a94
7 changed files with 146 additions and 98 deletions

View file

@ -6,6 +6,7 @@ import sys
from monero.backends.jsonrpc import JSONRPCDaemon
from monero.daemon import Daemon
from monero.transaction import Transaction
from monero import exceptions
def url_data(url):
@ -35,8 +36,9 @@ else:
d = Daemon(JSONRPCDaemon(**args.daemon_rpc_url))
for name, blob in blobs:
logging.debug("Sending {}".format(name))
tx = Transaction(blob=blob)
try:
res = d.send_transaction(blob)
res = d.send_transaction(tx)
except exceptions.TransactionBroadcastError as e:
print("{} not sent, reason: {}".format(name, e.details['reason']))
logging.debug(e.details)

View file

@ -51,14 +51,14 @@ elif args.verbosity > 1:
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
w = Wallet(JSONRPCWallet(**args.wallet_rpc_url))
txfrs = w.accounts[args.account].transfer_multiple(
txns = w.accounts[args.account].transfer_multiple(
args.destinations, priority=prio, ringsize=args.ring_size, payment_id=args.payment_id,
relay=args.outdir is None)
for tx in txfrs:
print(u"Transaction {hash}:\nXMR: {amount:21.12f} @ {fee:13.12f} fee\n"
u"Payment ID: {payment_id}\nTx key: {key}\nSize: {size} B".format(
hash=tx.hash, amount=tx.amount, fee=tx.fee,
payment_id=tx.payment_id, key=tx.key, size=len(tx.blob) >> 1))
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))
if args.outdir:
outname = os.path.join(args.outdir, tx.hash + '.tx')
outfile = open(outname, 'wb')

View file

@ -35,15 +35,15 @@ def get_wallet():
_TXHDR = "timestamp height id/hash " \
" amount fee {dir:95s} payment_id"
def tx2str(tx):
def pmt2str(pmt):
return "{time} {height:7d} {hash} {amount:17.12f} {fee:13.12f} {addr} {payment_id}".format(
time=tx.timestamp.strftime("%d-%m-%y %H:%M:%S") if getattr(tx, 'timestamp', None) else None,
height=tx.height or 0,
hash=tx.hash,
amount=tx.amount,
fee=tx.fee or 0,
payment_id=tx.payment_id,
addr=getattr(tx, 'local_address', None) or '')
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 '')
def a2str(a):
return "{addr} {label}".format(
@ -85,23 +85,23 @@ if len(w.accounts) > 1:
print("\nIncoming transactions:")
print(_TXHDR.format(dir='received by'))
for tx in ins:
print(tx2str(tx))
print(pmt2str(tx))
outs = acc.get_transactions_out(unconfirmed=True)
if outs:
print("\nOutgoing transactions:")
print(_TXHDR.format(dir='sent from'))
for tx in outs:
print(tx2str(tx))
print(pmt2str(tx))
else:
ins = w.get_transactions_in(unconfirmed=True)
if ins:
print("\nIncoming transactions:")
print(_TXHDR.format(dir='received by'))
for tx in ins:
print(tx2str(tx))
print(pmt2str(tx))
outs = w.get_transactions_out(unconfirmed=True)
if outs:
print("\nOutgoing transactions:")
print(_TXHDR.format(dir='sent from'))
for tx in outs:
print(tx2str(tx))
print(pmt2str(tx))