Creating a party on the Ledger via Java API
- liavOP
Hi,
Is anyone familiar with a Java API designed to create a party on the Ledger (either via gRPC or JSON API)?
Tried looking for it in the docs and the closest thing i could find is this but it looks like the user management section allows only partial provisioning and not the actual party creation
Thanks
- cocreature
It’s not exposed via the high-level APIs at the moment but you can access it directly. You can find an example in Java Bindings do not have all Ledger API services - #4 by bernhard
- cohen.avraham 1
G-d willing
How about this discussion… is it helpful?
- liav
Thank @cocreature ,
I tried running Bernhard code but failed on query the Ledger for existing party:
// query the ledger for parties PartyManagementServiceOuterClass.ListKnownPartiesResponse parties = pms.listKnownParties(PartyManagementServiceOuterClass.ListKnownPartiesRequest.newBuilder().build());I got this Exception - do you understand it?
Caused by: io.grpc.StatusRuntimeException: INTERNAL: http2 exception at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262) ~[grpc-stub-1.44.0.jar:1.44.0] at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243) ~[grpc-stub-1.44.0.jar:1.44.0] at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156) ~[grpc-stub-1.44.0.jar:1.44.0] at com.daml.ledger.api.v1.admin.PartyManagementServiceGrpc$PartyManagementServiceBlockingStub.listKnownParties(PartyManagementServiceGrpc.java:474) ~[bindings-java-2.0.0.jar:na] at com.sorintegrations.customerpolicyrequest.CustomerPolicyClient.allocateParty(CustomerPolicyClient.java:136) ~[classes/:na] at com.sorintegrations.customerpolicyrequest.CustomerPolicyClient.sendCustomerPolicyRequest(CustomerPolicyClient.java:84) ~[classes/:na] at com.sorintegrations.customerpolicyrequest.CustomerPolicyRequestApplication.run(CustomerPolicyRequestApplication.java:28) ~[classes/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:777) ~[spring-boot-2.6.4.jar:2.6.4] ... 10 common frames omitted Caused by: io.netty.handler.codec.http2.Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 1503010002 at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:108) ~[netty-codec-http2-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.verifyFirstFrameIsSettings(Http2ConnectionHandler.java:338) ~[netty-codec-http2-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:239) ~[netty-codec-http2-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:438) ~[netty-codec-http2-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:510) ~[netty-codec-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:449) ~[netty-codec-4.1.74.Final.jar:4.1.74.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279) ~[netty-codec-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) ~[netty-transport-4.1.74.Final.jar:4.1.74.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) ~[netty-common-4.1.74.Final.jar:4.1.74.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.74.Final.jar:4.1.74.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.74.Final.jar:4.1.74.Final] at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na] - cocreature
I’m somewhat guessing here but that looks like you might be trying to initiate a TLS connection against a non-TLS ledger or the other way around.
- liav
mmmm… I believe you’re right. I have changed the channel fetch to be TLS supported as below but fails on other thing (during the listKnownParties command)
Channel channel = null; try { channel = NettyChannelBuilder .forAddress(host, port) .sslContext(GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build()) .build(); } catch (SSLException e) { e.printStackTrace(); } PartyManagementServiceGrpc.PartyManagementServiceBlockingStub pms = PartyManagementServiceGrpc.newBlockingStub(channel); // query the ledger for parties PartyManagementServiceOuterClass.ListKnownPartiesResponse parties = pms.listKnownParties(PartyManagementServiceOuterClass.ListKnownPartiesRequest.newBuilder().build());Failure:
Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262) ~[grpc-stub-1.44.0.jar:1.44.0] at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243) ~[grpc-stub-1.44.0.jar:1.44.0] at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156) ~[grpc-stub-1.44.0.jar:1.44.0] at com.daml.ledger.api.v1.admin.PartyManagementServiceGrpc$PartyManagementServiceBlockingStub.listKnownParties(PartyManagementServiceGrpc.java:474) ~[bindings-java-2.0.0.jar:na] at com.sorintegrations.customerpolicyrequest.CustomerPolicyClient.allocateParty(CustomerPolicyClient.java:149) ~[classes/:na] at com.sorintegrations.customerpolicyrequest.CustomerPolicyClient.sendCustomerPolicyRequest(CustomerPolicyClient.java:86) ~[classes/:na] at com.sorintegrations.customerpolicyrequest.CustomerPolicyRequestApplication.run(CustomerPolicyRequestApplication.java:28) ~[classes/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:777) ~[spring-boot-2.6.4.jar:2.6.4] ... 10 common frames omitted - cocreature
Sounds like maybe the host and/or port are off.
- liav
But then (in case host/port are wrong) it would have failed performing the connection.
What do you mean by saying “off”?
- cocreature
You can sometimes get UNAVAILABLE if you connect to something but there is no gRPC ledger API behind it.
- liav
The Ledger is reachable since i’m successfully managing to connect to it before trying to create a party.
My Ledger connection code is:
DamlLedgerClient client = DamlLedgerClient.newBuilder(damlProperties.getHostIp(), damlProperties.getHostPort()) .withSslContext(GrpcSslContexts.forClient().build()) .withAccessToken(damlProperties.getListenerAccessToken()) .build(); client.connect();My Party creation code is:
Channel channel = null; try { channel = NettyChannelBuilder .forAddress(host, port) .negotiationType(NegotiationType.TLS) .sslContext(GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build()) .build(); } catch (SSLException e) { e.printStackTrace(); } PartyManagementServiceGrpc.PartyManagementServiceBlockingStub pms = PartyManagementServiceGrpc.newBlockingStub(channel); // query the ledger for parties PartyManagementServiceOuterClass.ListKnownPartiesResponse parties = pms.listKnownParties(PartyManagementServiceOuterClass.ListKnownPartiesRequest.newBuilder().build());The last command (ListKnownPartiesRequest) fails on io.grpc.StatusRuntimeException: UNAVAILABLE
Maybe my Channel fetching code is missing something?
- dtanabe 1
If you are trying to do this against Daml Hub, unfortunately the admin endpoints are not publicly available because we don’t grant admin tokens to users. It’s on our roadmap to improve this situation; we definitely understand this is a pain point!