mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 09:52:09 +01:00
Validate key manager matches account db on wallet startup (#1948)
This commit is contained in:
parent
1670902e75
commit
babab55eac
@ -117,9 +117,34 @@ abstract class Wallet
|
||||
} else FutureUtil.unit
|
||||
} yield ()
|
||||
|
||||
private def checkRootAccount: Future[Unit] = {
|
||||
val coinType = HDUtil.getCoinType(keyManager.kmParams.network)
|
||||
val coin =
|
||||
HDCoin(purpose = keyManager.kmParams.purpose, coinType = coinType)
|
||||
val account = HDAccount(coin = coin, index = 0)
|
||||
// safe since we're deriving from a priv
|
||||
val xpub = keyManager.deriveXPub(account).get
|
||||
|
||||
accountDAO.read(account.coin, account.index).flatMap {
|
||||
case Some(account) =>
|
||||
if (account.xpub != xpub) {
|
||||
val errorMsg =
|
||||
s"Divergent xpubs for account=$account. Existing database xpub=${account.xpub}, key manager's xpub=$xpub. " +
|
||||
s"It is possible we have a different key manager being used than expected, key manager=$keyManager"
|
||||
Future.failed(new RuntimeException(errorMsg))
|
||||
} else {
|
||||
FutureUtil.unit
|
||||
}
|
||||
case None =>
|
||||
val errorMsg = s"Missing root xpub for account $account in database"
|
||||
Future.failed(new RuntimeException(errorMsg))
|
||||
}
|
||||
}
|
||||
|
||||
override def start(): Future[Wallet] = {
|
||||
for {
|
||||
_ <- walletConfig.start()
|
||||
_ <- checkRootAccount
|
||||
_ <- downloadMissingUtxos
|
||||
} yield {
|
||||
startWalletThread()
|
||||
|
Loading…
Reference in New Issue
Block a user