Browse Source

server: Use the AddressValidator on the BalanceService

bitcoin
Alexis Hernandez 6 years ago
parent
commit
0373dff0fe
  1. 17
      server/app/com/xsn/explorer/services/BalanceService.scala

17
server/app/com/xsn/explorer/services/BalanceService.scala

@ -6,19 +6,19 @@ import com.alexitc.playsonify.models.ordering.OrderingQuery
import com.alexitc.playsonify.models.pagination.{Limit, Offset, PaginatedQuery}
import com.alexitc.playsonify.validators.PaginatedQueryValidator
import com.xsn.explorer.data.async.BalanceFutureDataHandler
import com.xsn.explorer.errors.AddressFormatError
import com.xsn.explorer.models.WrappedResult
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values._
import com.xsn.explorer.parsers.BalanceOrderingParser
import com.xsn.explorer.services.validators.AddressValidator
import javax.inject.Inject
import org.scalactic.{Good, One, Or}
import org.scalactic.Good
import scala.concurrent.ExecutionContext
class BalanceService @Inject() (
paginatedQueryValidator: PaginatedQueryValidator,
balanceOrderingParser: BalanceOrderingParser,
addressValidator: AddressValidator,
balanceFutureDataHandler: BalanceFutureDataHandler)(
implicit ec: ExecutionContext) {
@ -36,13 +36,10 @@ class BalanceService @Inject() (
val result = for {
_ <- paginatedQueryValidator.validate(PaginatedQuery(Offset(0), limit), 100).toFutureOr
lastSeenAddress <- {
lastSeenAddressString
.map(Address.from)
.map { txid => Or.from(txid, One(AddressFormatError)).map(Option.apply) }
.getOrElse(Good(Option.empty))
.toFutureOr
}
lastSeenAddress <- lastSeenAddressString
.map { string => addressValidator.validate(string).map(Option.apply) }
.getOrElse(Good(None))
.toFutureOr
data <- balanceFutureDataHandler.getHighestBalances(limit, lastSeenAddress).toFutureOr
} yield WrappedResult(data)

Loading…
Cancel
Save