Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from toknapp/develop
Browse files Browse the repository at this point in the history
Release 0.17.0
  • Loading branch information
allquantor committed Oct 2, 2018
2 parents ba7b476 + 6375b4c commit 410c8b3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Expand Up @@ -80,10 +80,10 @@ lazy val root = (project in file("."))
lazy val library =
new {
object Version {
val circe = "0.10.0-M1"
val circe = "0.10.0"
val scalaCheck = "1.14.0"
val scalaTest = "3.0.5"
val sttp = "1.2.2"
val sttp = "1.3.5"
val spongyCastle = "1.58.0.0"
val kindProjector = "0.9.7"
val logback = "1.2.3"
Expand Down
30 changes: 16 additions & 14 deletions core/src/main/scala/co/upvest/arweave4s/api/package.scala
Expand Up @@ -9,16 +9,17 @@ import cats.instances.future._
import cats.{Id, MonadError, ~>}
import co.upvest.arweave4s.utils.SttpExtensions.{PartialRequest, completeRequest}
import co.upvest.arweave4s.utils.MultipleHostsBackend
import com.softwaremill.sttp.{Response, SttpBackend, Uri}
import com.softwaremill.sttp.{DeserializationError, Response, SttpBackend, Uri}
import io.circe

import scala.concurrent.{ExecutionContext, Future}

package object api {

type JsonHandler[F[_]] = λ[α => F[Response[Either[circe.Error, α]]]] ~> F
type JsonHandler[F[_]] = λ[α => F[SttpResponse]]] ~> F
type EncodedStringHandler[F[_]] = λ[α => F[Response[Option[α]]]] ~> F
type SuccessHandler[F[_]] = F[Response[Unit]] => F[Unit]
type SttpResponse[A] = Response[Either[DeserializationError[circe.Error], A]]

trait Backend[F[_]] {
def apply[T](r: PartialRequest[T, Nothing]): F[Response[T]]
Expand Down Expand Up @@ -60,12 +61,12 @@ package object api {
trait MonadErrorInstances {
implicit def monadErrorJsonHandler[F[_]: MonadError[?[_], T], T](
implicit as: Failure As T
): JsonHandler[F] = new (λ[α => F[Response[Either[circe.Error, α]]]] ~> F) {
override def apply[A](fa: F[Response[Either[circe.Error, A]]]): F[A] =
): JsonHandler[F] = new (λ[α => F[SttpResponse]]] ~> F) {
override def apply[A](fa: F[SttpResponse[A]]): F[A] =
fa >>= { rsp =>
rsp.body match {
case Left(_) => as.coerce(HttpFailure(rsp)).raiseError
case Right(Left(e)) => as.coerce(DecodingFailure(e)).raiseError
case Right(Left(e)) => as.coerce(DecodingFailure(e.error)).raiseError
case Right(Right(a)) => a.pure[F]
}
}
Expand Down Expand Up @@ -100,12 +101,13 @@ package object api {

trait IdInstances {
implicit def idJsonHandler: JsonHandler[Id] =
new (λ[α => Id[Response[Either[circe.Error, α]]]] ~> Id) {
override def apply[A](rsp: Id[Response[Either[circe.Error, A]]]): A = rsp.body match {
case Left(_) => throw HttpFailure(rsp)
case Right(Left(e)) => throw DecodingFailure(e)
case Right(Right(a)) => a
}
new (λ[α => Id[SttpResponse[α]]] ~> Id) {
override def apply[A](rsp: Id[SttpResponse[A]]): A =
rsp.body match {
case Left(_) => throw HttpFailure(rsp)
case Right(Left(e)) => throw DecodingFailure(e.error)
case Right(Right(a)) => a
}
}

implicit def idEncodedStringHandler: EncodedStringHandler[Id] = new (λ[α => Id[Response[Option[α]]]] ~> Id) {
Expand All @@ -126,12 +128,12 @@ package object api {

trait FutureInstances {
implicit def futureJsonHandler(implicit ec:ExecutionContext): JsonHandler[Future] =
new (λ[α => Future[Response[Either[circe.Error, α]]]] ~> Future){
override def apply[A](frsp: Future[Response[Either[circe.Error, A]]])=
new (λ[α => Future[SttpResponse]]] ~> Future){
override def apply[A](frsp: Future[SttpResponse[A]])=
frsp map { rsp =>
rsp.body match {
case Left(_) => throw HttpFailure(rsp)
case Right(Left(e)) => throw DecodingFailure(e)
case Right(Left(e)) => throw DecodingFailure(e.error)
case Right(Right(a)) => a
}}
}
Expand Down
17 changes: 11 additions & 6 deletions core/src/main/scala/co/upvest/arweave4s/api/tx.scala
Expand Up @@ -4,11 +4,12 @@ import cats.Monad
import cats.syntax.applicative._
import cats.syntax.flatMap._
import cats.syntax.functor._
import co.upvest.arweave4s.adt.{Transaction, Signed}
import co.upvest.arweave4s.adt.{Signed, Transaction}
import co.upvest.arweave4s.marshalling.Marshaller
import com.softwaremill.sttp.circe._
import com.softwaremill.sttp.{asString, sttp}
import com.softwaremill.sttp.{DeserializationError, asString, sttp}
import io.circe.parser.decode
import cats.syntax.either._

object tx {
import Marshaller._
Expand All @@ -24,10 +25,14 @@ object tx {
case _ => jh(
Monad[F] pure rsp.copy(
rawErrorBody = rsp.rawErrorBody
.map (
decode[Signed[Transaction]](_)
map Transaction.WithStatus.Accepted.apply
)
.map { body =>
decode[Signed[Transaction]](body)
.leftMap {
DeserializationError(
body, _, "Failure in decoding Signed Transaction"
)
}.map { Transaction.WithStatus.Accepted }
}
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
@@ -1 +1 @@
version in ThisBuild := "0.16.1-SNAPSHOT"
version in ThisBuild := "0.17.0-SNAPSHOT"

0 comments on commit 410c8b3

Please sign in to comment.