mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 09:52:09 +01:00
Fix max by for getBlockCount (#1951)
* Fix max by for getBlockCount * Add helper func to package
This commit is contained in:
parent
cc2a118ff0
commit
1670902e75
@ -260,7 +260,9 @@ case class BlockHeaderDAO()(implicit
|
||||
|
||||
/** Returns the block height of the block with the most work from our database */
|
||||
def bestHeight: Future[Int] = {
|
||||
chainTips.map(_.maxBy(_.chainWork).height)
|
||||
chainTips.map { tips =>
|
||||
tips.maxByOption(_.chainWork).map(_.height).getOrElse(0)
|
||||
}
|
||||
}
|
||||
|
||||
private val maxWorkQuery: profile.ProfileAction[
|
||||
|
@ -8,9 +8,29 @@ import org.bitcoins.core.wallet.fee.SatoshisPerKiloByte
|
||||
import scodec.bits._
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.math.Ordering
|
||||
|
||||
package object core {
|
||||
|
||||
implicit class seqUtil[T](private val seq: Seq[T]) extends AnyVal {
|
||||
|
||||
def maxByOption[B](f: T => B)(implicit cmp: Ordering[B]): Option[T] = {
|
||||
if (seq.isEmpty) {
|
||||
None
|
||||
} else {
|
||||
Some(seq.maxBy(f))
|
||||
}
|
||||
}
|
||||
|
||||
def minByOption[B](f: T => B)(implicit cmp: Ordering[B]): Option[T] = {
|
||||
if (seq.isEmpty) {
|
||||
None
|
||||
} else {
|
||||
Some(seq.minBy(f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
implicit val satoshisPerKiloByteOrdering: Ordering[SatoshisPerKiloByte] =
|
||||
new Ordering[SatoshisPerKiloByte] {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user