diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 57a2202..9cccfd9 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -645,23 +645,7 @@ class BasicSwap(BaseApp): elif c == Coins.XMR: ci.ensureWalletExists() - expect_address = self.getStringKV('main_wallet_addr_' + chainparams[c]['name']) - if expect_address is None: - self.log.warning('Can\'t find expected main wallet address for coin {}'.format(ci.coin_name())) - else: - if expect_address == ci.getMainWalletAddress(): - ci.setWalletSeedWarning(False) - else: - self.log.warning('Wallet for coin {} not derived from swap seed.'.format(ci.coin_name())) - else: - expect_seedid = self.getStringKV('main_wallet_seedid_' + chainparams[c]['name']) - if expect_seedid is None: - self.log.warning('Can\'t find expected wallet seed id for coin {}'.format(ci.coin_name())) - else: - if expect_seedid == ci.getWalletSeedID(): - ci.setWalletSeedWarning(False) - else: - self.log.warning('Wallet for coin {} not derived from swap seed.'.format(ci.coin_name())) + self.checkWalletSeed(c) self.initialise() @@ -769,7 +753,7 @@ class BasicSwap(BaseApp): return root_key = self.getWalletKey(coin_type, 1) - root_hash = ci.getAddressHashFromKey(root_key) + root_hash = ci.getAddressHashFromKey(root_key)[::-1] ci.initialiseWallet(root_key) key_str = 'main_wallet_seedid_' + chainparams[coin_type]['name'] @@ -1254,6 +1238,47 @@ class BasicSwap(BaseApp): self.setStringKV(key_str, addr) return addr + def checkWalletSeed(self, c): + ci = self.ci(c) + if c == Coins.PART: + return True # TODO + if c == Coins.XMR: + expect_address = self.getStringKV('main_wallet_addr_' + chainparams[c]['name']) + if expect_address is None: + self.log.warning('Can\'t find expected main wallet address for coin {}'.format(ci.coin_name())) + return False + if expect_address == ci.getMainWalletAddress(): + ci.setWalletSeedWarning(False) + return True + self.log.warning('Wallet for coin {} not derived from swap seed.'.format(ci.coin_name())) + return False + + expect_seedid = self.getStringKV('main_wallet_seedid_' + chainparams[c]['name']) + if expect_seedid is None: + self.log.warning('Can\'t find expected wallet seed id for coin {}'.format(ci.coin_name())) + return False + if expect_seedid == ci.getWalletSeedID(): + ci.setWalletSeedWarning(False) + return True + self.log.warning('Wallet for coin {} not derived from swap seed.'.format(ci.coin_name())) + return False + + def reseedWallet(self, coin_type): + self.log.info('reseedWallet %s', coin_type) + ci = self.ci(coin_type) + if ci.knownWalletSeed(): + raise ValueError('{} wallet seed is already derived from the particl mnemonic'.format(ci.coin_name())) + + self.initialiseWallet(coin_type) + + # TODO: How to scan pruned blocks? + + if not self.checkWalletSeed(coin_type): + if coin_type == Coins.XMR: + raise ValueError('TODO: How to reseed XMR wallet?') + else: + raise ValueError('Wallet seed doesn\'t match expected.') + def getCachedAddressForCoin(self, coin_type): self.log.debug('getCachedAddressForCoin %s', coin_type) # TODO: auto refresh after used diff --git a/basicswap/http_server.py b/basicswap/http_server.py index fd9af4e..814abc2 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -221,8 +221,13 @@ class HttpHandler(BaseHTTPRequestHandler): if bytes('newaddr_' + cid, 'utf-8') in form_data: swap_client.cacheNewAddressForCoin(c) - - if bytes('withdraw_' + cid, 'utf-8') in form_data: + elif bytes('reseed_' + cid, 'utf-8') in form_data: + try: + swap_client.reseedWallet(c) + messages.append('Reseed complete ' + str(c)) + except Exception as ex: + messages.append('Reseed failed ' + str(ex)) + elif bytes('withdraw_' + cid, 'utf-8') in form_data: value = form_data[bytes('amt_' + cid, 'utf-8')][0].decode('utf-8') address = form_data[bytes('to_' + cid, 'utf-8')][0].decode('utf-8') subfee = True if bytes('subfee_' + cid, 'utf-8') in form_data else False @@ -255,6 +260,7 @@ class HttpHandler(BaseHTTPRequestHandler): 'synced': w['synced'], 'deposit_address': w['deposit_address'], 'expected_seed': w['expected_seed'], + 'balance_all': float(w['balance']) + float(w['unconfirmed']), }) if float(w['unconfirmed']) > 0.0: wallets_formatted[-1]['unconfirmed'] = w['unconfirmed'] @@ -263,6 +269,7 @@ class HttpHandler(BaseHTTPRequestHandler): return bytes(template.render( title=self.server.title, h2=self.server.title, + messages=messages, wallets=wallets_formatted, form_id=os.urandom(8).hex(), ), 'UTF-8') diff --git a/basicswap/templates/wallets.html b/basicswap/templates/wallets.html index 29089e5..82de2e4 100644 --- a/basicswap/templates/wallets.html +++ b/basicswap/templates/wallets.html @@ -11,7 +11,6 @@
- {% for w in wallets %}

{{ w.name }} {{ w.version }}

{% if w.error %} @@ -21,7 +20,7 @@ Balance:{{ w.balance }}{% if w.unconfirmed %}Unconfirmed:{{ w.unconfirmed }}{% endif %} Blocks:{{ w.blocks }} Synced:{{ w.synced }} -Expected Seed:{{ w.expected_seed }} +Expected Seed:{{ w.expected_seed }}{% if w.expected_seed != true %}{% endif %} {{ w.deposit_address }} Amount: Address: Subtract fee: Fee Rate:{{ w.fee_rate }}Est Fee:{{ w.est_fee }} @@ -33,4 +32,10 @@

home

+ +