Rename wallet.getSyncHeight() -> wallet.getSyncDescriptorOpt(). We don't just use height in the descriptor, the hash is just as valuable for connecting to chains (#2479)

This commit is contained in:
Chris Stewart 2021-01-07 07:40:30 -06:00 committed by GitHub
parent 1ea4e1b0be
commit b76be736b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View file

@ -54,7 +54,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger {
for { for {
bitcoindHeight <- bitcoind.getBlockCount bitcoindHeight <- bitcoind.getBlockCount
walletStateOpt <- wallet.getSyncHeight() walletStateOpt <- wallet.getSyncDescriptorOpt()
_ <- walletStateOpt match { _ <- walletStateOpt match {
case None => case None =>
for { for {

View file

@ -72,7 +72,7 @@ class BitcoindBackendTest extends BitcoinSAsyncTest with EmbeddedPg {
height <- bitcoind.getBlockCount height <- bitcoind.getBlockCount
bestHash <- bitcoind.getBestBlockHash bestHash <- bitcoind.getBestBlockHash
syncHeightOpt <- wallet.getSyncHeight() syncHeightOpt <- wallet.getSyncDescriptorOpt()
} yield { } yield {
assert(balance == amountToSend) assert(balance == amountToSend)
assert(syncHeightOpt.contains(SyncHeightDescriptor(bestHash, height))) assert(syncHeightOpt.contains(SyncHeightDescriptor(bestHash, height)))

View file

@ -35,7 +35,7 @@ class ProcessBlockTest extends BitcoinSWalletTest {
height <- bitcoind.getBlockCount height <- bitcoind.getBlockCount
bestHash <- bitcoind.getBestBlockHash bestHash <- bitcoind.getBestBlockHash
syncHeightOpt <- wallet.getSyncHeight() syncHeightOpt <- wallet.getSyncDescriptorOpt()
} yield { } yield {
assert(utxos.size == 1) assert(utxos.size == 1)
assert(utxos.head.output.scriptPubKey == addr.scriptPubKey) assert(utxos.head.output.scriptPubKey == addr.scriptPubKey)
@ -63,7 +63,7 @@ class ProcessBlockTest extends BitcoinSWalletTest {
height <- bitcoind.getBlockCount height <- bitcoind.getBlockCount
bestHash <- bitcoind.getBestBlockHash bestHash <- bitcoind.getBestBlockHash
syncHeightOpt <- wallet.getSyncHeight() syncHeightOpt <- wallet.getSyncDescriptorOpt()
} yield { } yield {
assert(utxos.size == 100) assert(utxos.size == 100)
assert(balance == Bitcoins(50)) assert(balance == Bitcoins(50))
@ -91,7 +91,7 @@ class ProcessBlockTest extends BitcoinSWalletTest {
height <- bitcoind.getBlockCount height <- bitcoind.getBlockCount
bestHash <- bitcoind.getBestBlockHash bestHash <- bitcoind.getBestBlockHash
syncHeightOpt <- wallet.getSyncHeight() syncHeightOpt <- wallet.getSyncDescriptorOpt()
} yield { } yield {
assert(utxos.size == 100) assert(utxos.size == 100)
assert(balance == Bitcoins(50)) assert(balance == Bitcoins(50))

View file

@ -157,8 +157,8 @@ abstract class Wallet
} }
} }
def getSyncHeight(): Future[Option[SyncHeightDescriptor]] = { def getSyncDescriptorOpt(): Future[Option[SyncHeightDescriptor]] = {
stateDescriptorDAO.getSyncHeightOpt() stateDescriptorDAO.getSyncDescriptorOpt()
} }
override def processCompactFilters( override def processCompactFilters(

View file

@ -55,7 +55,7 @@ case class WalletStateDescriptorDAO()(implicit
Seq] = Seq] =
findByPrimaryKeys(ts.map(_.tpe)) findByPrimaryKeys(ts.map(_.tpe))
def getSyncHeightOpt(): Future[Option[SyncHeightDescriptor]] = { def getSyncDescriptorOpt(): Future[Option[SyncHeightDescriptor]] = {
read(SyncHeight).map { read(SyncHeight).map {
case Some(db) => case Some(db) =>
val desc = SyncHeightDescriptor.fromString(db.descriptor.toString) val desc = SyncHeightDescriptor.fromString(db.descriptor.toString)
@ -67,7 +67,7 @@ case class WalletStateDescriptorDAO()(implicit
def updateSyncHeight( def updateSyncHeight(
hash: DoubleSha256DigestBE, hash: DoubleSha256DigestBE,
height: Int): Future[WalletStateDescriptorDb] = { height: Int): Future[WalletStateDescriptorDb] = {
getSyncHeightOpt().flatMap { getSyncDescriptorOpt().flatMap {
case Some(old) => case Some(old) =>
if (old.height > height) { if (old.height > height) {
Future.successful(WalletStateDescriptorDb(SyncHeight, old)) Future.successful(WalletStateDescriptorDb(SyncHeight, old))