More explicit naming

This commit is contained in:
Michał Sałaban 2018-01-06 16:44:38 +01:00
parent 5355824a61
commit 6a3015d880
4 changed files with 14 additions and 11 deletions

View File

@ -76,7 +76,7 @@ class JSONRPCWallet(object):
for tx in _payments['payments']: for tx in _payments['payments']:
data = self._tx2dict(tx) data = self._tx2dict(tx)
# Monero <= 0.11 : no address is passed because there's only one # Monero <= 0.11 : no address is passed because there's only one
data['address'] = data['address'] or self._master_address data['local_address'] = data['local_address'] or self._master_address
pmts.append(Payment(**data)) pmts.append(Payment(**data))
return pmts return pmts
@ -100,7 +100,7 @@ class JSONRPCWallet(object):
'payment_id': tx['payment_id'], 'payment_id': tx['payment_id'],
'note': tx.get('note'), 'note': tx.get('note'),
# NOTE: address will be resolved only after PR#3010 has been merged to Monero # NOTE: address will be resolved only after PR#3010 has been merged to Monero
'address': address(tx['address']) if 'address' in tx else None, 'local_address': address(tx['address']) if 'address' in tx else None,
'key': tx.get('key'), 'key': tx.get('key'),
'blob': tx.get('blob', None), 'blob': tx.get('blob', None),
} }

View File

@ -5,7 +5,7 @@ class Transaction(object):
payment_id = '0000000000000000' payment_id = '0000000000000000'
amount = None amount = None
fee = None fee = None
address = None local_address = None
def __init__(self, hash=None, **kwargs): def __init__(self, hash=None, **kwargs):
self.hash = hash self.hash = hash
@ -14,7 +14,10 @@ class Transaction(object):
self.payment_id = kwargs.get('payment_id', self.payment_id) self.payment_id = kwargs.get('payment_id', self.payment_id)
self.amount = kwargs.get('amount', self.amount) self.amount = kwargs.get('amount', self.amount)
self.fee = kwargs.get('fee', self.fee) self.fee = kwargs.get('fee', self.fee)
self.address = kwargs.get('address', self.address) self.local_address = kwargs.get('local_address', self.local_address)
def __repr__(self):
return self.hash
class Payment(Transaction): class Payment(Transaction):

View File

@ -281,6 +281,6 @@ class SubaddrWalletTestCase(unittest.TestCase):
self.assertEqual(len(list(payments)), 1) self.assertEqual(len(list(payments)), 1)
for payment in payments: for payment in payments:
self.assertIsInstance(payment, Payment) self.assertIsInstance(payment, Payment)
self.assertIsInstance(payment.address, Address) self.assertIsInstance(payment.local_address, Address)
self.assertIsInstance(payment.amount, Decimal) self.assertIsInstance(payment.amount, Decimal)
self.assertIsInstance(payment.height, int) self.assertIsInstance(payment.height, int)

View File

@ -33,7 +33,7 @@ def get_wallet():
password=args.password)) password=args.password))
_TXHDR = "timestamp height id/hash " \ _TXHDR = "timestamp height id/hash " \
" amount fee payment_id" " amount fee payment_id {dir}"
def tx2str(tx): def tx2str(tx):
return "{time} {height} {hash} {amount:17.12f} {fee:13.12f} {payment_id} {addr}".format( return "{time} {height} {hash} {amount:17.12f} {fee:13.12f} {payment_id} {addr}".format(
@ -43,7 +43,7 @@ def tx2str(tx):
amount=tx.amount, amount=tx.amount,
fee=tx.fee or 0, fee=tx.fee or 0,
payment_id=tx.payment_id, payment_id=tx.payment_id,
addr=getattr(tx, 'receiving_address', None) or '') addr=getattr(tx, 'local_address', None) or '')
w = get_wallet() w = get_wallet()
print( print(
@ -66,25 +66,25 @@ if len(w.accounts) > 1:
ins = acc.get_transactions_in() ins = acc.get_transactions_in()
if ins: if ins:
print("\nIncoming transactions:") print("\nIncoming transactions:")
print(_TXHDR) print(_TXHDR.format(dir='received by'))
for tx in ins: for tx in ins:
print(tx2str(tx)) print(tx2str(tx))
outs = acc.get_transactions_out() outs = acc.get_transactions_out()
if outs: if outs:
print("\nOutgoing transactions:") print("\nOutgoing transactions:")
print(_TXHDR) print(_TXHDR.format(dir='sent from'))
for tx in outs: for tx in outs:
print(tx2str(tx)) print(tx2str(tx))
else: else:
ins = w.get_transactions_in() ins = w.get_transactions_in()
if ins: if ins:
print("\nIncoming transactions:") print("\nIncoming transactions:")
print(_TXHDR) print(_TXHDR.format(dir='received by'))
for tx in ins: for tx in ins:
print(tx2str(tx)) print(tx2str(tx))
outs = w.get_transactions_out() outs = w.get_transactions_out()
if outs: if outs:
print("\nOutgoing transactions:") print("\nOutgoing transactions:")
print(_TXHDR) print(_TXHDR.format(dir='sent from'))
for tx in outs: for tx in outs:
print(tx2str(tx)) print(tx2str(tx))