0

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?

Slaw
  • 37,820
  • 8
  • 53
  • 80
Gaspar
  • 15
  • 3

2 Answers2

0

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.

bame
  • 960
  • 5
  • 7
0

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.

agabor
  • 662
  • 6
  • 7
  • Thanks for the answer! I've tried something like this, but this kind of command keeps throwing me connection timeout exceptions for some reason. – Gaspar Feb 28 '19 at 16:16
  • It might be that your command actually fails. Note that `client.getCommandSubmissionClient().submit(...)` cannot return a failure in all cases, due to the distributed asynchronous nature of command processing. You should rather use `client. getCommandClient(). submitAndWait(...)` which will track the command for you via the `completionStream`. That should give you a definitive answer on whether your command was successful or not. – agabor Mar 01 '19 at 08:14