Skip to content

Commit

Permalink
reintroduce 'unlock' command
Browse files Browse the repository at this point in the history
- the unlock command was replaced by an option to load_wallet,
because some applications (the swapserver plugin) need to be
executed with an unlocked password. Now the swapserver plugin
waits until the wallet is unlocked.
- wallet.unlock now checks password unconditionally, see #8799
  • Loading branch information
ecdsa committed Jun 8, 2024
1 parent 1705e47 commit 912e1a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions electrum/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,13 @@ async def list_wallets(self):
]

@command('n')
async def load_wallet(self, wallet_path=None, unlock=False, password=None):
async def load_wallet(self, wallet_path=None, password=None):
"""
Load the wallet in memory
"""
wallet = self.daemon.load_wallet(wallet_path, password, upgrade=True)
if wallet is None:
raise UserFacingException('could not load wallet')
if unlock:
# FIXME if this raises, load_wallet() above still succeeded...
wallet.unlock(password)
run_hook('load_wallet', wallet, None)

@command('n')
Expand Down Expand Up @@ -368,6 +365,11 @@ async def getaddresshistory(self, address):
sh = bitcoin.address_to_scripthash(address)
return await self.network.get_history_for_scripthash(sh)

@command('wp')
async def unlock(self, wallet: Abstract_Wallet = None, password=None):
"""Unlock the wallet (store the password in memory)."""
wallet.unlock(password)

@command('w')
async def listunspent(self, wallet: Abstract_Wallet = None):
"""List unspent outputs. Returns the list of unspent transaction
Expand Down Expand Up @@ -1470,7 +1472,6 @@ def eval_bool(x: str) -> bool:
'from_amount': (None, "Amount to convert (default: 1)"),
'from_ccy': (None, "Currency to convert from"),
'to_ccy': (None, "Currency to convert to"),
'unlock': (None, "Unlock the wallet (store the password in memory)."),
'public': (None, 'Channel will be announced'),
}

Expand Down
5 changes: 5 additions & 0 deletions electrum/plugins/swapserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def __init__(self, config: 'SimpleConfig', wallet: 'Abstract_Wallet'):
@ignore_exceptions
@log_exceptions
async def run(self):

while self.wallet.has_password() and self.wallet.get_unlocked_password() is None:
self.logger.info("This wallet is password-protected. Please unlock it to start the swapserver plugin")
await asyncio.sleep(10)

app = web.Application()
app.add_routes([web.get('/getpairs', self.get_pairs)])
app.add_routes([web.post('/createswap', self.create_swap)])
Expand Down
3 changes: 1 addition & 2 deletions electrum/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3274,8 +3274,7 @@ def synchronize(self) -> int:

def unlock(self, password):
self.logger.info(f'unlocking wallet')
if self.has_password():
self.check_password(password)
self.check_password(password)
self._password_in_memory = password

def get_unlocked_password(self):
Expand Down

0 comments on commit 912e1a3

Please sign in to comment.