Alexis Hernandez
6 years ago
5 changed files with 59 additions and 1 deletions
@ -0,0 +1,25 @@ |
|||
package com.xsn.explorer.services |
|||
|
|||
import com.alexitc.playsonify.core.FutureApplicationResult |
|||
import com.alexitc.playsonify.core.FutureOr.Implicits.{FutureOps, OrOps} |
|||
import com.xsn.explorer.data.async.TPoSContractFutureDataHandler |
|||
import com.xsn.explorer.models.{TPoSContract, WrappedResult} |
|||
import com.xsn.explorer.services.validators.AddressValidator |
|||
import javax.inject.Inject |
|||
|
|||
import scala.concurrent.ExecutionContext |
|||
|
|||
class TPoSContractService @Inject() ( |
|||
addressValidator: AddressValidator, |
|||
tposContractFutureDataHandler: TPoSContractFutureDataHandler)( |
|||
implicit ec: ExecutionContext) { |
|||
|
|||
def getBy(addressString: String): FutureApplicationResult[WrappedResult[List[TPoSContract]]] = { |
|||
val result = for { |
|||
address <- addressValidator.validate(addressString).toFutureOr |
|||
contracts <- tposContractFutureDataHandler.getBy(address).toFutureOr |
|||
} yield WrappedResult(contracts) |
|||
|
|||
result.toFuture |
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.xsn.explorer.services.validators |
|||
|
|||
import com.alexitc.playsonify.core.ApplicationResult |
|||
import com.xsn.explorer.errors.AddressFormatError |
|||
import com.xsn.explorer.models.values.Address |
|||
import org.scalactic.{One, Or} |
|||
|
|||
class AddressValidator { |
|||
|
|||
def validate(string: String): ApplicationResult[Address] = { |
|||
val maybe = Address.from(string) |
|||
Or.from(maybe, One(AddressFormatError)) |
|||
} |
|||
} |
Loading…
Reference in new issue