-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide contract choice metadata as constants in contract's class #14329
Comments
I'm not sure I'm following what you want to achieve here. The point of the generated classes is not that of returning something you can re-use separately, but rather to fit with a Daml model that exists. What you're proposing seems to be something in which you want to create code to then manually assemble exercises, but I fail to see the point of this if you can just have a method that returns the exercise command you want to send. |
@stefanobaghino-da if I follow the examples the examples have the choice string manually written. Is there choice methods generated for every choice? even if generated, having the choice name as a accessible variable/const would be helpful for reuse, testing etc. Generated classes can provide a second valuable function: to parse the daml file so code can be built from it. For example, maybe I want to monitor the transactions for a specific exercising of a choice, it would be nice to reference the choice name from the const instead of looking it up in the daml and re-writing it. If the value ever changed then I would be able to easily note/watch for the change of the const value in the generated code. |
I understand the point about the examples, but that to me is more of a pointer of the fact that we should do some work with regards to our examples (which were first authored before the first version of the codegen), rather than encourage working without generated code.
Yes.
Can you expand on what would be the advantage of generating constants for choice names, since you can access any of those through a method call?
Parsing Daml files is discouraged. Our codegen decouples from the surface language by using the Daml-LF intermediate format, which is designed for this.
This makes sense during the development workflow and could be a good argument towards considering this, but keep in mind that changing your choice names is something that should not be done lightly, since it represents a breaking change in Daml code and ultimately in the signature you expose through the Ledger API. @S11001001 @ray-roestenburg-da Thoughts? |
@stefanobaghino-da even something like: "You index/store the transactions and you want to query for specific moments where a choice was exercised." It comes back to having a "golden source" for the choice name. Maybe you want to validate that the choice is even possible before checking the index, so you need some source of choice names.
I was suggesting that your current codegen is already doing the parsing of the daml files / generates the code. From the generated code (from the daml codegen), there can be other code generation that occurs at later stages (both compile time and runtime): storage, indexing, UI generation, api request validations, etc. As you suggest, there may be a helper method for each choice, but someone may wish to write a single method that can execute any of the available choices, so could use the lower level builder and it would be better to use a reference to a name instead of manually re-typing it. (same idea for writing tests) |
Okay found the confusion here. The exerciseByKey commands are at the Template level, but you need to navigate into Even with the methods generated it would be nice to have these values available so they can be passed into other tooling as described above. |
Building on this further: https://discuss.daml.com/t/getting-all-choices-for-a-given-party-or-contract/4830/4. This discussion on how to get the list of choices is a good example of why we should have the choice names in the generated code. There is a lot of hoops to jump through to get a simple list of choices. by giving the devs the ability to meta program you enable the community to build more capabilities instead of waiting for DA to build everything. |
I suggest we codegen for each choice // one for each choice
public static final ChoiceMetadata<Tpl, ArgType, ResType> CHOICE_Iou_Transfer = ...
|
@S11001001 What would be the overlap with #12897 (comment)? |
@stefanobaghino-da The suggested implementations pretty much completely overlap. I should note, however, that for the typical choice exerciser, #14312 is likely to be a lot nicer to use for the restricted case of decoding the result (because if you line the utilities up, you can largely forget that encoding/decoding is happening at all). Which might be a better solution to #12897, depending on what the exercise code looks like. |
@stefanobaghino-da Let's say that you are inspecting a transaction stream. There are a few tools you can build nicely on top of
|
@leonidr-da @asarpeshkar-da @juliuswilliam-da I would like to have your feedback with regards to this and whether it would help you with the issue outlined in #12897 and https://discuss.daml.com/t/extracting-choice-return-type-defined-in-daml-templates-as-a-java-type/4666. |
TypeScript has a sort of counterpart to this daml/language-support/ts/daml-types/index.ts Lines 116 to 122 in a516be7
Of note, the daml/language-support/ts/daml-ledger/index.ts Lines 1104 to 1108 in a516be7
|
With #15116 merged, the example in description can be written as -ExerciseCommand(Organization.TEMPLATE_ID, "someContractId", "CreateManager", args)
+ExerciseCommand(Organization.TEMPLATE_ID, "someContractId", Organization.CHOICE_CreateManager.name, args) |
What is the problem you want to solve?
The upcoming deprecated exercise by key command currently hard codes the choice name such as:
The choice name is hard coded and cannot be referenced / re-used.
If I create the command manually I would use:
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!
The text was updated successfully, but these errors were encountered: