Differentiate between None and 0 as payment id

This commit is contained in:
Michał Sałaban 2018-01-11 06:13:33 +01:00
parent 5b7dd90b9d
commit 02a599e9ad
3 changed files with 11 additions and 7 deletions

View file

@ -33,7 +33,7 @@ class Account(object):
def get_transactions_out(self):
return self._backend.get_transactions_out(account=self.index)
def transfer(self, address, amount, priority=prio.NORMAL, mixin=5, payment_id=0, unlock_time=0):
def transfer(self, address, amount, priority=prio.NORMAL, mixin=5, payment_id=None, unlock_time=0):
return self._backend.transfer(
[(address, amount)],
priority,
@ -42,7 +42,7 @@ class Account(object):
unlock_time,
account=self.index)
def transfer_multiple(self, destinations, priority=prio.NORMAL, mixin=5, payment_id=0, unlock_time=0):
def transfer_multiple(self, destinations, priority=prio.NORMAL, mixin=5, payment_id=None, unlock_time=0):
"""
destinations = [(address, amount), ...]
"""

View file

@ -89,13 +89,14 @@ class JSONRPCWallet(object):
sorted(_transfers.get('out', []), key=operator.itemgetter('timestamp'))]
def _tx2dict(self, tx):
pid = tx.get('payment_id', None)
return {
'hash': tx.get('txid', tx.get('tx_hash')),
'timestamp': datetime.fromtimestamp(tx['timestamp']) if 'timestamp' in tx else None,
'amount': from_atomic(tx['amount']),
'fee': from_atomic(tx['fee']) if 'fee' in tx else None,
'height': tx.get('height', tx.get('block_height')),
'payment_id': PaymentID(tx.get('payment_id', 0)),
'payment_id': None if pid is None else PaymentID(pid),
'note': tx.get('note'),
# NOTE: address will be resolved only after PR#3010 has been merged to Monero
'local_address': address(tx['address']) if 'address' in tx else None,
@ -103,7 +104,7 @@ class JSONRPCWallet(object):
'blob': tx.get('blob', None),
}
def transfer(self, destinations, priority, mixin, payment_id, unlock_time, account=0):
def transfer(self, destinations, priority, mixin, payment_id=None, unlock_time=0, account=0):
data = {
'account_index': account,
'destinations': list(map(
@ -112,11 +113,12 @@ class JSONRPCWallet(object):
'mixin': mixin,
'priority': priority,
'unlock_time': 0,
'payment_id': str(PaymentID(payment_id)),
'get_tx_keys': True,
'get_tx_hex': True,
'new_algorithm': True,
}
if payment_id is not None:
data['payment_id'] = str(PaymentID(payment_id))
_transfers = self.raw_request('transfer_split', data)
_pertx = [dict(_tx) for _tx in map(
lambda vs: zip(('txid', 'amount', 'fee', 'key', 'blob', 'payment_id'), vs),

View file

@ -40,15 +40,16 @@ class Wallet(object):
def get_transactions_out(self):
return self.accounts[0].get_transactions_out()
def transfer(self, address, amount, priority=prio.NORMAL, mixin=5, unlock_time=0):
def transfer(self, address, amount, priority=prio.NORMAL, mixin=5, payment_id=None, unlock_time=0):
return self.accounts[0].transfer(
address,
amount,
priority=priority,
mixin=mixin,
payment_id=None,
unlock_time=unlock_time)
def transfer_multiple(self, destinations, priority=prio.NORMAL, mixin=5, unlock_time=0):
def transfer_multiple(self, destinations, priority=prio.NORMAL, mixin=5, payment_id=None, unlock_time=0):
"""
destinations = [(address, amount), ...]
"""
@ -56,4 +57,5 @@ class Wallet(object):
destinations,
priority=priority,
mixin=mixin,
payment_id=None,
unlock_time=unlock_time)