Reseed wallet option.
This commit is contained in:
		
							parent
							
								
									e70477eb64
								
							
						
					
					
						commit
						7bb2cd7d1e
					
				@ -645,23 +645,7 @@ class BasicSwap(BaseApp):
 | 
				
			|||||||
                elif c == Coins.XMR:
 | 
					                elif c == Coins.XMR:
 | 
				
			||||||
                    ci.ensureWalletExists()
 | 
					                    ci.ensureWalletExists()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    expect_address = self.getStringKV('main_wallet_addr_' + chainparams[c]['name'])
 | 
					                self.checkWalletSeed(c)
 | 
				
			||||||
                    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.initialise()
 | 
					        self.initialise()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -769,7 +753,7 @@ class BasicSwap(BaseApp):
 | 
				
			|||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        root_key = self.getWalletKey(coin_type, 1)
 | 
					        root_key = self.getWalletKey(coin_type, 1)
 | 
				
			||||||
        root_hash = ci.getAddressHashFromKey(root_key)
 | 
					        root_hash = ci.getAddressHashFromKey(root_key)[::-1]
 | 
				
			||||||
        ci.initialiseWallet(root_key)
 | 
					        ci.initialiseWallet(root_key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        key_str = 'main_wallet_seedid_' + chainparams[coin_type]['name']
 | 
					        key_str = 'main_wallet_seedid_' + chainparams[coin_type]['name']
 | 
				
			||||||
@ -1254,6 +1238,47 @@ class BasicSwap(BaseApp):
 | 
				
			|||||||
        self.setStringKV(key_str, addr)
 | 
					        self.setStringKV(key_str, addr)
 | 
				
			||||||
        return 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):
 | 
					    def getCachedAddressForCoin(self, coin_type):
 | 
				
			||||||
        self.log.debug('getCachedAddressForCoin %s', coin_type)
 | 
					        self.log.debug('getCachedAddressForCoin %s', coin_type)
 | 
				
			||||||
        # TODO: auto refresh after used
 | 
					        # TODO: auto refresh after used
 | 
				
			||||||
 | 
				
			|||||||
