Skip to content
CCPEDIAby Unity Nodes
App Development

How to create the command object for grpc SubmitRequest in command_submission_service

3 posts153 views1 likesLast activity Dec 2022

  1. Ashok_RajOP

    I want to send the following CreateCommand using python gRPC using command_submission_service. I have imported commands_pb2 How do i define this command…

    message CreateCommand {
      // The template of contract the client wants to create.
      // Required
      Identifier template_id = 1;
    
      // The arguments required for creating a contract from this template.
      // Required
      Record create_arguments = 2;
    }
    

    here is the code am currently using

    with grpc.insecure_channel('localhost:6865') as channel:
            stub=command_submission_service_pb2_grpc.CommandSubmissionServiceStub(channel)
            response=stub.Submit(command_submission_service_pb2.SubmitRequest(test_command))
    

    basically want to know how to construct test_command. If you have some eg. That would be great

  2. cocreature

    You are broadly looking at something like this:

    def run():
        with grpc.insecure_channel('localhost:6865') as channel:
            stub=command_submission_service_pb2_grpc.runSubmissionServiceStub(channel)
            commands=command_submission_service_pb2.Commands()
    
            commands.application_id="your_daml_user_id"
            commands.command_id=str(uuid.uuid4())
            commands.actAs=["yourpartyid"]
    
            create_command=command_submission_service_pb2.CreateCommand()
            template_id=command_submission_service_pb2.Identifier()
            template_id.package_id="yourpackageid"
            template_id.module_name="yourmodulename"
            template_id.entity_name="yourtemplatename"
    
            create_command.template_id=template_id
            payload=command_submission_service_pb2.Record()
            example_field=command_submission_service_pb2.RecordField()
            party_value=command_submission_service_pb2.Value()
            party_value.party="yourpartyid"
            example_field.value =party_value
            payload.fields=[example_field]
            create_command.create_arguments=payload
    
            commands.commands=[create_command]
    
            request=command_submission_service_pb2.SubmitRequest()
            request.commands=commands
            response=stub.Submit(command_submission_service_pb2.SubmitRequest())
            print(response)
    

    I don’t have a python environment ready to validate that though.
    I recommend to look at the following pieces of documentation:

    1. The protobuf docs on how protobuf is translated to python Python Generated Code  |  Protocol Buffers  |  Google Developers
    2. The high-level overview of command submission in the ledger API docs The Ledger API Services — Daml SDK 2.4.0 documentation
    3. The protobuf docs for the command service Ledger API Reference — Daml SDK 2.4.0 documentation

    That said, depending on your usecase dazl may be a significantly easier option to access the grpc API from python.

  3. Ianw1 1

    FWIW I found it quite useful to turn on payload logging, as described in Monitoring — Daml SDK 2.4.2 documentation, when working with gRPC. You can then compare a request that works (say from Navigator) with yours and get an idea of what you need to fix.