diff --git a/server/app/com/xsn/explorer/services/BalanceService.scala b/server/app/com/xsn/explorer/services/BalanceService.scala index c5792ab..33177eb 100644 --- a/server/app/com/xsn/explorer/services/BalanceService.scala +++ b/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)