Skip to content
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

Typed ACS and transaction streams for Java codegen #15159

Merged
merged 27 commits into from
Oct 12, 2022

Conversation

chunlokling-da
Copy link
Contributor

fixes #14969

@chunlokling-da chunlokling-da linked an issue Oct 4, 2022 that may be closed by this pull request

@Override
public TransactionFilter transactionFilter(Set<String> parties) {
Filter filter = new InclusiveFilter(Collections.emptySet(), Map.of(TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW));
Copy link
Contributor Author

@chunlokling-da chunlokling-da Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it makes sense to always include view or maybe we should pass in a method argument here and let the caller decide

Filter.Interface.INCLUDE_VIEW

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't include the view, the decoding part of the utility is guaranteed to fail to find the view. This utility should work in harmony with the other utilities that contribute to the goal of typed ACS/transaction streams.

@chunlokling-da chunlokling-da self-assigned this Oct 4, 2022
import java.util.Optional;
import java.util.Set;

public final class ContractWithInterfaceView<Id, View> extends Contract<Id, View> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example of why I am reluctant to add extends clauses to class or interface type parameters that aren't strictly necessary.

Sure, when defining Contract, we could have made its second type parameter extends Template. That would have compiled at the time. However, it has no functional benefits for the API, and then you would be stuck here.

While adding constraints to class tparams can be useful, it is more often no better than DatatypeContexts aka "stupid theta" in Haskell, and just as worth avoiding.

…ransaction-streams

# Conflicts:
#	language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java
CHANGELOG_BEGIN
CHANGELOG_END
@chunlokling-da chunlokling-da marked this pull request as ready for review October 6, 2022 11:22
@chunlokling-da chunlokling-da changed the title added transactionFilter Typed ACS and transaction streams for Java codegen Oct 6, 2022
@chunlokling-da chunlokling-da requested a review from a team October 6, 2022 14:13
@chunlokling-da chunlokling-da added component/java-ecosystem Java development experience team/ledger-clients Related to the Ledger Clients team's components. ledger clients facade enriching the ledger API by bindings/codegen, JSON API, custom view labels Oct 6, 2022
Copy link
Contributor

@ray-roestenburg-da ray-roestenburg-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@S11001001
Copy link
Contributor

@chunlokling-da Additionally, I created #15191 to follow-up on this PR; if you want to think about what this PR would mean for that issue, I won't stop you 🙂

…ransaction-streams

# Conflicts:
#	language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java
#	language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java
#	language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java
#	language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala
Comment on lines 31 to 36
static <Ct> ContractUtil<Ct> of(ContractCompanion<Ct, ?, ?> companion) {
Filter filter = new InclusiveFilter(Set.of(companion.TEMPLATE_ID), Collections.emptyMap());
return new ContractUtil<>(companion::fromCreatedEvent, filter);
}

static <Cid, View> ContractUtil<Contract<Cid, View>> of(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest doing at least the ACS part of #15191 in this PR, if leaving aside the transaction stream part, as a sanity check for the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it is now using the new ACS method in IouMain

@S11001001
Copy link
Contributor

S11001001 commented Oct 12, 2022

Per discussion out-of-band,

  • please revert the Java 8 changes

@chunlokling-da I believe there are symbol accessibility problems in this PR, but if you want to pick up #15191 right away to change the source/target in quickstart-java and update the example, then I think we can merge this one.

@S11001001
Copy link
Contributor

@chunlokling-da The other bearing that #15191 has on this PR is: as we have discussed, the idea of the rxjava additions is a bit of a crucible to ensure the bindings library and codegen provide enough support to make implementing this kind of stream relatively easy to do.

Likewise, the change to the quickstart-java is to ensure that the feature is powerful enough to support our tutorial and yields tutorial code that looks good; we can make further changes to this feature to ensure that both of those things are true in the PR for that issue.

Comment on lines +26 to +40
@NonNull
public Optional<String> getOffset() {
// Empty string indicates that the field is not present in the protobuf.
return Optional.of(offset).filter(off -> !offset.equals(""));
}

@NonNull
public List<@NonNull Ct> getContracts() {
return activeContracts;
}

@NonNull
public String getWorkflowId() {
return workflowId;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should define public final properties rather than private properties with getters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can consider this for a follow-up PR though, e.g. the quickstart-java one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, we do not care that Intellij thinks you shouldn't have Optional fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do it in the quickstart-java issue: #15191

@chunlokling-da chunlokling-da merged commit 74dd242 into main Oct 12, 2022
@chunlokling-da chunlokling-da deleted the 14969-typed-acs-and-transaction-streams branch October 12, 2022 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/java-ecosystem Java development experience ledger clients facade enriching the ledger API by bindings/codegen, JSON API, custom view team/ledger-clients Related to the Ledger Clients team's components.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typed ACS and transaction streams for Java codegen
3 participants