wallet_rpc_server: fix inconsistent wallet caches on reload

Loading the same wallet as the currently loaded one would autosave
the current state after loading it, leading to some kind of rollback
effect. We now save before loading to avoid this. If loading fails,
it means the current wallet will be saved (or maybe not, depending
on where the failure occurs: most of the sanity checks occur before
saving). There is a new autosave_current flag to open/restore calls
so the (enabled by default) autosave can be skipped.
This commit is contained in:
moneromooo-monero 2019-04-12 13:36:46 +00:00
parent 9c77dbf376
commit bcb86ae651
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 78 additions and 46 deletions

View file

@ -265,7 +265,7 @@ class Wallet(object):
}
return self.rpc.send_json_rpc_request(query_key)
def restore_deterministic_wallet(self, seed = '', seed_offset = '', filename = '', restore_height = 0, password = '', language = ''):
def restore_deterministic_wallet(self, seed = '', seed_offset = '', filename = '', restore_height = 0, password = '', language = '', autosave_current = True):
restore_deterministic_wallet = {
'method': 'restore_deterministic_wallet',
'params' : {
@ -274,14 +274,15 @@ class Wallet(object):
'seed': seed,
'seed_offset': seed_offset,
'password': password,
'language': language
'language': language,
'autosave_current': autosave_current,
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(restore_deterministic_wallet)
def generate_from_keys(self, restore_height = 0, filename = "", password = "", address = "", spendkey = "", viewkey = ""):
def generate_from_keys(self, restore_height = 0, filename = "", password = "", address = "", spendkey = "", viewkey = "", autosave_current = True):
generate_from_keys = {
'method': 'generate_from_keys',
'params' : {
@ -291,16 +292,31 @@ class Wallet(object):
'spendkey': spendkey,
'viewkey': viewkey,
'password': password,
'autosave_current': autosave_current,
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(generate_from_keys)
def close_wallet(self):
def open_wallet(self, filename, password='', autosave_current = True):
open_wallet = {
'method': 'open_wallet',
'params' : {
'filename': filename,
'password': password,
'autosave_current': autosave_current,
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(open_wallet)
def close_wallet(self, autosave_current = True):
close_wallet = {
'method': 'close_wallet',
'params' : {
'autosave_current': autosave_current
},
'jsonrpc': '2.0',
'id': '0'