-
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.
Provide contract choice metadata (#15116)
* #13766 initial implementation of choice metadata for templates * #13766 initial implementation of choice metadata for interfaces * #13766 Add marker type to ContractTypeCompanion * #13766 Minor type fix * Cleanup after merge with main * Temporary fix for package prefixes * Format java files, rename Maker -> ContractType in ContractTypeCompanion * Add documentation and tests * Complete choice metadata implementation CHANGELOG_BEGIN - Add new representation of a choice, ChoiceMetadata. - Generated templates and interfaces now include fields for each available choice. These fields will have a ChoiceMetadata type and will be called CHOICE_N, where N represents the choices' name. CHANGELOG_END * Update docs and cleanup tests
- Loading branch information
Showing
9 changed files
with
232 additions
and
24 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
38 changes: 38 additions & 0 deletions
38
...port/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ChoiceMetadata.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,38 @@ | ||
// 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; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* This represents a Daml choice | ||
* | ||
* @param <Tpl> The generated template class or marker interface for a Daml interface | ||
* @param <ArgType> The choice's argument type | ||
* @param <ResType> The result from exercising the choice | ||
*/ | ||
public final class ChoiceMetadata<Tpl, ArgType, ResType> { | ||
|
||
/** The choice name * */ | ||
public final String name; | ||
|
||
private final Function<ArgType, Value> encodeArg; | ||
|
||
private ChoiceMetadata(final String name, final Function<ArgType, Value> encodeArg) { | ||
this.name = name; | ||
this.encodeArg = encodeArg; | ||
} | ||
|
||
/** | ||
* <strong>INTERNAL API</strong>: this is meant for use by <a | ||
* href="https://docs.daml.com/app-dev/bindings-java/codegen.html">the Java code generator</a>, | ||
* and <em>should not be referenced directly</em>. Applications should refer to the generated | ||
* {@code CHOICE_*} fields on templates or interfaces. | ||
*/ | ||
public static <Tpl, ArgType, ResType> ChoiceMetadata<Tpl, ArgType, ResType> create( | ||
final String name, final Function<ArgType, Value> encodeArg) { | ||
return new ChoiceMetadata<>(name, encodeArg); | ||
} | ||
} |
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
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
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.