You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
852 B

package com.xsn.explorer.services
import javax.inject.Inject
import com.alexitc.playsonify.core.FutureApplicationResult
import com.alexitc.playsonify.core.FutureOr.Implicits.{FutureOps, OrOps}
import com.xsn.explorer.errors.TransactionFormatError
import com.xsn.explorer.models.TransactionId
import org.scalactic.{One, Or}
import play.api.libs.json.JsValue
import scala.concurrent.ExecutionContext
class TransactionService @Inject() (xsnService: XSNService)(implicit ec: ExecutionContext) {
def getTransaction(txidString: String): FutureApplicationResult[JsValue] = {
val result = for {
txid <- {
val maybe = TransactionId.from(txidString)
Or.from(maybe, One(TransactionFormatError)).toFutureOr
}
transaction <- xsnService.getTransaction(txid).toFutureOr
} yield transaction
result.toFuture
}
}