# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc

from . import command_completion_service_pb2 as com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2


class CommandCompletionServiceStub(object):
  """Allows clients to observe the status of their submissions.
  Commands may be submitted via the Command Submission Service.
  The on-ledger effects of their submissions are disclosed by the Transaction Service.
  Commands may fail in 4 distinct manners:

  1. ``INVALID_PARAMETER`` gRPC error on malformed payloads and missing required fields.
  2. Failure communicated in the gRPC error.
  3. Failure communicated in a Completion.
  4. A Checkpoint with ``record_time`` > command ``mrt`` arrives through the Completion Stream, and the command's Completion was not visible before. In this case the command is lost.

  Clients that do not receive a successful completion about their submission MUST NOT assume that it was successful.
  Clients SHOULD subscribe to the CompletionStream before starting to submit commands to prevent race conditions.

  Interprocess tracing of command submissions may be achieved via Zipkin by filling out the ``trace_context`` field.
  The server will return a child context of the submitted one, (or a new one if the context was missing) on both the Completion and Transaction streams.
  """

  def __init__(self, channel):
    """Constructor.

    Args:
      channel: A grpc.Channel.
    """
    self.CompletionStream = channel.unary_stream(
        '/com.digitalasset.ledger.api.v1.CommandCompletionService/CompletionStream',
        request_serializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionStreamRequest.SerializeToString,
        response_deserializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionStreamResponse.FromString,
        )
    self.CompletionEnd = channel.unary_unary(
        '/com.digitalasset.ledger.api.v1.CommandCompletionService/CompletionEnd',
        request_serializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionEndRequest.SerializeToString,
        response_deserializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionEndResponse.FromString,
        )


class CommandCompletionServiceServicer(object):
  """Allows clients to observe the status of their submissions.
  Commands may be submitted via the Command Submission Service.
  The on-ledger effects of their submissions are disclosed by the Transaction Service.
  Commands may fail in 4 distinct manners:

  1. ``INVALID_PARAMETER`` gRPC error on malformed payloads and missing required fields.
  2. Failure communicated in the gRPC error.
  3. Failure communicated in a Completion.
  4. A Checkpoint with ``record_time`` > command ``mrt`` arrives through the Completion Stream, and the command's Completion was not visible before. In this case the command is lost.

  Clients that do not receive a successful completion about their submission MUST NOT assume that it was successful.
  Clients SHOULD subscribe to the CompletionStream before starting to submit commands to prevent race conditions.

  Interprocess tracing of command submissions may be achieved via Zipkin by filling out the ``trace_context`` field.
  The server will return a child context of the submitted one, (or a new one if the context was missing) on both the Completion and Transaction streams.
  """

  def CompletionStream(self, request, context):
    """Subscribe to command completion events.
    """
    context.set_code(grpc.StatusCode.UNIMPLEMENTED)
    context.set_details('Method not implemented!')
    raise NotImplementedError('Method not implemented!')

  def CompletionEnd(self, request, context):
    """Returns the offset after the latest completion.
    """
    context.set_code(grpc.StatusCode.UNIMPLEMENTED)
    context.set_details('Method not implemented!')
    raise NotImplementedError('Method not implemented!')


def add_CommandCompletionServiceServicer_to_server(servicer, server):
  rpc_method_handlers = {
      'CompletionStream': grpc.unary_stream_rpc_method_handler(
          servicer.CompletionStream,
          request_deserializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionStreamRequest.FromString,
          response_serializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionStreamResponse.SerializeToString,
      ),
      'CompletionEnd': grpc.unary_unary_rpc_method_handler(
          servicer.CompletionEnd,
          request_deserializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionEndRequest.FromString,
          response_serializer=com_dot_digitalasset_dot_ledger_dot_api_dot_v1_dot_command__completion__service__pb2.CompletionEndResponse.SerializeToString,
      ),
  }
  generic_handler = grpc.method_handlers_generic_handler(
      'com.digitalasset.ledger.api.v1.CommandCompletionService', rpc_method_handlers)
  server.add_generic_rpc_handlers((generic_handler,))