@ -221,8 +221,13 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if bytes('newaddr_' + cid, 'utf-8') in form_data:
 | 
					                if bytes('newaddr_' + cid, 'utf-8') in form_data:
 | 
				
			||||||
                    swap_client.cacheNewAddressForCoin(c)
 | 
					                    swap_client.cacheNewAddressForCoin(c)
 | 
				
			||||||
 | 
					                elif bytes('reseed_' + cid, 'utf-8') in form_data:
 | 
				
			||||||
                if bytes('withdraw_' + 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')
 | 
					                    value = form_data[bytes('amt_' + cid, 'utf-8')][0].decode('utf-8')
 | 
				
			||||||
                    address = form_data[bytes('to_' + 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
 | 
					                    subfee = True if bytes('subfee_' + cid, 'utf-8') in form_data else False
 | 
				
			||||||
@ -255,6 +260,7 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
                'synced': w['synced'],
 | 
					                'synced': w['synced'],
 | 
				
			||||||
                'deposit_address': w['deposit_address'],
 | 
					                'deposit_address': w['deposit_address'],
 | 
				
			||||||
                'expected_seed': w['expected_seed'],
 | 
					                'expected_seed': w['expected_seed'],
 | 
				
			||||||
 | 
					                'balance_all': float(w['balance']) + float(w['unconfirmed']),
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            if float(w['unconfirmed']) > 0.0:
 | 
					            if float(w['unconfirmed']) > 0.0:
 | 
				
			||||||
                wallets_formatted[-1]['unconfirmed'] = w['unconfirmed']
 | 
					                wallets_formatted[-1]['unconfirmed'] = w['unconfirmed']
 | 
				
			||||||
@ -263,6 +269,7 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
        return bytes(template.render(
 | 
					        return bytes(template.render(
 | 
				
			||||||
            title=self.server.title,
 | 
					            title=self.server.title,
 | 
				
			||||||
            h2=self.server.title,
 | 
					            h2=self.server.title,
 | 
				
			||||||
 | 
					            messages=messages,
 | 
				
			||||||
            wallets=wallets_formatted,
 | 
					            wallets=wallets_formatted,
 | 
				
			||||||
            form_id=os.urandom(8).hex(),
 | 
					            form_id=os.urandom(8).hex(),
 | 
				
			||||||
        ), 'UTF-8')
 | 
					        ), 'UTF-8')
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<form method="post">
 | 
					<form method="post">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
{% for w in wallets %}
 | 
					{% for w in wallets %}
 | 
				
			||||||
<h4>{{ w.name }} {{ w.version }}</h4>
 | 
					<h4>{{ w.name }} {{ w.version }}</h4>
 | 
				
			||||||
{% if w.error %}
 | 
					{% if w.error %}
 | 
				
			||||||
@ -21,7 +20,7 @@
 | 
				
			|||||||
<tr><td>Balance:</td><td>{{ w.balance }}</td>{% if w.unconfirmed %}<td>Unconfirmed:</td><td>{{ w.unconfirmed }}</td>{% endif %}</tr>
 | 
					<tr><td>Balance:</td><td>{{ w.balance }}</td>{% if w.unconfirmed %}<td>Unconfirmed:</td><td>{{ w.unconfirmed }}</td>{% endif %}</tr>
 | 
				
			||||||
<tr><td>Blocks:</td><td>{{ w.blocks }}</td></tr>
 | 
					<tr><td>Blocks:</td><td>{{ w.blocks }}</td></tr>
 | 
				
			||||||
<tr><td>Synced:</td><td>{{ w.synced }}</td></tr>
 | 
					<tr><td>Synced:</td><td>{{ w.synced }}</td></tr>
 | 
				
			||||||
<tr><td>Expected Seed:</td><td>{{ w.expected_seed }}</td></tr>
 | 
					<tr><td>Expected Seed:</td><td>{{ w.expected_seed }}</td>{% if w.expected_seed != true %}<td><input type="submit" name="reseed_{{ w.cid }}" value="Reseed wallet" onclick="confirmReseed()"></td>{% endif %}</tr>
 | 
				
			||||||
<tr><td><input type="submit" name="newaddr_{{ w.cid }}" value="Deposit Address"></td><td>{{ w.deposit_address }}</td></tr>
 | 
					<tr><td><input type="submit" name="newaddr_{{ w.cid }}" value="Deposit Address"></td><td>{{ w.deposit_address }}</td></tr>
 | 
				
			||||||
<tr><td><input type="submit" name="withdraw_{{ w.cid }}" value="Withdraw"></td><td>Amount: <input type="text" name="amt_{{ w.cid }}"></td><td>Address: <input type="text" name="to_{{ w.cid }}"></td><td>Subtract fee: <input type="checkbox" name="subfee_{{ w.cid }}"></td></tr>
 | 
					<tr><td><input type="submit" name="withdraw_{{ w.cid }}" value="Withdraw"></td><td>Amount: <input type="text" name="amt_{{ w.cid }}"></td><td>Address: <input type="text" name="to_{{ w.cid }}"></td><td>Subtract fee: <input type="checkbox" name="subfee_{{ w.cid }}"></td></tr>
 | 
				
			||||||
<tr><td>Fee Rate:</td><td>{{ w.fee_rate }}</td><td>Est Fee:</td><td>{{ w.est_fee }}</td></tr>
 | 
					<tr><td>Fee Rate:</td><td>{{ w.fee_rate }}</td><td>Est Fee:</td><td>{{ w.est_fee }}</td></tr>
 | 
				
			||||||
@ -33,4 +32,10 @@
 | 
				
			|||||||
</form>
 | 
					</form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p><a href="/">home</a></p>
 | 
					<p><a href="/">home</a></p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					function confirmReseed() {
 | 
				
			||||||
 | 
					    confirm("Are you sure?\nBackup your wallet before and after.\nWon't detect used keys.\nShould only be used for new wallets.");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
</body></html>
 | 
					</body></html>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user