All Downloads are FREE. Search and download functionalities are using the official Maven repository.

signrpc.SignerHandler.scala Maven / Gradle / Ivy

The newest version!

// Generated by Pekko gRPC. DO NOT EDIT.
package signrpc

import scala.concurrent.ExecutionContext

import org.apache.pekko
import pekko.grpc.scaladsl.{ GrpcExceptionHandler, GrpcMarshalling }
import pekko.grpc.Trailers

import pekko.actor.ActorSystem
import pekko.actor.ClassicActorSystemProvider
import pekko.annotation.ApiMayChange
import pekko.http.scaladsl.model
import pekko.stream.{Materializer, SystemMaterializer}

import pekko.grpc.internal.TelemetryExtension

import pekko.grpc.PekkoGrpcGenerated




/*
 * Generated by Pekko gRPC. DO NOT EDIT.
 *
 * The API of this class may still change in future Pekko gRPC versions, see for instance
 * https://github.com/akka/akka-grpc/issues/994
 */
@ApiMayChange
@PekkoGrpcGenerated
object SignerHandler {
    private val notFound = scala.concurrent.Future.successful(model.HttpResponse(model.StatusCodes.NotFound))
    private val unsupportedMediaType = scala.concurrent.Future.successful(model.HttpResponse(model.StatusCodes.UnsupportedMediaType))

    /**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `SignerHandler.partial` when combining
     * several services.
     */
    def apply(implementation: Signer)(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation).orElse { case _ => notFound }

    /**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `SignerHandler.partial` when combining
     * several services.
     */
    def apply(implementation: Signer, eHandler: ActorSystem => PartialFunction[Throwable, Trailers])(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, Signer.name, eHandler).orElse { case _ => notFound }

    /**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `SignerHandler.partial` when combining
     * several services.
     *
     * Registering a gRPC service under a custom prefix is not widely supported and strongly discouraged by the specification.
     */
    def apply(implementation: Signer, prefix: String)(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, prefix).orElse { case _ => notFound }

    /**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `SignerHandler.partial` when combining
     * several services.
     *
     * Registering a gRPC service under a custom prefix is not widely supported and strongly discouraged by the specification.
     */
    def apply(implementation: Signer, prefix: String, eHandler: ActorSystem => PartialFunction[Throwable, Trailers])(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, prefix, eHandler).orElse { case _ => notFound }



    /**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler. The generated handler falls back to a reflection handler for
     * `Signer` and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `SignerHandler.partial` when combining
     * several services.
     */
    def withServerReflection(implementation: Signer)(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
        pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound(
          SignerHandler.partial(implementation),
          pekko.grpc.scaladsl.ServerReflection.partial(List(Signer)))


    /**
     * Creates a partial `HttpRequest` to `HttpResponse` handler that can be combined with handlers of other
     * services with `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` and then used in for example
     * `Http().bindAndHandleAsync`.
     *
     * Use `SignerHandler.apply` if the server is only handling one service.
     *
     * Registering a gRPC service under a custom prefix is not widely supported and strongly discouraged by the specification.
     */
    def partial(implementation: Signer, prefix: String = Signer.name, eHandler: ActorSystem => PartialFunction[Throwable, Trailers] = GrpcExceptionHandler.defaultMapper)(implicit system: ClassicActorSystemProvider): PartialFunction[model.HttpRequest, scala.concurrent.Future[model.HttpResponse]] = {
      implicit val mat: Materializer = SystemMaterializer(system).materializer
      implicit val ec: ExecutionContext = mat.executionContext
      val spi = TelemetryExtension(system).spi

      import Signer.Serializers._

      def handle(request: model.HttpRequest, method: String): scala.concurrent.Future[model.HttpResponse] =
        GrpcMarshalling.negotiated(request, (reader, writer) =>
          (method match {
            
            case "SignOutputRaw" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SignReqSerializer, mat, reader)
                  .flatMap(implementation.signOutputRaw(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(SignRespSerializer, writer, system))
            
            case "ComputeInputScript" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SignReqSerializer, mat, reader)
                  .flatMap(implementation.computeInputScript(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(InputScriptRespSerializer, writer, system))
            
            case "SignMessage" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SignMessageReqSerializer, mat, reader)
                  .flatMap(implementation.signMessage(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(SignMessageRespSerializer, writer, system))
            
            case "VerifyMessage" =>
                
                GrpcMarshalling.unmarshal(request.entity)(VerifyMessageReqSerializer, mat, reader)
                  .flatMap(implementation.verifyMessage(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(VerifyMessageRespSerializer, writer, system))
            
            case "DeriveSharedKey" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SharedKeyRequestSerializer, mat, reader)
                  .flatMap(implementation.deriveSharedKey(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(SharedKeyResponseSerializer, writer, system))
            
            case "MuSig2CombineKeys" =>
                
                GrpcMarshalling.unmarshal(request.entity)(MuSig2CombineKeysRequestSerializer, mat, reader)
                  .flatMap(implementation.muSig2CombineKeys(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(MuSig2CombineKeysResponseSerializer, writer, system))
            
            case "MuSig2CreateSession" =>
                
                GrpcMarshalling.unmarshal(request.entity)(MuSig2SessionRequestSerializer, mat, reader)
                  .flatMap(implementation.muSig2CreateSession(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(MuSig2SessionResponseSerializer, writer, system))
            
            case "MuSig2RegisterNonces" =>
                
                GrpcMarshalling.unmarshal(request.entity)(MuSig2RegisterNoncesRequestSerializer, mat, reader)
                  .flatMap(implementation.muSig2RegisterNonces(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(MuSig2RegisterNoncesResponseSerializer, writer, system))
            
            case "MuSig2Sign" =>
                
                GrpcMarshalling.unmarshal(request.entity)(MuSig2SignRequestSerializer, mat, reader)
                  .flatMap(implementation.muSig2Sign(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(MuSig2SignResponseSerializer, writer, system))
            
            case "MuSig2CombineSig" =>
                
                GrpcMarshalling.unmarshal(request.entity)(MuSig2CombineSigRequestSerializer, mat, reader)
                  .flatMap(implementation.muSig2CombineSig(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(MuSig2CombineSigResponseSerializer, writer, system))
            
            case "MuSig2Cleanup" =>
                
                GrpcMarshalling.unmarshal(request.entity)(MuSig2CleanupRequestSerializer, mat, reader)
                  .flatMap(implementation.muSig2Cleanup(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(MuSig2CleanupResponseSerializer, writer, system))
            
            case m => scala.concurrent.Future.failed(new NotImplementedError(s"Not implemented: $m"))
          })
          .recoverWith(GrpcExceptionHandler.from(eHandler(system.classicSystem))(system, writer))
      ).getOrElse(unsupportedMediaType)

      Function.unlift((req: model.HttpRequest) => req.uri.path match {
        case model.Uri.Path.Slash(model.Uri.Path.Segment(`prefix`, model.Uri.Path.Slash(model.Uri.Path.Segment(method, model.Uri.Path.Empty)))) =>
          Some(handle(spi.onRequest(prefix, method, req), method))
        case _ =>
          None
      })
    }
  }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy