diff --git a/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala b/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala index 4eba89bfb7..80a93a6723 100644 --- a/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala +++ b/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala @@ -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) ) ) } diff --git a/core/src/main/scala/org/bitcoins/core/api/wallet/BlockSyncState.scala b/core/src/main/scala/org/bitcoins/core/api/wallet/BlockSyncState.scala new file mode 100644 index 0000000000..fa807de8d3 --- /dev/null +++ b/core/src/main/scala/org/bitcoins/core/api/wallet/BlockSyncState.scala @@ -0,0 +1,5 @@ +package org.bitcoins.core.api.wallet + +import org.bitcoins.crypto.DoubleSha256DigestBE + +case class BlockSyncState(height: Int, blockHash: DoubleSha256DigestBE) diff --git a/core/src/main/scala/org/bitcoins/core/api/wallet/WalletApi.scala b/core/src/main/scala/org/bitcoins/core/api/wallet/WalletApi.scala index 6b5769755e..91f9ca6c72 100644 --- a/core/src/main/scala/org/bitcoins/core/api/wallet/WalletApi.scala +++ b/core/src/main/scala/org/bitcoins/core/api/wallet/WalletApi.scala @@ -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 */ diff --git a/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala b/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala index 51f6c30289..508c14064b 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala @@ -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] = {