wallet: make sure payment requests are persisted
Fixes: after adding a payment request, if the process was killed, the payreq might get lost. In case of using the GUI, neither the callee nor the caller called wallet.save_db(). Unclear where wallet.save_db() should be called... Now each method tries to persist their changes by default, but as an optimisation, the caller can pass write_to_disk=False e.g. when calling multiple such methods and then call wallet.save_db() itself. If we had partial writes, which would either rm the need for wallet.save_db() or at least make it cheaper, this code might get simpler... related: https://github.com/spesmilo/electrum/pull/6435 related: https://github.com/spesmilo/electrum/issues/4823
This commit is contained in:
@@ -882,14 +882,12 @@ class Commands:
|
||||
expiration = int(expiration) if expiration else None
|
||||
req = wallet.make_payment_request(addr, amount, memo, expiration)
|
||||
wallet.add_payment_request(req)
|
||||
wallet.save_db()
|
||||
return wallet.export_request(req)
|
||||
|
||||
@command('wn')
|
||||
async def add_lightning_request(self, amount, memo='', expiration=3600, wallet: Abstract_Wallet = None):
|
||||
amount_sat = int(satoshis(amount))
|
||||
key = await wallet.lnworker._add_request_coro(amount_sat, memo, expiration)
|
||||
wallet.save_db()
|
||||
return wallet.get_formatted_request(key)
|
||||
|
||||
@command('w')
|
||||
@@ -913,9 +911,7 @@ class Commands:
|
||||
@command('w')
|
||||
async def rmrequest(self, address, wallet: Abstract_Wallet = None):
|
||||
"""Remove a payment request"""
|
||||
result = wallet.remove_payment_request(address)
|
||||
wallet.save_db()
|
||||
return result
|
||||
return wallet.remove_payment_request(address)
|
||||
|
||||
@command('w')
|
||||
async def clear_requests(self, wallet: Abstract_Wallet = None):
|
||||
|
||||
Reference in New Issue
Block a user