Provide contract choice metadata as constants in contract's class
See original GitHub issueWhat is the problem you want to solve?
The upcoming deprecated exercise by key command currently hard codes the choice name such as:
...
public static ExerciseByKeyCommand exerciseByKeyCreateManager(String key,
CreateManager arg) {
return new ExerciseByKeyCommand(Organization.TEMPLATE_ID, new Party(key), "CreateManager", arg.toValue());
}
..
The choice name is hard coded and cannot be referenced / re-used.
If I create the command manually I would use:
ExerciseCommand(Organization.TEMPLATE_ID, "someContractId", "CreateManager", args)
But again I have to know about the choice name and if the choice name changed in the future, compile time errors would not appear.
What is the solution you would propose?
Could we get the choice names on a contract as constants (or some equivalent) so we can insert them as references?
It would also be helpful to have some contextual information about choices, such as is it a consuming or non-consuming, etc choice, so we can code around expected behaviour: example knowing it is a consuming choice can mean we remove it from the UI on submission (and re-add it if command eventually fails), vs non-consuming we would never remove it. But would settle for just have the constants to start!
Issue Analytics
- State:
- Created a year ago
- Comments:13 (13 by maintainers)
Top GitHub Comments
TypeScript has a sort of counterpart to this
ChoiceMetadata
proposal in theChoice
type.https://github.com/digital-asset/daml/blob/a516be732849880c0d24586ab480c081f6da4472/language-support/ts/daml-types/index.ts#L116-L122
Of note, the
C
andR
tparams can be used to drive argument encoding and result decoding in the way I’ve described forArgType
andResType
above:https://github.com/digital-asset/daml/blob/a516be732849880c0d24586ab480c081f6da4472/language-support/ts/daml-ledger/index.ts#L1104-L1108
With #15116 merged, the example in description can be written as