mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-20 14:03:11 +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 query = table.filter(_.time === time)
|
||||||
|
|
||||||
val opt = database.run(query.result).map(_.headOption)
|
val opt = safeDatabase.run(query.result).map(_.headOption)
|
||||||
|
|
||||||
opt.flatMap {
|
opt.flatMap {
|
||||||
case None =>
|
case None =>
|
||||||
|
@ -249,14 +249,13 @@ case class BlockHeaderDAO()(implicit
|
||||||
|
|
||||||
def getLowestNoWorkHeight: Future[Int] = {
|
def getLowestNoWorkHeight: Future[Int] = {
|
||||||
val query = lowestNoWorkQuery
|
val query = lowestNoWorkQuery
|
||||||
database.run(query)
|
safeDatabase.run(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the maximum block height from our database */
|
/** Returns the maximum block height from our database */
|
||||||
def maxHeight: Future[Int] = {
|
def maxHeight: Future[Int] = {
|
||||||
val query = maxHeightQuery
|
val query = maxHeightQuery
|
||||||
val result = database.run(query)
|
safeDatabase.run(query)
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val maxHeightQuery: profile.ProfileAction[
|
private val maxHeightQuery: profile.ProfileAction[
|
||||||
|
@ -489,7 +488,7 @@ case class BlockHeaderDAO()(implicit
|
||||||
headersF.map(headers => Blockchain.fromHeaders(headers.reverse))
|
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
|
def find(f: BlockHeaderDb => Boolean)(implicit
|
||||||
ec: ExecutionContext): Future[Option[BlockHeaderDb]] = {
|
ec: ExecutionContext): Future[Option[BlockHeaderDb]] = {
|
||||||
val chainsF = getBlockchains()
|
val chainsF = getBlockchains()
|
||||||
|
|
|
@ -50,7 +50,7 @@ final case class BroadcastAbleTransactionDAO()(implicit
|
||||||
import mappers._
|
import mappers._
|
||||||
|
|
||||||
val query = table.filter(_.txid === hash.flip)
|
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 */
|
/** Table over TXs we can broadcast over the P2P network */
|
||||||
|
|
|
@ -46,7 +46,7 @@ case class AccountDAO()(implicit
|
||||||
.filter(_.purpose === account.purpose)
|
.filter(_.purpose === account.purpose)
|
||||||
.filter(_.index === account.index)
|
.filter(_.index === account.index)
|
||||||
|
|
||||||
database.run(q.result).map {
|
safeDatabase.run(q.result).map {
|
||||||
case h +: Vector() =>
|
case h +: Vector() =>
|
||||||
Some(h)
|
Some(h)
|
||||||
case Vector() =>
|
case Vector() =>
|
||||||
|
|
|
@ -71,7 +71,7 @@ case class AddressDAO()(implicit
|
||||||
.headOption
|
.headOption
|
||||||
} yield (addr, spk)
|
} yield (addr, spk)
|
||||||
|
|
||||||
database
|
safeDatabase
|
||||||
.run(actions.transactionally)
|
.run(actions.transactionally)
|
||||||
.map {
|
.map {
|
||||||
case (Some(addr), Some(spk)) => addr.toAddressDb(spk.scriptPubKey)
|
case (Some(addr), Some(spk)) => addr.toAddressDb(spk.scriptPubKey)
|
||||||
|
|
|
@ -38,8 +38,7 @@ case class ScriptPubKeyDAO()(implicit
|
||||||
}
|
}
|
||||||
} yield spk
|
} yield spk
|
||||||
|
|
||||||
database
|
safeDatabase.run(actions.transactionally)
|
||||||
.run(actions.transactionally)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case class ScriptPubKeyTable(tag: Tag)
|
case class ScriptPubKeyTable(tag: Tag)
|
||||||
|
|
|
@ -235,7 +235,7 @@ case class SpendingInfoDAO()(implicit
|
||||||
} yield (utxos, spkDbs)
|
} yield (utxos, spkDbs)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
(utxos, spks) <- database.run(filtered)
|
(utxos, spks) <- safeDatabase.run(filtered)
|
||||||
_ = require(
|
_ = require(
|
||||||
utxos.length == outputs.length,
|
utxos.length == outputs.length,
|
||||||
s"Was given ${outputs.length} outputs, found ${utxos.length} in DB")
|
s"Was given ${outputs.length} outputs, found ${utxos.length} in DB")
|
||||||
|
@ -330,7 +330,7 @@ case class SpendingInfoDAO()(implicit
|
||||||
def _findAllUnspent(): Future[Vector[UTXORecord]] = {
|
def _findAllUnspent(): Future[Vector[UTXORecord]] = {
|
||||||
val query = table.filter(_.state.inSet(TxoState.receivedStates))
|
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]] =
|
def utxoToInfo(utxos: Vector[UTXORecord]): Future[Vector[SpendingInfoDb]] =
|
||||||
|
|
|
@ -69,7 +69,7 @@ trait TxDAO[DbEntryType <: TxDB]
|
||||||
val q = table
|
val q = table
|
||||||
.filter(_.txIdBE === txIdBE)
|
.filter(_.txIdBE === txIdBE)
|
||||||
|
|
||||||
database.run(q.result).map {
|
safeDatabase.run(q.result).map {
|
||||||
case h +: Vector() =>
|
case h +: Vector() =>
|
||||||
Some(h)
|
Some(h)
|
||||||
case Vector() =>
|
case Vector() =>
|
||||||
|
@ -86,7 +86,7 @@ trait TxDAO[DbEntryType <: TxDB]
|
||||||
|
|
||||||
def findByTxIdBEs(
|
def findByTxIdBEs(
|
||||||
txIdBEs: Vector[DoubleSha256DigestBE]): Future[Vector[DbEntryType]] = {
|
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