Create BlockSyncState type (#2567)

This commit is contained in:
benthecarman 2021-01-27 14:15:07 -06:00 committed by GitHub
parent d305dc50d5
commit fa27fb3fb1
4 changed files with 28 additions and 3 deletions

View File

@ -562,7 +562,10 @@ case class WalletRoutes(wallet: AnyHDWalletApi)(implicit
/** Returns information about the state of our wallet */
def getInfo: Future[Obj] = {
wallet.getDefaultAccount().map { accountDb =>
for {
accountDb <- wallet.getDefaultAccount()
walletState <- wallet.getSyncState()
} yield {
Obj(
WalletAppConfig.moduleName ->
Obj(
@ -570,7 +573,9 @@ case class WalletRoutes(wallet: AnyHDWalletApi)(implicit
"rootXpub" -> Str(wallet.keyManager.getRootXPub.toString)
),
"xpub" -> Str(accountDb.xpub.toString),
"hdPath" -> Str(accountDb.hdAccount.toString)
"hdPath" -> Str(accountDb.hdAccount.toString),
"height" -> Num(walletState.height),
"blockHash" -> Str(walletState.blockHash.hex)
)
)
}

View File

@ -0,0 +1,5 @@
package org.bitcoins.core.api.wallet
import org.bitcoins.crypto.DoubleSha256DigestBE
case class BlockSyncState(height: Int, blockHash: DoubleSha256DigestBE)

View File

@ -396,6 +396,8 @@ trait WalletApi extends StartStopAsync[WalletApi] {
* is a change output from this wallet
*/
def isChange(output: TransactionOutput): Future[Boolean]
def getSyncState(): Future[BlockSyncState]
}
/** An HDWallet that uses Neutrino to sync */

View File

@ -5,7 +5,11 @@ import org.bitcoins.core.api.chain.ChainQueryApi
import org.bitcoins.core.api.feeprovider.FeeRateApi
import org.bitcoins.core.api.node.NodeApi
import org.bitcoins.core.api.wallet.db.{AccountDb, SpendingInfoDb}
import org.bitcoins.core.api.wallet.{AnyHDWalletApi, CoinSelectionAlgo}
import org.bitcoins.core.api.wallet.{
AnyHDWalletApi,
BlockSyncState,
CoinSelectionAlgo
}
import org.bitcoins.core.bloom.{BloomFilter, BloomUpdateAll}
import org.bitcoins.core.config.NetworkParameters
import org.bitcoins.core.crypto.ExtPublicKey
@ -161,6 +165,15 @@ abstract class Wallet
stateDescriptorDAO.getSyncDescriptorOpt()
}
override def getSyncState(): Future[BlockSyncState] = {
getSyncDescriptorOpt().map {
case Some(descriptor) =>
BlockSyncState(descriptor.height, descriptor.bestHash)
case None =>
BlockSyncState(0, chainParams.genesisHashBE)
}
}
override def processCompactFilters(
blockFilters: Vector[(DoubleSha256Digest, GolombFilter)]): Future[
Wallet] = {