-
Notifications
You must be signed in to change notification settings - Fork 205
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
chunlokling-da
merged 27 commits into
main
from
14969-typed-acs-and-transaction-streams
Oct 12, 2022
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
43c9f36
added transactionFilter
chunlokling-da 08d0254
move transactionFilter to `TransactionFilter`
chunlokling-da 7178636
fromCreatedEvent
chunlokling-da ca68c0c
format
chunlokling-da b76ff64
added getTransaction with contract type companion
chunlokling-da 7269048
ACS using contract type companion
chunlokling-da ff2cde0
Merge remote-tracking branch 'origin/main' into 14969-typed-acs-and-t…
chunlokling-da 14af3cc
position
chunlokling-da 1057819
add change log
chunlokling-da ac6fca6
Ct
chunlokling-da 783383c
Ct
chunlokling-da 6532d5d
format
chunlokling-da 85d8973
better exception
chunlokling-da 99868fb
fixed test cases
chunlokling-da bc65de3
added java doc and rename method to GetContracts
chunlokling-da ecb1ea8
address Stephen's comments
chunlokling-da ec9fc8f
address Stephen's comments
chunlokling-da f9c0fa4
address Stephen's comments
chunlokling-da 5526e2f
Merge remote-tracking branch 'origin/main' into 14969-typed-acs-and-t…
chunlokling-da 7b45bd3
remove unused import
chunlokling-da f8f58ba
format
chunlokling-da 2e00060
address Stephen's comments
chunlokling-da 73ee886
address Stephen's comments
chunlokling-da 5e70489
Make some codegen code to be java 8 compatible; Modify IouMain to use…
chunlokling-da c8b2200
use 1.11, no need to be java 8 compatible
chunlokling-da 922d1fd
revert
chunlokling-da 24bbec2
11 not 1.11
chunlokling-da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
64 changes: 64 additions & 0 deletions
64
language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.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,64 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.rxjava; | ||
|
||
import com.daml.ledger.javaapi.data.*; | ||
import com.daml.ledger.javaapi.data.codegen.Contract; | ||
import com.daml.ledger.javaapi.data.codegen.ContractCompanion; | ||
import com.daml.ledger.javaapi.data.codegen.InterfaceCompanion; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* This class contains utilities to decode a <code>CreatedEvent</code> and create a <code> | ||
* TransactionFilter</code> by provider parties It can only be instantiated with a subtype of <code> | ||
* ContractCompanion</code> | ||
*/ | ||
public final class ContractUtil<Ct> { | ||
private final FromCreatedEventFunc<CreatedEvent, Ct> fromCreatedEvent; | ||
|
||
private final Filter filter; | ||
|
||
private ContractUtil(FromCreatedEventFunc<CreatedEvent, Ct> fromCreatedEvent, Filter filter) { | ||
this.fromCreatedEvent = fromCreatedEvent; | ||
this.filter = filter; | ||
} | ||
|
||
public static <Ct> ContractUtil<Ct> of(ContractCompanion<Ct, ?, ?> companion) { | ||
Filter filter = | ||
new InclusiveFilter(Collections.singleton(companion.TEMPLATE_ID), Collections.emptyMap()); | ||
return new ContractUtil<>(companion::fromCreatedEvent, filter); | ||
} | ||
|
||
public static <Cid, View> ContractUtil<Contract<Cid, View>> of( | ||
InterfaceCompanion<?, Cid, View> companion) { | ||
Filter filter = | ||
new InclusiveFilter( | ||
Collections.emptySet(), | ||
Collections.singletonMap(companion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); | ||
return new ContractUtil<>(companion::fromCreatedEvent, filter); | ||
} | ||
|
||
public Ct toContract(CreatedEvent createdEvent) throws IllegalArgumentException { | ||
return fromCreatedEvent.apply(createdEvent); | ||
} | ||
|
||
public TransactionFilter transactionFilter(Set<String> parties) { | ||
return transactionFilter(filter, parties); | ||
} | ||
|
||
private static TransactionFilter transactionFilter(Filter filter, Set<String> parties) { | ||
Map<String, Filter> partyToFilters = | ||
parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); | ||
return new FiltersByParty(partyToFilters); | ||
} | ||
|
||
@FunctionalInterface | ||
private interface FromCreatedEventFunc<T, R> { | ||
R apply(T t) throws IllegalArgumentException; | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...age-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.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,69 @@ | ||
// 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; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class ActiveContracts<Ct> implements WorkflowEvent { | ||
|
||
private final String offset; | ||
|
||
private final List<Ct> activeContracts; | ||
|
||
private final String workflowId; | ||
|
||
public ActiveContracts( | ||
@NonNull String offset, @NonNull List<Ct> activeContracts, String workflowId) { | ||
this.offset = offset; | ||
this.activeContracts = activeContracts; | ||
this.workflowId = workflowId; | ||
} | ||
|
||
@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; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ActiveContracts{" | ||
+ "offset='" | ||
+ offset | ||
+ '\'' | ||
+ ", activeContracts=" | ||
+ activeContracts | ||
+ ", workflowId=" | ||
+ workflowId | ||
+ '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ActiveContracts<?> that = (ActiveContracts<?>) o; | ||
return Objects.equals(offset, that.offset) | ||
&& Objects.equals(activeContracts, that.activeContracts) | ||
&& Objects.equals(workflowId, that.workflowId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(offset, activeContracts, workflowId); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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