mirror of
https://github.com/basicswap/basicswap.git
synced 2025-03-03 07:14:54 +00:00
checkWalletSeed sets expected seed id if missing.
This commit is contained in:
parent
0c01dcf2f5
commit
2929e74c78
2 changed files with 33 additions and 20 deletions
|
@ -979,13 +979,11 @@ class BasicSwap(BaseApp):
|
||||||
core_version = ci.getDaemonVersion()
|
core_version = ci.getDaemonVersion()
|
||||||
self.log.info("%s Core version %d", ci.coin_name(), core_version)
|
self.log.info("%s Core version %d", ci.coin_name(), core_version)
|
||||||
self.coin_clients[c]["core_version"] = core_version
|
self.coin_clients[c]["core_version"] = core_version
|
||||||
# thread_func = threadPollXMRChainState if c in (Coins.XMR, Coins.WOW) else threadPollChainState
|
|
||||||
if c == Coins.XMR:
|
thread_func = {
|
||||||
thread_func = threadPollXMRChainState
|
Coins.XMR: threadPollXMRChainState,
|
||||||
elif c == Coins.WOW:
|
Coins.WOW: threadPollWOWChainState,
|
||||||
thread_func = threadPollWOWChainState
|
}.get(c, threadPollChainState) # default case
|
||||||
else:
|
|
||||||
thread_func = threadPollChainState
|
|
||||||
|
|
||||||
t = threading.Thread(target=thread_func, args=(self, c))
|
t = threading.Thread(target=thread_func, args=(self, c))
|
||||||
self.threads.append(t)
|
self.threads.append(t)
|
||||||
|
@ -1290,6 +1288,20 @@ class BasicSwap(BaseApp):
|
||||||
finally:
|
finally:
|
||||||
self._read_zmq_queue = True
|
self._read_zmq_queue = True
|
||||||
|
|
||||||
|
def storeSeedIDForCoin(self, root_key, coin_type, cursor=None) -> None:
|
||||||
|
ci = self.ci(coin_type)
|
||||||
|
db_key_coin_name = ci.coin_name().lower()
|
||||||
|
seed_id = ci.getSeedHash(root_key)
|
||||||
|
|
||||||
|
key_str = "main_wallet_seedid_" + db_key_coin_name
|
||||||
|
self.setStringKV(key_str, seed_id.hex(), cursor)
|
||||||
|
|
||||||
|
if coin_type == Coins.DCR:
|
||||||
|
# TODO: How to force getmasterpubkey to always return the new slip44 (42) key
|
||||||
|
key_str = "main_wallet_seedid_alt_" + db_key_coin_name
|
||||||
|
legacy_root_hash = ci.getSeedHash(root_key, 20)
|
||||||
|
self.setStringKV(key_str, legacy_root_hash.hex(), cursor)
|
||||||
|
|
||||||
def initialiseWallet(self, coin_type, raise_errors: bool = False) -> None:
|
def initialiseWallet(self, coin_type, raise_errors: bool = False) -> None:
|
||||||
if coin_type == Coins.PART:
|
if coin_type == Coins.PART:
|
||||||
return
|
return
|
||||||
|
@ -1308,7 +1320,6 @@ class BasicSwap(BaseApp):
|
||||||
return
|
return
|
||||||
|
|
||||||
root_key = self.getWalletKey(coin_type, 1)
|
root_key = self.getWalletKey(coin_type, 1)
|
||||||
root_hash = ci.getSeedHash(root_key)
|
|
||||||
try:
|
try:
|
||||||
ci.initialiseWallet(root_key)
|
ci.initialiseWallet(root_key)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -1320,18 +1331,9 @@ class BasicSwap(BaseApp):
|
||||||
self.log.error(traceback.format_exc())
|
self.log.error(traceback.format_exc())
|
||||||
return
|
return
|
||||||
|
|
||||||
legacy_root_hash = None
|
|
||||||
if coin_type == Coins.DCR:
|
|
||||||
legacy_root_hash = ci.getSeedHash(root_key, 20)
|
|
||||||
try:
|
try:
|
||||||
cursor = self.openDB()
|
cursor = self.openDB()
|
||||||
key_str = "main_wallet_seedid_" + db_key_coin_name
|
self.storeSeedIDForCoin(root_key, coin_type, cursor)
|
||||||
self.setStringKV(key_str, root_hash.hex(), cursor)
|
|
||||||
|
|
||||||
if coin_type == Coins.DCR:
|
|
||||||
# TODO: How to force getmasterpubkey to always return the new slip44 (42) key
|
|
||||||
key_str = "main_wallet_seedid_alt_" + db_key_coin_name
|
|
||||||
self.setStringKV(key_str, legacy_root_hash.hex(), cursor)
|
|
||||||
|
|
||||||
# Clear any saved addresses
|
# Clear any saved addresses
|
||||||
self.clearStringKV("receive_addr_" + db_key_coin_name, cursor)
|
self.clearStringKV("receive_addr_" + db_key_coin_name, cursor)
|
||||||
|
@ -2606,9 +2608,19 @@ class BasicSwap(BaseApp):
|
||||||
expect_seedid = self.getStringKV("main_wallet_seedid_" + ci.coin_name().lower())
|
expect_seedid = self.getStringKV("main_wallet_seedid_" + ci.coin_name().lower())
|
||||||
if expect_seedid is None:
|
if expect_seedid is None:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"Can't find expected wallet seed id for coin {}".format(ci.coin_name())
|
"Can't find expected wallet seed id for coin {}.".format(ci.coin_name())
|
||||||
)
|
)
|
||||||
return False
|
_, is_locked = self.getLockedState()
|
||||||
|
if is_locked is False:
|
||||||
|
self.log.warning(
|
||||||
|
"Setting seed id for coin {} from master key.".format(ci.coin_name())
|
||||||
|
)
|
||||||
|
root_key = self.getWalletKey(c, 1)
|
||||||
|
self.storeSeedIDForCoin(root_key, c)
|
||||||
|
else:
|
||||||
|
self.log.warning("Node is locked.")
|
||||||
|
return False
|
||||||
|
|
||||||
if c == Coins.BTC and len(ci.rpc("listwallets")) < 1:
|
if c == Coins.BTC and len(ci.rpc("listwallets")) < 1:
|
||||||
self.log.warning("Missing wallet for coin {}".format(ci.coin_name()))
|
self.log.warning("Missing wallet for coin {}".format(ci.coin_name()))
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -179,6 +179,7 @@ class Test(BaseTest):
|
||||||
== "8e54a313e6df8918df6d758fafdbf127a115175fdd2238d0e908dd8093c9ac3b"
|
== "8e54a313e6df8918df6d758fafdbf127a115175fdd2238d0e908dd8093c9ac3b"
|
||||||
)
|
)
|
||||||
assert rv["seed_id"] == "3da5c0af91879e8ce97d9a843874601c08688078"
|
assert rv["seed_id"] == "3da5c0af91879e8ce97d9a843874601c08688078"
|
||||||
|
assert (rv["seed_id"] == rv["expected_seed_id"])
|
||||||
|
|
||||||
rv = read_json_api(
|
rv = read_json_api(
|
||||||
1800,
|
1800,
|
||||||
|
|
Loading…
Reference in a new issue