2017-11-26 22:22:48 +00:00
|
|
|
from . import address
|
|
|
|
from . import prio
|
|
|
|
from . import account
|
2018-01-22 02:55:08 +00:00
|
|
|
from . import transaction
|
2017-11-26 22:22:48 +00:00
|
|
|
|
|
|
|
class Wallet(object):
|
|
|
|
accounts = None
|
|
|
|
|
|
|
|
def __init__(self, backend):
|
|
|
|
self._backend = backend
|
|
|
|
self.refresh()
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
self.accounts = self.accounts or []
|
|
|
|
idx = 0
|
|
|
|
for _acc in self._backend.get_accounts():
|
|
|
|
try:
|
|
|
|
if self.accounts[idx]:
|
|
|
|
continue
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
self.accounts.append(_acc)
|
|
|
|
idx += 1
|
|
|
|
|
2018-01-22 02:55:08 +00:00
|
|
|
def get_height(self):
|
|
|
|
"""
|
|
|
|
Returns the height of the wallet.
|
|
|
|
"""
|
|
|
|
return self._backend.get_height()
|
|
|
|
|
2018-01-14 05:28:28 +00:00
|
|
|
def get_view_key(self):
|
|
|
|
"""
|
|
|
|
Returns private view key.
|
|
|
|
"""
|
|
|
|
return self._backend.get_view_key()
|
|
|
|
|
|
|
|
def get_seed(self):
|
|
|
|
"""
|
|
|
|
Returns word seed.
|
|
|
|
"""
|
|
|
|
return self._backend.get_seed()
|
|
|
|
|
2018-01-11 22:17:34 +00:00
|
|
|
def new_account(self, label=None):
|
|
|
|
acc, addr = self._backend.new_account(label=label)
|
|
|
|
assert acc.index == len(self.accounts)
|
|
|
|
self.accounts.append(acc)
|
|
|
|
return acc
|
|
|
|
|
2018-01-22 02:55:08 +00:00
|
|
|
def get_transaction(self, hash):
|
|
|
|
return self._backend.get_transaction(hash)
|
|
|
|
|
|
|
|
def confirmations(self, txn):
|
|
|
|
txn = self._backend.get_transaction(txn)
|
|
|
|
if txn.height is None:
|
|
|
|
return 0
|
|
|
|
return max(0, self.get_height() - txn.height)
|
|
|
|
|
2017-11-26 22:22:48 +00:00
|
|
|
# Following methods operate on default account (index=0)
|
2017-12-01 05:06:15 +00:00
|
|
|
def get_balances(self):
|
|
|
|
return self.accounts[0].get_balances()
|
|
|
|
|
|
|
|
def get_balance(self, unlocked=False):
|
|
|
|
return self.accounts[0].get_balance(unlocked=unlocked)
|
2017-11-26 22:22:48 +00:00
|
|
|
|
2018-01-13 21:24:17 +00:00
|
|
|
def get_address(self):
|
2017-11-26 22:22:48 +00:00
|
|
|
return self.accounts[0].get_addresses()[0]
|
|
|
|
|
2018-01-13 21:24:17 +00:00
|
|
|
def get_addresses(self):
|
|
|
|
return self.accounts[0].get_addresses()
|
|
|
|
|
2018-01-11 22:17:34 +00:00
|
|
|
def new_address(self, label=None):
|
|
|
|
return self.accounts[0].new_address(label=label)
|
|
|
|
|
2017-12-27 00:49:59 +00:00
|
|
|
def get_payments(self, payment_id=None):
|
|
|
|
return self.accounts[0].get_payments(payment_id=payment_id)
|
2017-11-26 22:22:48 +00:00
|
|
|
|
2018-01-22 02:55:08 +00:00
|
|
|
def get_transactions_in(self, confirmed=True, unconfirmed=False):
|
|
|
|
return self.accounts[0].get_transactions_in(cofirmed=confirmed, unconfirmed=unconfirmed)
|
2017-12-27 00:49:59 +00:00
|
|
|
|
2018-01-22 02:55:08 +00:00
|
|
|
def get_transactions_out(self, confirmed=True, unconfirmed=True):
|
|
|
|
return self.accounts[0].get_transactions_out(confirmed=confirmed, unconfirmed=unconfirmed)
|
2017-11-26 22:22:48 +00:00
|
|
|
|
2018-01-14 02:40:46 +00:00
|
|
|
def transfer(self, address, amount,
|
|
|
|
priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0,
|
|
|
|
relay=True):
|
2017-11-29 03:38:29 +00:00
|
|
|
return self.accounts[0].transfer(
|
|
|
|
address,
|
|
|
|
amount,
|
|
|
|
priority=priority,
|
2018-01-13 21:24:17 +00:00
|
|
|
ringsize=ringsize,
|
2018-01-11 05:13:33 +00:00
|
|
|
payment_id=None,
|
2018-01-14 02:40:46 +00:00
|
|
|
unlock_time=unlock_time,
|
|
|
|
relay=relay)
|
2017-11-29 03:38:29 +00:00
|
|
|
|
2018-01-14 02:40:46 +00:00
|
|
|
def transfer_multiple(self, destinations,
|
|
|
|
priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0,
|
|
|
|
relay=True):
|
2017-11-26 22:22:48 +00:00
|
|
|
"""
|
|
|
|
destinations = [(address, amount), ...]
|
|
|
|
"""
|
2017-11-29 03:38:29 +00:00
|
|
|
return self.accounts[0].transfer_multiple(
|
|
|
|
destinations,
|
|
|
|
priority=priority,
|
2018-01-13 21:24:17 +00:00
|
|
|
ringsize=ringsize,
|
2018-01-11 05:13:33 +00:00
|
|
|
payment_id=None,
|
2018-01-14 02:40:46 +00:00
|
|
|
unlock_time=unlock_time,
|
|
|
|
relay=relay)
|