-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
two-phase create-and-exercise with unified exercise methods in Java (#…
…14037) * new getCompanion methods generated for contract IDs * document new output for exercise methods * link to #14039 CHANGELOG_BEGIN - [Java codegen] ``createAndExercise*`` and ``exerciseByKey*`` methods are deprecated; instead, use the new ``createAnd().exercise*`` and ``byKey(key).exercise*`` methods. When the ledger API supports it, interface choices will be reachable via ``createAnd().toInterface(Ifc.INTERFACE).exercise*`` and ``byKey(key).toInterface(Ifc.INTERFACE).exercise*``, exactly the syntax supported by contract-ID exercise; see #14056. CHANGELOG_END
- Loading branch information
Showing
17 changed files
with
618 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ByKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.javaapi.data.codegen; | ||
|
||
import com.daml.ledger.javaapi.data.ExerciseByKeyCommand; | ||
import com.daml.ledger.javaapi.data.Value; | ||
|
||
/** Parent of all generated {@code ByKey} classes within templates and interfaces. */ | ||
public abstract class ByKey implements Exercises<ExerciseByKeyCommand> { | ||
protected final Value contractKey; | ||
|
||
protected ByKey(Value contractKey) { | ||
this.contractKey = contractKey; | ||
} | ||
|
||
@Override | ||
public ExerciseByKeyCommand makeExerciseCmd(String choice, Value choiceArgument) { | ||
return new ExerciseByKeyCommand( | ||
getCompanion().TEMPLATE_ID, contractKey, choice, choiceArgument); | ||
} | ||
|
||
/** The origin of the choice, not the template relevant to contractKey. */ | ||
protected abstract ContractTypeCompanion getCompanion(); | ||
|
||
/** | ||
* Parent of all generated {@code ByKey} classes within interfaces. These need to pass both the | ||
* template and interface ID. | ||
*/ | ||
public abstract static class ToInterface extends ByKey { | ||
private final ContractCompanion<?, ?, ?> keySource; | ||
|
||
protected ToInterface(ContractCompanion<?, ?, ?> keySource, Value contractKey) { | ||
super(contractKey); | ||
this.keySource = keySource; | ||
} | ||
|
||
@Override | ||
public ExerciseByKeyCommand makeExerciseCmd(String choice, Value choiceArgument) { | ||
// TODO #14056 use getCompanion().TEMPLATE_ID as the interface ID | ||
return new ExerciseByKeyCommand(keySource.TEMPLATE_ID, contractKey, choice, choiceArgument); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...va/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.javaapi.data.codegen; | ||
|
||
import com.daml.ledger.javaapi.data.Identifier; | ||
|
||
/** The commonality between {@link ContractCompanion} and {@link InterfaceCompanion}. */ | ||
public abstract class ContractTypeCompanion { | ||
/** The full template ID of the template or interface that defined this companion. */ | ||
public final Identifier TEMPLATE_ID; | ||
|
||
protected ContractTypeCompanion(Identifier templateId) { | ||
TEMPLATE_ID = templateId; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...e-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/CreateAnd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.javaapi.data.codegen; | ||
|
||
import com.daml.ledger.javaapi.data.CreateAndExerciseCommand; | ||
import com.daml.ledger.javaapi.data.Template; | ||
import com.daml.ledger.javaapi.data.Value; | ||
|
||
/** Parent of all generated {@code CreateAnd} classes within templates and interfaces. */ | ||
public abstract class CreateAnd implements Exercises<CreateAndExerciseCommand> { | ||
protected final Template createArguments; | ||
|
||
protected CreateAnd(Template createArguments) { | ||
this.createArguments = createArguments; | ||
} | ||
|
||
@Override | ||
public CreateAndExerciseCommand makeExerciseCmd(String choice, Value choiceArgument) { | ||
return new CreateAndExerciseCommand( | ||
getCompanion().TEMPLATE_ID, createArguments.toValue(), choice, choiceArgument); | ||
} | ||
|
||
/** The origin of the choice, not the createArguments. */ | ||
protected abstract ContractTypeCompanion getCompanion(); | ||
|
||
/** | ||
* Parent of all generated {@code CreateAnd} classes within interfaces. These need to pass both | ||
* the template and interface ID. | ||
*/ | ||
public abstract static class ToInterface extends CreateAnd { | ||
private final ContractCompanion<?, ?, ?> createSource; | ||
|
||
protected ToInterface(ContractCompanion<?, ?, ?> createSource, Template createArguments) { | ||
super(createArguments); | ||
this.createSource = createSource; | ||
} | ||
|
||
@Override | ||
public final CreateAndExerciseCommand makeExerciseCmd(String choice, Value choiceArgument) { | ||
// TODO #14056 use getCompanion().TEMPLATE_ID as the interface ID | ||
return new CreateAndExerciseCommand( | ||
createSource.TEMPLATE_ID, createArguments.toValue(), choice, choiceArgument); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...e-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Exercises.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.javaapi.data.codegen; | ||
|
||
import com.daml.ledger.javaapi.data.Value; | ||
|
||
/** | ||
* Root of all generated {@code Exercises} interfaces for templates and Daml interfaces. | ||
* | ||
* @param <Cmd> The returned type of ledger command. | ||
*/ | ||
public interface Exercises<Cmd> { | ||
Cmd makeExerciseCmd(String choice, Value choiceArgument); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.