Is there a way to automatically return the contractId
generated by a command like:
client.getCommandSubmissionClient().submit(...).blockingGet();
If not, what's the best way to do it?
There is no inbuilt synchronous API call that returns the resulting transaction of a (successful) command submission. The command service only returns the command completion (ie success/fail).
One way to do what you want is to use the commandId
field. It allows the submitting party to correlate the command submission and resulting transaction. You would, however, have to build a wrapper combining the command and transaction services yourself.
a simple way for finding the transaction you are looking for would be something like this:
client.getTransactionsClient()
.getTransactions(LedgerOffset.LedgerBegin.getInstance(), new FiltersByParty(Collections.singletonMap(party, NoFilter.instance)), false)
.filter(t => "MyCommandId".equals(t.getCommandId))
.singleOrError()
.blockingGet()
Note that here we are reading from LedgerBegin
. Normally you would ask for the ledger end via client.getTransactionsClient().getLedgerEnd()
before submitting the command and use the that offset for subscribing to transactions.