Java Bindings do not have all Ledger API services

The bindings-rxjava package on Maven Central seems to be missing a few of the services available on the Ledger API, in particular:

It’s possible to use the grpc equivalents to these, but then we end up with a mixture of bindings-rxjava and grpc, which increases the maintenance load.

Will bindings-rxjava come in sync with Ledger API services?

2 Likes

The future of the RxJava Bindings for the ledger is currently under discussion. @Darko, could you shed some light on this maybe?

2 Likes

Thanks for pinging @gerolf

We are currently in the middle of an analysis about the usage and requirements of the language bindings. I am expecting that that bindings-rxjava will be updated to support the missing services. Until then it should be very easy to use the java bindings (without the streaming layer) to do the management tasks that you need.

@bernhard has created an example showing what needs to be done.

1 Like

Here it is. The only important parts here are

  • 41-42 to get the service
  • 45 to query parties
  • 57-61 to allocate a party
import com.daml.ledger.api.v1.admin.PartyManagementServiceGrpc;
import com.daml.ledger.api.v1.admin.PartyManagementServiceGrpc.PartyManagementServiceBlockingStub;
import com.daml.ledger.api.v1.admin.PartyManagementServiceOuterClass.AllocatePartyRequest;
import com.daml.ledger.api.v1.admin.PartyManagementServiceOuterClass.AllocatePartyResponse;
import com.daml.ledger.api.v1.admin.PartyManagementServiceOuterClass.ListKnownPartiesRequest;
import com.daml.ledger.api.v1.admin.PartyManagementServiceOuterClass.ListKnownPartiesResponse;
import com.daml.ledger.api.v1.admin.PartyManagementServiceOuterClass.PartyDetails;
import com.google.gson.Gson;

import io.grpc.Channel;
import io.grpc.ManagedChannelBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;

public class PartyManagementMain {

    private final static Logger logger = LoggerFactory.getLogger(PartyManagementMain.class);

    // application id used for sending commands
    public static final String APP_ID = "PartyManagementApp";

    public static void main(String[] args) {
        // Extract host and port from arguments
        if (args.length < 3) {
            System.err.println("Usage: HOST PORT PARTY");
            System.exit(-1);
        }
        String host = args[0];
        int port = Integer.parseInt(args[1]);
        String party = args[2];

        // create a stub for the PackageManagementService
        Channel channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();
        PartyManagementServiceBlockingStub pms = PartyManagementServiceGrpc.newBlockingStub(channel);

        // query the ledger for parties
        ListKnownPartiesResponse parties = pms.listKnownParties(ListKnownPartiesRequest.newBuilder().build());

        // check whether party exists
        Optional<PartyDetails> partyDetails = parties.getPartyDetailsList().stream()
            .filter(p -> p.getParty().equals(party))
            .findAny();

        // create party if needed and log the result
        Gson gson = new Gson();
        if(partyDetails.isPresent()) {
            logger.info("Party found: " + gson.toJson(partyDetails.get()));
        } else {
            AllocatePartyResponse allocateResponse = pms.allocateParty(
                AllocatePartyRequest.newBuilder()
                    .setDisplayName(party)
                    .setPartyIdHint(party)
                    .build());
            logger.info("New party allocated: " + gson.toJson(allocateResponse.getPartyDetails()));

        }
    }
}
3 Likes