Open leonidr-da opened 2 years ago
Right now the Java codegen includes a decoder which allows you to translate a created event into a the generated Java representation of the Daml contract whose creation happens as part of said event. In this representation, choices are modeled as methods on the Java object that "wraps" a Daml contract
Based on what you wrote, you would like to:
Choice
) that has been taken, whose exact structure is expressed as a Java class generated in the same way as Contract
s, with fields and/or accessor methods that allow to directly tap into
Choice
and Contract
objects, rather than a sequence of child event identifiers as in the ExercisedEvent
ExercisedEvent
into a Choice
objectIs the phrasing I used to expand on your ask correct and complete?
I'd also like a more finely typed way of traversing the transaction tree. To the above, I'd add that the arguments and results should also use generated types rather than the generic Value
AST type.
It would also be nice if the ExercisedEvent -> Choice
decoder implemented a deep transformation so one could then implement a tree traversal as a bunch of type tests on Choice
values.
Yes, I probably wrote it badly, but both were points I was trying to make in my reply, thanks for confirming.
@stefanobaghino-da Yes. I think 1.i, 1.ii and 2 would go a really long way already. But once you have those, I think that you're in reach of 1.iii too, which would be awesome.
Depends on:
With those we will not even need to generate any new code to support an exercise event decoder.
Implementation plan for this feature:
<Z>
that takes a series of pairs <Id, Arg, Res> (Choice<Id, Arg, Res>, EEv<ContractId<Id>, Arg, Res> => Z)
where EEv
is a generalization of Exercised
to produce a stream of Z
Z
can be supplied as well; if undefined, unrecognized choices will simply be discardedChoice<Id, Arg, Res>
and produces a stream of EEv<ContractId<Id>, Arg, Res>
is trivially derivable from that by simply passing identity
as the function argZ = Void
ContractDecoder
to ExerciseDecoder
that produces untyped but codegen-classed EEv
s
ContractDecoder
to take InterfaceCompanion
s as well, possibly by taking any ContractTypeCompanion
s, andINTERFACE
s as well when generating a ContractDecoder subclassExerciseDecoder
, which uses its own builder...this implements 1(iii) from @stefanobaghino-da 's post For posterity, the thing we have called Choice
in the bindings now is not what @stefanobaghino-da refers to as Choice
above; instead I have called the latter Choice
EEv
in the above plan.
What is the problem you want to solve?
Can we extend the Java codegen to include a decoder for choices as well as templates? From an ExercisedEvent.
This would allow us to traverse transaction tree's and write logic that depends on a specific model event as opposed to reinterpreting the structure of a general ExercisedEvent.
cc @asarpeshkar-da