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

walletrpc.WalletKitHandler.scala Maven / Gradle / Ivy

The newest version!

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

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 WalletKitHandler {
    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 `WalletKitHandler.partial` when combining
     * several services.
     */
    def apply(implementation: WalletKit)(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 `WalletKitHandler.partial` when combining
     * several services.
     */
    def apply(implementation: WalletKit, eHandler: ActorSystem => PartialFunction[Throwable, Trailers])(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, WalletKit.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 `WalletKitHandler.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: WalletKit, 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 `WalletKitHandler.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: WalletKit, 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
     * `WalletKit` and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `WalletKitHandler.partial` when combining
     * several services.
     */
    def withServerReflection(implementation: WalletKit)(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
        pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound(
          WalletKitHandler.partial(implementation),
          pekko.grpc.scaladsl.ServerReflection.partial(List(WalletKit)))


    /**
     * 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 `WalletKitHandler.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: WalletKit, prefix: String = WalletKit.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 WalletKit.Serializers._

      def handle(request: model.HttpRequest, method: String): scala.concurrent.Future[model.HttpResponse] =
        GrpcMarshalling.negotiated(request, (reader, writer) =>
          (method match {
            
            case "ListUnspent" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ListUnspentRequestSerializer, mat, reader)
                  .flatMap(implementation.listUnspent(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ListUnspentResponseSerializer, writer, system))
            
            case "LeaseOutput" =>
                
                GrpcMarshalling.unmarshal(request.entity)(LeaseOutputRequestSerializer, mat, reader)
                  .flatMap(implementation.leaseOutput(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(LeaseOutputResponseSerializer, writer, system))
            
            case "ReleaseOutput" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ReleaseOutputRequestSerializer, mat, reader)
                  .flatMap(implementation.releaseOutput(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ReleaseOutputResponseSerializer, writer, system))
            
            case "ListLeases" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ListLeasesRequestSerializer, mat, reader)
                  .flatMap(implementation.listLeases(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ListLeasesResponseSerializer, writer, system))
            
            case "DeriveNextKey" =>
                
                GrpcMarshalling.unmarshal(request.entity)(KeyReqSerializer, mat, reader)
                  .flatMap(implementation.deriveNextKey(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(signrpc_KeyDescriptorSerializer, writer, system))
            
            case "DeriveKey" =>
                
                GrpcMarshalling.unmarshal(request.entity)(signrpc_KeyLocatorSerializer, mat, reader)
                  .flatMap(implementation.deriveKey(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(signrpc_KeyDescriptorSerializer, writer, system))
            
            case "NextAddr" =>
                
                GrpcMarshalling.unmarshal(request.entity)(AddrRequestSerializer, mat, reader)
                  .flatMap(implementation.nextAddr(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(AddrResponseSerializer, writer, system))
            
            case "ListAccounts" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ListAccountsRequestSerializer, mat, reader)
                  .flatMap(implementation.listAccounts(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ListAccountsResponseSerializer, writer, system))
            
            case "RequiredReserve" =>
                
                GrpcMarshalling.unmarshal(request.entity)(RequiredReserveRequestSerializer, mat, reader)
                  .flatMap(implementation.requiredReserve(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(RequiredReserveResponseSerializer, writer, system))
            
            case "ListAddresses" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ListAddressesRequestSerializer, mat, reader)
                  .flatMap(implementation.listAddresses(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ListAddressesResponseSerializer, writer, system))
            
            case "SignMessageWithAddr" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SignMessageWithAddrRequestSerializer, mat, reader)
                  .flatMap(implementation.signMessageWithAddr(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(SignMessageWithAddrResponseSerializer, writer, system))
            
            case "VerifyMessageWithAddr" =>
                
                GrpcMarshalling.unmarshal(request.entity)(VerifyMessageWithAddrRequestSerializer, mat, reader)
                  .flatMap(implementation.verifyMessageWithAddr(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(VerifyMessageWithAddrResponseSerializer, writer, system))
            
            case "ImportAccount" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ImportAccountRequestSerializer, mat, reader)
                  .flatMap(implementation.importAccount(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ImportAccountResponseSerializer, writer, system))
            
            case "ImportPublicKey" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ImportPublicKeyRequestSerializer, mat, reader)
                  .flatMap(implementation.importPublicKey(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ImportPublicKeyResponseSerializer, writer, system))
            
            case "ImportTapscript" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ImportTapscriptRequestSerializer, mat, reader)
                  .flatMap(implementation.importTapscript(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ImportTapscriptResponseSerializer, writer, system))
            
            case "PublishTransaction" =>
                
                GrpcMarshalling.unmarshal(request.entity)(TransactionSerializer, mat, reader)
                  .flatMap(implementation.publishTransaction(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(PublishResponseSerializer, writer, system))
            
            case "SendOutputs" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SendOutputsRequestSerializer, mat, reader)
                  .flatMap(implementation.sendOutputs(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(SendOutputsResponseSerializer, writer, system))
            
            case "EstimateFee" =>
                
                GrpcMarshalling.unmarshal(request.entity)(EstimateFeeRequestSerializer, mat, reader)
                  .flatMap(implementation.estimateFee(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(EstimateFeeResponseSerializer, writer, system))
            
            case "PendingSweeps" =>
                
                GrpcMarshalling.unmarshal(request.entity)(PendingSweepsRequestSerializer, mat, reader)
                  .flatMap(implementation.pendingSweeps(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(PendingSweepsResponseSerializer, writer, system))
            
            case "BumpFee" =>
                
                GrpcMarshalling.unmarshal(request.entity)(BumpFeeRequestSerializer, mat, reader)
                  .flatMap(implementation.bumpFee(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(BumpFeeResponseSerializer, writer, system))
            
            case "ListSweeps" =>
                
                GrpcMarshalling.unmarshal(request.entity)(ListSweepsRequestSerializer, mat, reader)
                  .flatMap(implementation.listSweeps(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(ListSweepsResponseSerializer, writer, system))
            
            case "LabelTransaction" =>
                
                GrpcMarshalling.unmarshal(request.entity)(LabelTransactionRequestSerializer, mat, reader)
                  .flatMap(implementation.labelTransaction(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(LabelTransactionResponseSerializer, writer, system))
            
            case "FundPsbt" =>
                
                GrpcMarshalling.unmarshal(request.entity)(FundPsbtRequestSerializer, mat, reader)
                  .flatMap(implementation.fundPsbt(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(FundPsbtResponseSerializer, writer, system))
            
            case "SignPsbt" =>
                
                GrpcMarshalling.unmarshal(request.entity)(SignPsbtRequestSerializer, mat, reader)
                  .flatMap(implementation.signPsbt(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(SignPsbtResponseSerializer, writer, system))
            
            case "FinalizePsbt" =>
                
                GrpcMarshalling.unmarshal(request.entity)(FinalizePsbtRequestSerializer, mat, reader)
                  .flatMap(implementation.finalizePsbt(_))
                  .map(e => GrpcMarshalling.marshal(e, eHandler)(FinalizePsbtResponseSerializer, 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