mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-19 21:45:36 +01:00
Fix all DAOs to use safeDatabase (#2556)
This commit is contained in:
parent
ee7c96245e
commit
c91f81bdbf
7 changed files with 12 additions and 14 deletions
|
@ -223,7 +223,7 @@ case class BlockHeaderDAO()(implicit
|
|||
|
||||
val query = table.filter(_.time === time)
|
||||
|
||||
val opt = database.run(query.result).map(_.headOption)
|
||||
val opt = safeDatabase.run(query.result).map(_.headOption)
|
||||
|
||||
opt.flatMap {
|
||||
case None =>
|
||||
|
@ -249,14 +249,13 @@ case class BlockHeaderDAO()(implicit
|
|||
|
||||
def getLowestNoWorkHeight: Future[Int] = {
|
||||
val query = lowestNoWorkQuery
|
||||
database.run(query)
|
||||
safeDatabase.run(query)
|
||||
}
|
||||
|
||||
/** Returns the maximum block height from our database */
|
||||
def maxHeight: Future[Int] = {
|
||||
val query = maxHeightQuery
|
||||
val result = database.run(query)
|
||||
result
|
||||
safeDatabase.run(query)
|
||||
}
|
||||
|
||||
private val maxHeightQuery: profile.ProfileAction[
|
||||
|
@ -489,7 +488,7 @@ case class BlockHeaderDAO()(implicit
|
|||
headersF.map(headers => Blockchain.fromHeaders(headers.reverse))
|
||||
}
|
||||
|
||||
/** Finds a [[org.bitcoins.chain.models.BlockHeaderDb block header]] that satisfies the given predicate, else returns None */
|
||||
/** Finds a [[org.bitcoins.core.api.chain.db.BlockHeaderDb block header]] that satisfies the given predicate, else returns None */
|
||||
def find(f: BlockHeaderDb => Boolean)(implicit
|
||||
ec: ExecutionContext): Future[Option[BlockHeaderDb]] = {
|
||||
val chainsF = getBlockchains()
|
||||
|
|
|
@ -50,7 +50,7 @@ final case class BroadcastAbleTransactionDAO()(implicit
|
|||
import mappers._
|
||||
|
||||
val query = table.filter(_.txid === hash.flip)
|
||||
database.run(query.result).map(_.headOption)
|
||||
safeDatabase.run(query.result).map(_.headOption)
|
||||
}
|
||||
|
||||
/** Table over TXs we can broadcast over the P2P network */
|
||||
|
|
|
@ -46,7 +46,7 @@ case class AccountDAO()(implicit
|
|||
.filter(_.purpose === account.purpose)
|
||||
.filter(_.index === account.index)
|
||||
|
||||
database.run(q.result).map {
|
||||
safeDatabase.run(q.result).map {
|
||||
case h +: Vector() =>
|
||||
Some(h)
|
||||
case Vector() =>
|
||||
|
|
|
@ -71,7 +71,7 @@ case class AddressDAO()(implicit
|
|||
.headOption
|
||||
} yield (addr, spk)
|
||||
|
||||
database
|
||||
safeDatabase
|
||||
.run(actions.transactionally)
|
||||
.map {
|
||||
case (Some(addr), Some(spk)) => addr.toAddressDb(spk.scriptPubKey)
|
||||
|
|
|
@ -38,8 +38,7 @@ case class ScriptPubKeyDAO()(implicit
|
|||
}
|
||||
} yield spk
|
||||
|
||||
database
|
||||
.run(actions.transactionally)
|
||||
safeDatabase.run(actions.transactionally)
|
||||
}
|
||||
|
||||
case class ScriptPubKeyTable(tag: Tag)
|
||||
|
|
|
@ -235,7 +235,7 @@ case class SpendingInfoDAO()(implicit
|
|||
} yield (utxos, spkDbs)
|
||||
|
||||
for {
|
||||
(utxos, spks) <- database.run(filtered)
|
||||
(utxos, spks) <- safeDatabase.run(filtered)
|
||||
_ = require(
|
||||
utxos.length == outputs.length,
|
||||
s"Was given ${outputs.length} outputs, found ${utxos.length} in DB")
|
||||
|
@ -330,7 +330,7 @@ case class SpendingInfoDAO()(implicit
|
|||
def _findAllUnspent(): Future[Vector[UTXORecord]] = {
|
||||
val query = table.filter(_.state.inSet(TxoState.receivedStates))
|
||||
|
||||
database.run(query.result).map(_.toVector)
|
||||
safeDatabase.run(query.result).map(_.toVector)
|
||||
}
|
||||
|
||||
def utxoToInfo(utxos: Vector[UTXORecord]): Future[Vector[SpendingInfoDb]] =
|
||||
|
|
|
@ -69,7 +69,7 @@ trait TxDAO[DbEntryType <: TxDB]
|
|||
val q = table
|
||||
.filter(_.txIdBE === txIdBE)
|
||||
|
||||
database.run(q.result).map {
|
||||
safeDatabase.run(q.result).map {
|
||||
case h +: Vector() =>
|
||||
Some(h)
|
||||
case Vector() =>
|
||||
|
@ -86,7 +86,7 @@ trait TxDAO[DbEntryType <: TxDB]
|
|||
|
||||
def findByTxIdBEs(
|
||||
txIdBEs: Vector[DoubleSha256DigestBE]): Future[Vector[DbEntryType]] = {
|
||||
database.run(findByPrimaryKeys(txIdBEs).result).map(_.toVector)
|
||||
safeDatabase.run(findByPrimaryKeys(txIdBEs).result).map(_.toVector)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue