From 43c9f36e00e14ed8aff902ce265396b52f613b82 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 4 Oct 2022 11:21:19 +0100 Subject: [PATCH 01/25] added transactionFilter --- .../javaapi/data/codegen/ContractCompanion.java | 15 ++++++++++++--- .../data/codegen/ContractTypeCompanion.java | 5 +++++ .../javaapi/data/codegen/InterfaceCompanion.java | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index c1491ae34363..4fad5f4be566 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -3,13 +3,15 @@ package com.daml.ledger.javaapi.data.codegen; -import com.daml.ledger.javaapi.data.CreatedEvent; +import com.daml.ledger.javaapi.data.*; import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Identifier; -import com.daml.ledger.javaapi.data.Value; + +import java.util.Collections; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Function; +import java.util.stream.Collectors; /** * Metadata and utilities associated with a template as a whole, rather than one single contract @@ -68,6 +70,13 @@ public Id toContractId(ContractId parameterizedContractId) { return newContractId.apply(parameterizedContractId.contractId); } + @Override + public TransactionFilter transactionFilter(Set parties) { + Filter filter = new InclusiveFilter(Set.of(TEMPLATE_ID), Collections.emptyMap()); + Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); + return new FiltersByParty(partyToFilters); + } + protected ContractCompanion( String templateClassName, Identifier templateId, diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java index 390a34a8a05b..e052c3f47863 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java @@ -4,6 +4,9 @@ package com.daml.ledger.javaapi.data.codegen; import com.daml.ledger.javaapi.data.Identifier; +import com.daml.ledger.javaapi.data.TransactionFilter; + +import java.util.Set; /** The commonality between {@link ContractCompanion} and {@link InterfaceCompanion}. */ public abstract class ContractTypeCompanion { @@ -13,4 +16,6 @@ public abstract class ContractTypeCompanion { protected ContractTypeCompanion(Identifier templateId) { TEMPLATE_ID = templateId; } + + public abstract TransactionFilter transactionFilter(Set parties); } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index 2912953fb16a..b9674a78ede9 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -3,7 +3,13 @@ package com.daml.ledger.javaapi.data.codegen; -import com.daml.ledger.javaapi.data.Identifier; +import com.daml.ledger.javaapi.data.*; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; /** * Metadata and utilities associated with an interface as a whole. Its subclasses serve to @@ -19,4 +25,11 @@ protected InterfaceCompanion(Identifier templateId, ValueDecoder valueDeco super(templateId); this.valueDecoder = valueDecoder; } + + @Override + public TransactionFilter transactionFilter(Set parties) { + Filter filter = new InclusiveFilter(Collections.emptySet(), Map.of(TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); + Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); + return new FiltersByParty(partyToFilters); + } } From 08d025404e6cc4c4b8f746f0ac39d9633eeef808 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 4 Oct 2022 13:50:26 +0100 Subject: [PATCH 02/25] move transactionFilter to `TransactionFilter` --- .../ledger/javaapi/data/TransactionFilter.java | 15 +++++++++++++++ .../javaapi/data/codegen/ContractCompanion.java | 7 ------- .../data/codegen/ContractTypeCompanion.java | 2 -- .../javaapi/data/codegen/InterfaceCompanion.java | 7 ------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java index fb310394f5ba..bcb17b4eba8d 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java @@ -4,7 +4,14 @@ package com.daml.ledger.javaapi.data; import com.daml.ledger.api.v1.TransactionFilterOuterClass; +import com.daml.ledger.javaapi.data.codegen.ContractCompanion; +import com.daml.ledger.javaapi.data.codegen.ContractTypeCompanion; + +import java.util.Collections; +import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; public abstract class TransactionFilter { @@ -17,4 +24,12 @@ public static TransactionFilter fromProto( abstract TransactionFilterOuterClass.TransactionFilter toProto(); public abstract Set getParties(); + + public static TransactionFilter transactionFilter(ContractTypeCompanion contractCompanion , Set parties) { + Filter filter = (contractCompanion instanceof ContractCompanion) + ? new InclusiveFilter(Set.of(contractCompanion.TEMPLATE_ID), Collections.emptyMap()) + : new InclusiveFilter(Collections.emptySet(), Map.of(contractCompanion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); + Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); + return new FiltersByParty(partyToFilters); + } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index 4fad5f4be566..43073a96e475 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -70,13 +70,6 @@ public Id toContractId(ContractId parameterizedContractId) { return newContractId.apply(parameterizedContractId.contractId); } - @Override - public TransactionFilter transactionFilter(Set parties) { - Filter filter = new InclusiveFilter(Set.of(TEMPLATE_ID), Collections.emptyMap()); - Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); - return new FiltersByParty(partyToFilters); - } - protected ContractCompanion( String templateClassName, Identifier templateId, diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java index e052c3f47863..73922579042e 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java @@ -16,6 +16,4 @@ public abstract class ContractTypeCompanion { protected ContractTypeCompanion(Identifier templateId) { TEMPLATE_ID = templateId; } - - public abstract TransactionFilter transactionFilter(Set parties); } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index b9674a78ede9..b7ab71b732ba 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -25,11 +25,4 @@ protected InterfaceCompanion(Identifier templateId, ValueDecoder valueDeco super(templateId); this.valueDecoder = valueDecoder; } - - @Override - public TransactionFilter transactionFilter(Set parties) { - Filter filter = new InclusiveFilter(Collections.emptySet(), Map.of(TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); - Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); - return new FiltersByParty(partyToFilters); - } } From 7178636316c5b29a46b60ad9f4ef12d17037db2b Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Wed, 5 Oct 2022 15:10:20 +0100 Subject: [PATCH 03/25] fromCreatedEvent --- .../ledger/javaapi/data/codegen/Contract.java | 6 +-- .../data/codegen/ContractCompanion.java | 3 -- .../data/codegen/ContractTypeCompanion.java | 5 +- .../codegen/ContractWithInterfaceView.java | 25 +++++++++ .../javaapi/data/codegen/ContractWithKey.java | 3 +- .../data/codegen/InterfaceCompanion.java | 40 +++++++++++++-- .../backend/java/inner/ContractClass.scala | 15 ------ .../backend/java/inner/InterfaceClass.scala | 51 +++++++++++-------- 8 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java index 7fef884aa855..3052dab38004 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java @@ -42,9 +42,6 @@ protected Contract( this.observers = observers; } - // concrete 1st type param would need a self-reference type param in Contract - protected abstract ContractCompanion, Id, Data> getCompanion(); - @Override public boolean equals(Object object) { if (this == object) { @@ -74,8 +71,7 @@ public int hashCode() { @Override public String toString() { return String.format( - "%s.Contract(%s, %s, %s, %s, %s)", - getCompanion().templateClassName, + "Contract(%s, %s, %s, %s, %s)", this.id, this.data, this.agreementText, diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index 43073a96e475..299ec51a3095 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -6,12 +6,9 @@ import com.daml.ledger.javaapi.data.*; import com.daml.ledger.javaapi.data.DamlRecord; -import java.util.Collections; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; /** * Metadata and utilities associated with a template as a whole, rather than one single contract diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java index 73922579042e..3c08a4a4868c 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java @@ -4,12 +4,9 @@ package com.daml.ledger.javaapi.data.codegen; import com.daml.ledger.javaapi.data.Identifier; -import com.daml.ledger.javaapi.data.TransactionFilter; - -import java.util.Set; /** The commonality between {@link ContractCompanion} and {@link InterfaceCompanion}. */ -public abstract class ContractTypeCompanion { +public abstract class ContractTypeCompanion { /** The full template ID of the template or interface that defined this companion. */ public final Identifier TEMPLATE_ID; diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java new file mode 100644 index 000000000000..0bf4645b1b7c --- /dev/null +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java @@ -0,0 +1,25 @@ +// 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.codegen; + +import java.util.Optional; +import java.util.Set; + +public final class ContractWithInterfaceView extends Contract { + + ContractWithInterfaceView( + Id id, + View interfaceView, + Optional agreementText, + Set signatories, + Set observers) { + super(id, interfaceView, agreementText, signatories, observers); + } + + @Override + public boolean equals(Object object) { + return object instanceof ContractWithInterfaceView + && super.equals(object); + } +} diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java index d4dada8a7a8f..53b04f92a1db 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java @@ -38,8 +38,7 @@ public final int hashCode() { @Override public final String toString() { return String.format( - "%s.Contract(%s, %s, %s, %s, %s, %s)", - getCompanion().templateClassName, + "Contract(%s, %s, %s, %s, %s, %s)", this.id, this.data, this.agreementText, diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index b7ab71b732ba..c4dc4d360598 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -4,12 +4,12 @@ package com.daml.ledger.javaapi.data.codegen; import com.daml.ledger.javaapi.data.*; +import com.daml.ledger.javaapi.data.DamlRecord; -import java.util.Collections; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; /** * Metadata and utilities associated with an interface as a whole. Its subclasses serve to @@ -17,12 +17,44 @@ * * @param The generated interface marker class. */ -public abstract class InterfaceCompanion extends ContractTypeCompanion { +public abstract class InterfaceCompanion extends ContractTypeCompanion { + + protected final Function newContractId; public final ValueDecoder valueDecoder; - protected InterfaceCompanion(Identifier templateId, ValueDecoder valueDecoder) { + public Contract fromIdAndRecord( + String contractId, + Map interfaceViews, + Optional agreementText, + Set signatories, + Set observers) throws IllegalAccessException { + Optional maybeRecord = Optional.ofNullable(interfaceViews.get(TEMPLATE_ID)); + Id id = newContractId.apply(contractId); + if(maybeRecord.isPresent()) { + View view = valueDecoder.decode(maybeRecord.get()); + return new ContractWithInterfaceView<>(id, view, agreementText, signatories, observers); + } else { + throw new IllegalAccessException("interface view not found. It could be failed"); + } + } + + public final Contract fromCreatedEvent(CreatedEvent event) throws IllegalAccessException { + return fromIdAndRecord( + event.getContractId(), + event.getInterfaceViews(), + event.getAgreementText(), + event.getSignatories(), + event.getObservers()); + } + + protected InterfaceCompanion( + Identifier templateId, + Function newContractId, + ValueDecoder valueDecoder + ) { super(templateId); + this.newContractId = newContractId; this.valueDecoder = valueDecoder; } } diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala index 7f9c019a2c9e..51b14f4b3d22 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala @@ -107,19 +107,6 @@ object ContractClass { private[this] val contractIdClassName = ClassName bestGuess "ContractId" - private[this] def generateGetCompanion(templateClassName: ClassName): MethodSpec = { - val contractClassName = ClassName bestGuess "Contract" - ClassGenUtils.generateGetCompanion( - ParameterizedTypeName.get( - ClassName get classOf[javaapi.data.codegen.ContractCompanion[_, _, _]], - contractClassName, - contractIdClassName, - templateClassName, - ), - companionFieldName, - ) - } - def create( templateClassName: ClassName, key: Option[Type], @@ -172,8 +159,6 @@ object ContractClass { classBuilder.addMethod(constructor) val contractClassName = ClassName.bestGuess("Contract") - classBuilder - .addMethod(generateGetCompanion(templateClassName)) new Builder( classBuilder, contractClassName, diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index 08db7668a149..a6905f7296ab 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -84,27 +84,36 @@ object InterfaceClass extends StrictLogging { private def generateInterfaceCompanionClass( interfaceName: ClassName, interfaceViewTypeName: ClassName, - ): TypeSpec = TypeSpec - .classBuilder(companionName) - .superclass( - ParameterizedTypeName - .get(ClassName get classOf[InterfaceCompanion[_, _]], interfaceName, interfaceViewTypeName) - ) - .addModifiers(Modifier.FINAL, Modifier.PUBLIC, Modifier.STATIC) - .addMethod { - MethodSpec - .constructorBuilder() - // intentionally package-private - .addStatement( - "super($T.$N, $T.$L())", - interfaceName, - ClassGenUtils.templateIdFieldName, - interfaceViewTypeName, - "valueDecoder", - ) - .build() - } - .build() + ): TypeSpec = { + val contractIdClassName = ClassName bestGuess "ContractId" + TypeSpec + .classBuilder(companionName) + .superclass( + ParameterizedTypeName + .get( + ClassName get classOf[InterfaceCompanion[_, _, _]], + interfaceName, + contractIdClassName, + interfaceViewTypeName, + ) + ) + .addModifiers(Modifier.FINAL, Modifier.PUBLIC, Modifier.STATIC) + .addMethod { + MethodSpec + .constructorBuilder() + // intentionally package-private + .addStatement( + "super($T.$N, $T::new, $T.$L())", + interfaceName, + ClassGenUtils.templateIdFieldName, + contractIdClassName, + interfaceViewTypeName, + "valueDecoder", + ) + .build() + } + .build() + } private def generateTemplateIdField(packageId: PackageId, name: QualifiedName): FieldSpec = ClassGenUtils.generateTemplateIdField( From ca68c0c866b2271e6952924145df80ab063c8af4 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Wed, 5 Oct 2022 15:27:31 +0100 Subject: [PATCH 04/25] format --- .../javaapi/data/TransactionFilter.java | 14 +++++++---- .../ledger/javaapi/data/codegen/Contract.java | 6 +---- .../data/codegen/ContractCompanion.java | 1 - .../codegen/ContractWithInterfaceView.java | 3 +-- .../javaapi/data/codegen/ContractWithKey.java | 7 +----- .../data/codegen/InterfaceCompanion.java | 25 +++++++++---------- 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java index bcb17b4eba8d..351eca956b70 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/TransactionFilter.java @@ -6,7 +6,6 @@ import com.daml.ledger.api.v1.TransactionFilterOuterClass; import com.daml.ledger.javaapi.data.codegen.ContractCompanion; import com.daml.ledger.javaapi.data.codegen.ContractTypeCompanion; - import java.util.Collections; import java.util.Map; import java.util.Set; @@ -25,11 +24,16 @@ public static TransactionFilter fromProto( public abstract Set getParties(); - public static TransactionFilter transactionFilter(ContractTypeCompanion contractCompanion , Set parties) { - Filter filter = (contractCompanion instanceof ContractCompanion) + public static TransactionFilter transactionFilter( + ContractTypeCompanion contractCompanion, Set parties) { + Filter filter = + (contractCompanion instanceof ContractCompanion) ? new InclusiveFilter(Set.of(contractCompanion.TEMPLATE_ID), Collections.emptyMap()) - : new InclusiveFilter(Collections.emptySet(), Map.of(contractCompanion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); - Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); + : new InclusiveFilter( + Collections.emptySet(), + Map.of(contractCompanion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); + Map partyToFilters = + parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); return new FiltersByParty(partyToFilters); } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java index 3052dab38004..6de7406d070a 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java @@ -72,10 +72,6 @@ public int hashCode() { public String toString() { return String.format( "Contract(%s, %s, %s, %s, %s)", - this.id, - this.data, - this.agreementText, - this.signatories, - this.observers); + this.id, this.data, this.agreementText, this.signatories, this.observers); } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index 299ec51a3095..0298bdc57efa 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -5,7 +5,6 @@ import com.daml.ledger.javaapi.data.*; import com.daml.ledger.javaapi.data.DamlRecord; - import java.util.Optional; import java.util.Set; import java.util.function.Function; diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java index 0bf4645b1b7c..1ef8d1d93370 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java @@ -19,7 +19,6 @@ public final class ContractWithInterfaceView extends Contract extends ContractTypeCompan public final ValueDecoder valueDecoder; - public Contract fromIdAndRecord( - String contractId, - Map interfaceViews, - Optional agreementText, - Set signatories, - Set observers) throws IllegalAccessException { + private Contract fromIdAndRecord( + String contractId, + Map interfaceViews, + Optional agreementText, + Set signatories, + Set observers) + throws IllegalAccessException { Optional maybeRecord = Optional.ofNullable(interfaceViews.get(TEMPLATE_ID)); Id id = newContractId.apply(contractId); - if(maybeRecord.isPresent()) { + if (maybeRecord.isPresent()) { View view = valueDecoder.decode(maybeRecord.get()); return new ContractWithInterfaceView<>(id, view, agreementText, signatories, observers); } else { + // TODO: CL handle all exceptional cases throw new IllegalAccessException("interface view not found. It could be failed"); } } - public final Contract fromCreatedEvent(CreatedEvent event) throws IllegalAccessException { + public final Contract fromCreatedEvent(CreatedEvent event) + throws IllegalAccessException { return fromIdAndRecord( event.getContractId(), event.getInterfaceViews(), @@ -49,10 +51,7 @@ public final Contract fromCreatedEvent(CreatedEvent event) throws Ille } protected InterfaceCompanion( - Identifier templateId, - Function newContractId, - ValueDecoder valueDecoder - ) { + Identifier templateId, Function newContractId, ValueDecoder valueDecoder) { super(templateId); this.newContractId = newContractId; this.valueDecoder = valueDecoder; From b76ff642d5e5dcf521c7a77f6de8d0f61e223d76 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 11:12:41 +0100 Subject: [PATCH 05/25] added getTransaction with contract type companion --- .../com/daml/ledger/rxjava/ContractUtil.java | 57 +++++++++++++++++++ .../ledger/rxjava/TransactionsClient.java | 15 +++-- .../rxjava/grpc/TransactionClientImpl.java | 36 ++++++++++++ .../codegen/ContractWithInterfaceView.java | 2 +- 4 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java new file mode 100644 index 000000000000..fcb52bc5abb4 --- /dev/null +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java @@ -0,0 +1,57 @@ +// 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; + +public final class ContractUtil { + private final FromCreatedEventFunc fromCreatedEvent; + + private final Filter filter; + + private ContractUtil(FromCreatedEventFunc fromCreatedEvent, Filter filter) { + this.fromCreatedEvent = fromCreatedEvent; + this.filter = filter; + } + + static ContractUtil of(ContractCompanion companion) { + Filter filter = new InclusiveFilter(Set.of(companion.TEMPLATE_ID), Collections.emptyMap()); + return new ContractUtil<>(companion::fromCreatedEvent, filter); + } + + static ContractUtil> of( + InterfaceCompanion companion) { + Filter filter = + new InclusiveFilter( + Collections.emptySet(), Map.of(companion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); + return new ContractUtil<>(companion::fromCreatedEvent, filter); + } + + public Ct toContract(CreatedEvent createdEvent) throws IllegalAccessException { + return fromCreatedEvent.apply(createdEvent); + } + + public TransactionFilter transactionFilter(Set parties) { + return transactionFilter(filter, parties); + } + + private TransactionFilter transactionFilter(Filter filter, Set parties) { + Map partyToFilters = + parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); + return new FiltersByParty(partyToFilters); + } + + @FunctionalInterface + private interface FromCreatedEventFunc { + R apply(T t) throws IllegalAccessException; + } +} diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java index d8cfdc89e4fa..0aa19ffeaec7 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java @@ -3,10 +3,7 @@ package com.daml.ledger.rxjava; -import com.daml.ledger.javaapi.data.LedgerOffset; -import com.daml.ledger.javaapi.data.Transaction; -import com.daml.ledger.javaapi.data.TransactionFilter; -import com.daml.ledger.javaapi.data.TransactionTree; +import com.daml.ledger.javaapi.data.*; import io.reactivex.Flowable; import io.reactivex.Single; import java.util.Set; @@ -30,6 +27,16 @@ Flowable getTransactions( Flowable getTransactions( LedgerOffset begin, TransactionFilter filter, boolean verbose, String accessToken); + Flowable getTransactions( + ContractUtil contractUtil, LedgerOffset begin, Set parties, boolean verbose); + + Flowable getTransactions( + ContractUtil contractUtil, + LedgerOffset begin, + Set parties, + boolean verbose, + String accessToken); + Flowable getTransactionsTrees( LedgerOffset begin, LedgerOffset end, TransactionFilter filter, boolean verbose); diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java index e8054317197d..541ac89aa3a3 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java @@ -7,6 +7,7 @@ import com.daml.ledger.api.v1.TransactionServiceGrpc; import com.daml.ledger.api.v1.TransactionServiceOuterClass; import com.daml.ledger.javaapi.data.*; +import com.daml.ledger.rxjava.ContractUtil; import com.daml.ledger.rxjava.TransactionsClient; import com.daml.ledger.rxjava.grpc.helpers.StubHelper; import com.daml.ledger.rxjava.util.ClientPublisherFlowable; @@ -73,6 +74,41 @@ public Flowable getTransactions( return getTransactions(begin, end, filter, verbose, Optional.of(accessToken)); } + private Flowable getTransactions( + ContractUtil contractUtil, + LedgerOffset begin, + Set parties, + boolean verbose, + Optional accessToken) { + TransactionFilter filter = contractUtil.transactionFilter(parties); + Flowable transactions = getTransactions(begin, filter, verbose, accessToken); + Flowable createdEvents = + transactions + .concatMapIterable(Transaction::getEvents) + .flatMap( + event -> + (event instanceof CreatedEvent) + ? Flowable.just((CreatedEvent) event) + : Flowable.empty()); + return createdEvents.map(contractUtil::toContract); + } + + @Override + public Flowable getTransactions( + ContractUtil contractUtil, LedgerOffset begin, Set parties, boolean verbose) { + return getTransactions(contractUtil, begin, parties, verbose, Optional.empty()); + } + + @Override + public Flowable getTransactions( + ContractUtil contractUtil, + LedgerOffset begin, + Set parties, + boolean verbose, + String accessToken) { + return getTransactions(contractUtil, begin, parties, verbose, Optional.of(accessToken)); + } + private Flowable getTransactions( LedgerOffset begin, TransactionFilter filter, boolean verbose, Optional accessToken) { TransactionServiceOuterClass.GetTransactionsRequest request = diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java index 1ef8d1d93370..f6668ad09ac0 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java @@ -6,7 +6,7 @@ import java.util.Optional; import java.util.Set; -public final class ContractWithInterfaceView extends Contract { +final class ContractWithInterfaceView extends Contract { ContractWithInterfaceView( Id id, From 7269048f9783303edb2316f8fcb33ca5a8e1dc5b Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 11:38:24 +0100 Subject: [PATCH 06/25] ACS using contract type companion --- .../ledger/rxjava/ActiveContractsClient.java | 8 +++ .../rxjava/grpc/ActiveContractClientImpl.java | 41 ++++++++++- .../ledger/javaapi/data/ActiveContracts.java | 69 +++++++++++++++++++ 3 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java index 959529d23a5c..daeea71a3680 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java @@ -3,9 +3,11 @@ package com.daml.ledger.rxjava; +import com.daml.ledger.javaapi.data.ActiveContracts; import com.daml.ledger.javaapi.data.GetActiveContractsResponse; import com.daml.ledger.javaapi.data.TransactionFilter; import io.reactivex.Flowable; +import java.util.Set; /** An RxJava version of {@link com.daml.ledger.api.v1.ActiveContractsServiceGrpc} */ public interface ActiveContractsClient { @@ -15,4 +17,10 @@ Flowable getActiveContracts( Flowable getActiveContracts( TransactionFilter filter, boolean verbose, String accessToken); + + Flowable> getActiveContracts( + ContractUtil contractUtil, Set parties, boolean verbose); + + Flowable> getActiveContracts( + ContractUtil contractUtil, Set parties, boolean verbose, String accessToken); } diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java index fc1bd2851884..a82802da1b2b 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java @@ -6,15 +6,17 @@ import com.daml.grpc.adapter.ExecutionSequencerFactory; import com.daml.ledger.api.v1.ActiveContractsServiceGrpc; import com.daml.ledger.api.v1.ActiveContractsServiceOuterClass; -import com.daml.ledger.javaapi.data.GetActiveContractsRequest; -import com.daml.ledger.javaapi.data.GetActiveContractsResponse; -import com.daml.ledger.javaapi.data.TransactionFilter; +import com.daml.ledger.javaapi.data.*; import com.daml.ledger.rxjava.ActiveContractsClient; +import com.daml.ledger.rxjava.ContractUtil; import com.daml.ledger.rxjava.grpc.helpers.StubHelper; import com.daml.ledger.rxjava.util.ClientPublisherFlowable; import io.grpc.Channel; import io.reactivex.Flowable; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; +import java.util.Set; import org.checkerframework.checker.nullness.qual.NonNull; public class ActiveContractClientImpl implements ActiveContractsClient { @@ -56,4 +58,37 @@ public Flowable getActiveContracts( @NonNull TransactionFilter filter, boolean verbose, @NonNull String accessToken) { return getActiveContracts(filter, verbose, Optional.of(accessToken)); } + + private Flowable> getActiveContracts( + ContractUtil contractUtil, + Set parties, + boolean verbose, + Optional accessToken) { + TransactionFilter filter = contractUtil.transactionFilter(parties); + + Flowable responses = + getActiveContracts(filter, verbose, accessToken); + return responses.map( + response -> { + List activeContracts = new ArrayList<>(); + for (CreatedEvent createdEvent : response.getCreatedEvents()) { + Ct ct = contractUtil.toContract(createdEvent); + activeContracts.add(ct); + } + return new ActiveContracts<>( + response.getOffset().orElse(""), activeContracts, response.getWorkflowId()); + }); + } + + @Override + public Flowable> getActiveContracts( + ContractUtil contractUtil, Set parties, boolean verbose) { + return getActiveContracts(contractUtil, parties, verbose, Optional.empty()); + } + + @Override + public Flowable> getActiveContracts( + ContractUtil contractUtil, Set parties, boolean verbose, String accessToken) { + return getActiveContracts(contractUtil, parties, verbose, Optional.of(accessToken)); + } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java new file mode 100644 index 000000000000..f66393750fa0 --- /dev/null +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java @@ -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 class ActiveContracts implements WorkflowEvent { + + private final String offset; + + private final List activeContracts; + + private final String workflowId; + + public ActiveContracts( + @NonNull String offset, @NonNull List activeContracts, String workflowId) { + this.offset = offset; + this.activeContracts = activeContracts; + this.workflowId = workflowId; + } + + @NonNull + public Optional 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 "GetActiveContractsResponse{" + + "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); + } +} From 14af3cc1be134018045160ae5bf3803e8f0788b0 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 11:48:54 +0100 Subject: [PATCH 07/25] position --- .../data/codegen/InterfaceCompanion.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index 93d71293c1b5..3393f5b146bd 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -24,6 +24,19 @@ public abstract class InterfaceCompanion extends ContractTypeCompan public final ValueDecoder valueDecoder; + /** + * INTERNAL API: this is meant for use by the Java code generator, + * and should not be referenced directly. Applications should refer to the {@code + * INTERFACE} field on generated code for Daml interfaces instead. + */ + protected InterfaceCompanion( + Identifier templateId, Function newContractId, ValueDecoder valueDecoder) { + super(templateId); + this.newContractId = newContractId; + this.valueDecoder = valueDecoder; + } + private Contract fromIdAndRecord( String contractId, Map interfaceViews, @@ -51,17 +64,4 @@ public final Contract fromCreatedEvent(CreatedEvent event) event.getSignatories(), event.getObservers()); } - - /** - * INTERNAL API: this is meant for use by the Java code generator, - * and should not be referenced directly. Applications should refer to the {@code - * INTERFACE} field on generated code for Daml interfaces instead. - */ - protected InterfaceCompanion( - Identifier templateId, Function newContractId, ValueDecoder valueDecoder) { - super(templateId); - this.newContractId = newContractId; - this.valueDecoder = valueDecoder; - } } From 10578197c9e8363a4e230ad405b930e0d24944fc Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 11:49:05 +0100 Subject: [PATCH 08/25] add change log CHANGELOG_BEGIN CHANGELOG_END From ac6fca657812732d7bbd6584bb9f33d35c3177db Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 11:51:12 +0100 Subject: [PATCH 09/25] Ct --- .../main/java/com/daml/ledger/javaapi/data/ActiveContracts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java index f66393750fa0..5366c5c35fe3 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java @@ -56,7 +56,7 @@ public String toString() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ActiveContracts that = (ActiveContracts) o; + ActiveContracts that = (ActiveContracts) o; return Objects.equals(offset, that.offset) && Objects.equals(activeContracts, that.activeContracts) && Objects.equals(workflowId, that.workflowId); From 783383c68e013a217652a814397c6e7df978f0e0 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 11:56:45 +0100 Subject: [PATCH 10/25] Ct --- .../main/java/com/daml/ledger/javaapi/data/ActiveContracts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java index 5366c5c35fe3..e67c132d3d9d 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java @@ -56,7 +56,7 @@ public String toString() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ActiveContracts that = (ActiveContracts) o; + ActiveContracts that = (ActiveContracts) o; return Objects.equals(offset, that.offset) && Objects.equals(activeContracts, that.activeContracts) && Objects.equals(workflowId, that.workflowId); From 6532d5dedd7aa4f7529c1a55b18040ab4d3c96ce Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 12:00:45 +0100 Subject: [PATCH 11/25] format --- .../daml/ledger/javaapi/data/codegen/InterfaceCompanion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index 3393f5b146bd..dddf23286781 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -31,7 +31,7 @@ public abstract class InterfaceCompanion extends ContractTypeCompan * INTERFACE} field on generated code for Daml interfaces instead. */ protected InterfaceCompanion( - Identifier templateId, Function newContractId, ValueDecoder valueDecoder) { + Identifier templateId, Function newContractId, ValueDecoder valueDecoder) { super(templateId); this.newContractId = newContractId; this.valueDecoder = valueDecoder; From 85d8973b5e3bdb7ededd18166f6239822814f34c Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 12:20:29 +0100 Subject: [PATCH 12/25] better exception --- .../java/com/daml/ledger/rxjava/ContractUtil.java | 4 ++-- .../javaapi/data/codegen/InterfaceCompanion.java | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java index fcb52bc5abb4..829b40a998ea 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java @@ -36,7 +36,7 @@ static ContractUtil> of( return new ContractUtil<>(companion::fromCreatedEvent, filter); } - public Ct toContract(CreatedEvent createdEvent) throws IllegalAccessException { + public Ct toContract(CreatedEvent createdEvent) throws IllegalArgumentException { return fromCreatedEvent.apply(createdEvent); } @@ -52,6 +52,6 @@ private TransactionFilter transactionFilter(Filter filter, Set parties) @FunctionalInterface private interface FromCreatedEventFunc { - R apply(T t) throws IllegalAccessException; + R apply(T t) throws IllegalArgumentException; } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index dddf23286781..6fd5600c29b1 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -43,20 +43,22 @@ private Contract fromIdAndRecord( Optional agreementText, Set signatories, Set observers) - throws IllegalAccessException { + throws IllegalArgumentException { Optional maybeRecord = Optional.ofNullable(interfaceViews.get(TEMPLATE_ID)); + Optional maybeFailedRecord = Optional.ofNullable(interfaceViews.get(TEMPLATE_ID)); Id id = newContractId.apply(contractId); - if (maybeRecord.isPresent()) { + if (maybeFailedRecord.isPresent()) { + throw new IllegalArgumentException("Failed interface view for " + TEMPLATE_ID); + } else if (maybeRecord.isPresent()) { View view = valueDecoder.decode(maybeRecord.get()); return new ContractWithInterfaceView<>(id, view, agreementText, signatories, observers); } else { - // TODO: CL handle all exceptional cases - throw new IllegalAccessException("interface view not found. It could be failed"); + throw new IllegalArgumentException("interface view of " + TEMPLATE_ID + " not found."); } } public final Contract fromCreatedEvent(CreatedEvent event) - throws IllegalAccessException { + throws IllegalArgumentException { return fromIdAndRecord( event.getContractId(), event.getInterfaceViews(), From 99868fba35b021304353bef9df3bb7908f7eaa42 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Thu, 6 Oct 2022 14:24:59 +0100 Subject: [PATCH 13/25] fixed test cases --- .../java/codegen/src/it/java/com/daml/TemplateMethodTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java b/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java index 58da382a82f5..f117f0b2395b 100644 --- a/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java +++ b/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java @@ -129,7 +129,7 @@ void contractHasCompanion() { @Test void contractHasToString() { assertEquals( - "tests.template1.SimpleTemplate.Contract(ContractId(cid), " + "Contract(ContractId(cid), " + "tests.template1.SimpleTemplate(Bob), Optional[I agree], [], [])", SimpleTemplate.Contract.fromCreatedEvent(agreementEvent).toString()); } From bc65de3c0b8a31c9b2ea12d8dc74cea76cd2177d Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Mon, 10 Oct 2022 19:26:46 +0100 Subject: [PATCH 14/25] added java doc and rename method to GetContracts --- .../ledger/rxjava/ActiveContractsClient.java | 21 +++++++++++++++ .../com/daml/ledger/rxjava/ContractUtil.java | 5 ++++ .../ledger/rxjava/TransactionsClient.java | 27 +++++++++++++++++-- .../rxjava/grpc/TransactionClientImpl.java | 10 +++---- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java index daeea71a3680..5658b0e1d590 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ActiveContractsClient.java @@ -18,9 +18,30 @@ Flowable getActiveContracts( Flowable getActiveContracts( TransactionFilter filter, boolean verbose, String accessToken); + /** + * Get active Contracts + * + * @param contractUtil Utilities for specified type of contract. It can be instantiated with + * ContractTypeCompanion + * @param parties Set of parties to be included in the transaction filter. + * @param verbose If enabled, values served over the API will contain more information than + * strictly necessary to interpret the data. + * @return Flowable of active contracts of type Ct + */ Flowable> getActiveContracts( ContractUtil contractUtil, Set parties, boolean verbose); + /** + * Get active Contracts + * + * @param contractUtil Utilities for specified type of contract. It can be instantiated with + * ContractTypeCompanion + * @param parties Set of parties to be included in the transaction filter. + * @param verbose If enabled, values served over the API will contain more information than + * strictly necessary to interpret the data. + * @param accessToken Access token for authentication. + * @return Active contracts of type Ct + */ Flowable> getActiveContracts( ContractUtil contractUtil, Set parties, boolean verbose, String accessToken); } diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java index 829b40a998ea..39bacb0ab303 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java @@ -13,6 +13,11 @@ import java.util.function.Function; import java.util.stream.Collectors; +/** + * This class contains utilities to decode a CreatedEvent and create a + * TransactionFilter by provider parties It can only be instantiated with a subtype of + * ContractCompanion + */ public final class ContractUtil { private final FromCreatedEventFunc fromCreatedEvent; diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java index 0aa19ffeaec7..c60ab1398da1 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/TransactionsClient.java @@ -27,10 +27,33 @@ Flowable getTransactions( Flowable getTransactions( LedgerOffset begin, TransactionFilter filter, boolean verbose, String accessToken); - Flowable getTransactions( + /** + * Get contracts + * + * @param contractUtil Utilities for specified type of contract. It can be instantiated with + * ContractTypeCompanion + * @param begin begin offset. + * @param parties Set of parties to be included in the transaction filter. + * @param verbose If enabled, values served over the API will contain more information than + * strictly necessary to interpret the data. + * @return Flowable of contract type Ct + */ + Flowable getContracts( ContractUtil contractUtil, LedgerOffset begin, Set parties, boolean verbose); - Flowable getTransactions( + /** + * Get contracts + * + * @param contractUtil Utilities for specified type of contract. It can be instantiated with + * ContractTypeCompanion + * @param begin begin offset. + * @param parties Set of parties to be included in the transaction filter. + * @param verbose If enabled, values served over the API will contain more information than + * strictly necessary to interpret the data. + * @param accessToken Access token for authentication. + * @return Flowable of contract type Ct + */ + Flowable getContracts( ContractUtil contractUtil, LedgerOffset begin, Set parties, diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java index 541ac89aa3a3..20ce5c44f9c4 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java @@ -74,7 +74,7 @@ public Flowable getTransactions( return getTransactions(begin, end, filter, verbose, Optional.of(accessToken)); } - private Flowable getTransactions( + private Flowable getContracts( ContractUtil contractUtil, LedgerOffset begin, Set parties, @@ -94,19 +94,19 @@ private Flowable getTransactions( } @Override - public Flowable getTransactions( + public Flowable getContracts( ContractUtil contractUtil, LedgerOffset begin, Set parties, boolean verbose) { - return getTransactions(contractUtil, begin, parties, verbose, Optional.empty()); + return getContracts(contractUtil, begin, parties, verbose, Optional.empty()); } @Override - public Flowable getTransactions( + public Flowable getContracts( ContractUtil contractUtil, LedgerOffset begin, Set parties, boolean verbose, String accessToken) { - return getTransactions(contractUtil, begin, parties, verbose, Optional.of(accessToken)); + return getContracts(contractUtil, begin, parties, verbose, Optional.of(accessToken)); } private Flowable getTransactions( From ecb1ea891d4b190abfe6f92548bca6b37952f65c Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 09:52:02 +0100 Subject: [PATCH 15/25] address Stephen's comments --- .../rxjava/grpc/TransactionClientImpl.java | 14 ++++----- .../ledger/javaapi/data/ActiveContracts.java | 4 +-- .../data/codegen/ContractCompanion.java | 4 ++- .../data/codegen/InterfaceCompanion.java | 29 +++++++++++++------ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java index 20ce5c44f9c4..c4ef363e0baf 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/TransactionClientImpl.java @@ -17,6 +17,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.Future; +import java.util.stream.Collectors; public final class TransactionClientImpl implements TransactionsClient { private final String ledgerId; @@ -83,13 +84,12 @@ private Flowable getContracts( TransactionFilter filter = contractUtil.transactionFilter(parties); Flowable transactions = getTransactions(begin, filter, verbose, accessToken); Flowable createdEvents = - transactions - .concatMapIterable(Transaction::getEvents) - .flatMap( - event -> - (event instanceof CreatedEvent) - ? Flowable.just((CreatedEvent) event) - : Flowable.empty()); + transactions.concatMapIterable( + tx -> + tx.getEvents().stream() + .filter(e -> e instanceof CreatedEvent) + .map(e -> (CreatedEvent) e) + .collect(Collectors.toList())); return createdEvents.map(contractUtil::toContract); } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java index e67c132d3d9d..7baaa27e5e25 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ActiveContracts.java @@ -8,7 +8,7 @@ import java.util.Optional; import org.checkerframework.checker.nullness.qual.NonNull; -public class ActiveContracts implements WorkflowEvent { +public final class ActiveContracts implements WorkflowEvent { private final String offset; @@ -41,7 +41,7 @@ public String getWorkflowId() { @Override public String toString() { - return "GetActiveContractsResponse{" + return "ActiveContracts{" + "offset='" + offset + '\'' diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index f87a79fdbfef..a847e13afa9f 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -3,8 +3,10 @@ package com.daml.ledger.javaapi.data.codegen; -import com.daml.ledger.javaapi.data.*; +import com.daml.ledger.javaapi.data.CreatedEvent; import com.daml.ledger.javaapi.data.DamlRecord; +import com.daml.ledger.javaapi.data.Identifier; +import com.daml.ledger.javaapi.data.Value; import java.util.Optional; import java.util.Set; import java.util.function.Function; diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index 6fd5600c29b1..ba0de7586abb 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -20,7 +20,7 @@ */ public abstract class InterfaceCompanion extends ContractTypeCompanion { - protected final Function newContractId; + private final Function newContractId; public final ValueDecoder valueDecoder; @@ -47,14 +47,25 @@ private Contract fromIdAndRecord( Optional maybeRecord = Optional.ofNullable(interfaceViews.get(TEMPLATE_ID)); Optional maybeFailedRecord = Optional.ofNullable(interfaceViews.get(TEMPLATE_ID)); Id id = newContractId.apply(contractId); - if (maybeFailedRecord.isPresent()) { - throw new IllegalArgumentException("Failed interface view for " + TEMPLATE_ID); - } else if (maybeRecord.isPresent()) { - View view = valueDecoder.decode(maybeRecord.get()); - return new ContractWithInterfaceView<>(id, view, agreementText, signatories, observers); - } else { - throw new IllegalArgumentException("interface view of " + TEMPLATE_ID + " not found."); - } + + return maybeRecord + .map( + record -> { + View view = valueDecoder.decode(record); + return new ContractWithInterfaceView<>( + id, view, agreementText, signatories, observers); + }) + .orElseThrow( + () -> + maybeFailedRecord + .map( + record -> + new IllegalArgumentException( + "Failed interface view for " + TEMPLATE_ID)) + .orElseThrow( + () -> + new IllegalArgumentException( + "interface view of " + TEMPLATE_ID + " not found."))); } public final Contract fromCreatedEvent(CreatedEvent event) From ec9fc8f18be6b477db10af299342d5847f706255 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 10:54:03 +0100 Subject: [PATCH 16/25] address Stephen's comments --- .../daml/ledger/javaapi/data/codegen/Contract.java | 12 ++++++++++-- .../javaapi/data/codegen/ContractCompanion.java | 5 +---- .../javaapi/data/codegen/ContractTypeCompanion.java | 5 ++++- .../data/codegen/ContractWithInterfaceView.java | 9 +++++++++ .../javaapi/data/codegen/InterfaceCompanion.java | 9 ++++++--- .../codegen/backend/java/inner/ContractClass.scala | 13 +++++++++++++ .../codegen/backend/java/inner/InterfaceClass.scala | 3 ++- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java index c6789c78cb02..469e433d0742 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/Contract.java @@ -48,6 +48,9 @@ protected Contract( this.observers = observers; } + // concrete 1st type param would need a self-reference type param in Contract + protected abstract ContractTypeCompanion getCompanion(); + @Override public boolean equals(Object object) { if (this == object) { @@ -77,7 +80,12 @@ public int hashCode() { @Override public String toString() { return String.format( - "Contract(%s, %s, %s, %s, %s)", - this.id, this.data, this.agreementText, this.signatories, this.observers); + "%s.Contract(%s, %s, %s, %s, %s)", + getCompanion().TEMPLATE_CLASS_NAME, + this.id, + this.data, + this.agreementText, + this.signatories, + this.observers); } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index a847e13afa9f..d3c2974def5b 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -25,8 +25,6 @@ * the template, whose instances contain only the payload. */ public abstract class ContractCompanion extends ContractTypeCompanion { - final String templateClassName; // not something we want outside this package - protected final Function newContractId; protected final Function fromValue; @@ -82,8 +80,7 @@ protected ContractCompanion( Identifier templateId, Function newContractId, Function fromValue) { - super(templateId); - this.templateClassName = templateClassName; + super(templateId, templateClassName); this.newContractId = newContractId; this.fromValue = fromValue; } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java index d26277d83e93..8ff8e3d591d0 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java @@ -10,13 +10,16 @@ public abstract class ContractTypeCompanion { /** The full template ID of the template or interface that defined this companion. */ public final Identifier TEMPLATE_ID; + protected final String TEMPLATE_CLASS_NAME; + /** * INTERNAL API: this is meant for use by {@link ContractCompanion} and {@link * InterfaceCompanion}, and should not be referenced directly. Applications should refer * to code-generated {@code COMPANION} and {@code INTERFACE} fields specific to the template or * interface in question instead. */ - protected ContractTypeCompanion(Identifier templateId) { + protected ContractTypeCompanion(Identifier templateId, String templateClassName) { TEMPLATE_ID = templateId; + TEMPLATE_CLASS_NAME = templateClassName; } } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java index f6668ad09ac0..6d060592119e 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithInterfaceView.java @@ -8,13 +8,22 @@ final class ContractWithInterfaceView extends Contract { + private final ContractTypeCompanion contractTypeCompanion; + ContractWithInterfaceView( + ContractTypeCompanion contractTypeCompanion, Id id, View interfaceView, Optional agreementText, Set signatories, Set observers) { super(id, interfaceView, agreementText, signatories, observers); + this.contractTypeCompanion = contractTypeCompanion; + } + + @Override + protected ContractTypeCompanion getCompanion() { + return contractTypeCompanion; } @Override diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index ba0de7586abb..8a26c36b4f2f 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -31,8 +31,11 @@ public abstract class InterfaceCompanion extends ContractTypeCompan * INTERFACE} field on generated code for Daml interfaces instead. */ protected InterfaceCompanion( - Identifier templateId, Function newContractId, ValueDecoder valueDecoder) { - super(templateId); + String templateClassName, + Identifier templateId, + Function newContractId, + ValueDecoder valueDecoder) { + super(templateId, templateClassName); this.newContractId = newContractId; this.valueDecoder = valueDecoder; } @@ -53,7 +56,7 @@ private Contract fromIdAndRecord( record -> { View view = valueDecoder.decode(record); return new ContractWithInterfaceView<>( - id, view, agreementText, signatories, observers); + this, id, view, agreementText, signatories, observers); }) .orElseThrow( () -> diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala index 51b14f4b3d22..004b28f6fd61 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/ContractClass.scala @@ -107,6 +107,17 @@ object ContractClass { private[this] val contractIdClassName = ClassName bestGuess "ContractId" + private[this] def generateGetCompanion(templateClassName: ClassName): MethodSpec = { + ClassGenUtils.generateGetCompanion( + ParameterizedTypeName.get( + ClassName get classOf[javaapi.data.codegen.ContractTypeCompanion[_, _]], + templateClassName, + templateClassName, + ), + companionFieldName, + ) + } + def create( templateClassName: ClassName, key: Option[Type], @@ -159,6 +170,8 @@ object ContractClass { classBuilder.addMethod(constructor) val contractClassName = ClassName.bestGuess("Contract") + classBuilder + .addMethod(generateGetCompanion(templateClassName)) new Builder( classBuilder, contractClassName, diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index 30e9b7d4cf3f..72a4cf14c2b6 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -105,7 +105,8 @@ object InterfaceClass extends StrictLogging { .constructorBuilder() // intentionally package-private .addStatement( - "super($T.$N, $T::new, $T.$L())", + "super($>$Z$S, $T.$N, $T::new, $T.$L())", + interfaceName, interfaceName, ClassGenUtils.templateIdFieldName, contractIdClassName, From f9c0fa463f8bbc07cc5d3b991b345354d888a9dd Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 10:57:38 +0100 Subject: [PATCH 17/25] address Stephen's comments --- .../ledger/javaapi/data/codegen/ContractWithKey.java | 10 ++++++++-- .../src/it/java/com/daml/TemplateMethodTest.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java index 19aa706c0e63..dc548e89c504 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractWithKey.java @@ -44,7 +44,13 @@ public final int hashCode() { @Override public final String toString() { return String.format( - "Contract(%s, %s, %s, %s, %s, %s)", - this.id, this.data, this.agreementText, this.key, this.signatories, this.observers); + "%s.Contract(%s, %s, %s, %s, %s, %s)", + getCompanion().TEMPLATE_CLASS_NAME, + this.id, + this.data, + this.agreementText, + this.key, + this.signatories, + this.observers); } } diff --git a/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java b/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java index f117f0b2395b..58da382a82f5 100644 --- a/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java +++ b/language-support/java/codegen/src/it/java/com/daml/TemplateMethodTest.java @@ -129,7 +129,7 @@ void contractHasCompanion() { @Test void contractHasToString() { assertEquals( - "Contract(ContractId(cid), " + "tests.template1.SimpleTemplate.Contract(ContractId(cid), " + "tests.template1.SimpleTemplate(Bob), Optional[I agree], [], [])", SimpleTemplate.Contract.fromCreatedEvent(agreementEvent).toString()); } From 7b45bd31f570a1e955b88fef2470df30a5c9334a Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 14:04:50 +0100 Subject: [PATCH 18/25] remove unused import --- .../daml/lf/codegen/backend/java/inner/InterfaceClass.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index 9415e4fabdcb..a1a99024a509 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -4,7 +4,6 @@ package com.daml.lf.codegen.backend.java.inner import com.daml.ledger.javaapi.data.codegen.InterfaceCompanion -import com.daml.lf.codegen.backend.java.inner.InterfaceClass.companionClassName import com.daml.lf.codegen.backend.java.inner.TemplateClass.toChoiceNameField import com.daml.lf.data.Ref.{ChoiceName, PackageId, QualifiedName} import com.daml.lf.typesig From f8f58ba9f9fb34faebba6d703082cf2f970c16c7 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 14:23:02 +0100 Subject: [PATCH 19/25] format --- .../ledger/javaapi/data/codegen/ContractTypeCompanion.java | 4 +++- .../daml/ledger/javaapi/data/codegen/InterfaceCompanion.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java index eadb8fdeeb51..a4649c811dea 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java @@ -35,7 +35,9 @@ public abstract class ContractTypeCompanion { * interface in question instead. */ protected ContractTypeCompanion( - Identifier templateId, String templateClassName, List> choices) { + Identifier templateId, + String templateClassName, + List> choices) { TEMPLATE_ID = templateId; TEMPLATE_CLASS_NAME = templateClassName; this.choices = diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java index 1571805a3a0e..2d8fb2d33bda 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/InterfaceCompanion.java @@ -5,12 +5,12 @@ import com.daml.ledger.javaapi.data.*; import com.daml.ledger.javaapi.data.DamlRecord; +import com.daml.ledger.javaapi.data.Identifier; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Function; -import com.daml.ledger.javaapi.data.Identifier; -import java.util.List; /** * Metadata and utilities associated with an interface as a whole. Its subclasses serve to From 2e000601df9a0339ee8ffbf18d665e7c2cce7fdb Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 15:49:09 +0100 Subject: [PATCH 20/25] address Stephen's comments --- .../ledger/rxjava/grpc/ActiveContractClientImpl.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java index a82802da1b2b..ff3cd7de9d88 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/ActiveContractClientImpl.java @@ -13,10 +13,10 @@ import com.daml.ledger.rxjava.util.ClientPublisherFlowable; import io.grpc.Channel; import io.reactivex.Flowable; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.NonNull; public class ActiveContractClientImpl implements ActiveContractsClient { @@ -70,11 +70,10 @@ private Flowable> getActiveContracts( getActiveContracts(filter, verbose, accessToken); return responses.map( response -> { - List activeContracts = new ArrayList<>(); - for (CreatedEvent createdEvent : response.getCreatedEvents()) { - Ct ct = contractUtil.toContract(createdEvent); - activeContracts.add(ct); - } + List activeContracts = + response.getCreatedEvents().stream() + .map(contractUtil::toContract) + .collect(Collectors.toList()); return new ActiveContracts<>( response.getOffset().orElse(""), activeContracts, response.getWorkflowId()); }); From 73ee8869bae426be4285dfbf1471331494d543da Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Tue, 11 Oct 2022 19:57:57 +0100 Subject: [PATCH 21/25] address Stephen's comments --- .../src/main/java/com/daml/ledger/rxjava/ContractUtil.java | 2 +- .../daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java | 2 +- .../daml/lf/codegen/backend/java/inner/InterfaceClass.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java index 39bacb0ab303..e13e2afec5b2 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java @@ -49,7 +49,7 @@ public TransactionFilter transactionFilter(Set parties) { return transactionFilter(filter, parties); } - private TransactionFilter transactionFilter(Filter filter, Set parties) { + private static TransactionFilter transactionFilter(Filter filter, Set parties) { Map partyToFilters = parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter)); return new FiltersByParty(partyToFilters); diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java index a4649c811dea..abe4b530c93a 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractTypeCompanion.java @@ -14,7 +14,7 @@ public abstract class ContractTypeCompanion { /** The full template ID of the template or interface that defined this companion. */ public final Identifier TEMPLATE_ID; - protected final String TEMPLATE_CLASS_NAME; + final String TEMPLATE_CLASS_NAME; /** * The provides a mapping of choice name to Choice. diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index a1a99024a509..13933eefc858 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -121,7 +121,7 @@ object InterfaceClass extends StrictLogging { .constructorBuilder() // intentionally package-private .addStatement( - "super($>$Z$S, $T.$N, $T::new, $T.$L(), $T.of($L))", + "super($>$Z$S, $T.$N, $T::new, $T.$L(), $T.of($L))$<$Z", interfaceName, interfaceName, ClassGenUtils.templateIdFieldName, From 5e70489b9e0b917f945adb163f4bd1af26f98b19 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Wed, 12 Oct 2022 11:32:31 +0100 Subject: [PATCH 22/25] Make some codegen code to be java 8 compatible; Modify IouMain to use the new getActiveContracts. to address Stephen's comments --- docs/source/app-dev/bindings-java/codegen.rst | 2 +- .../main/java/com/daml/quickstart/iou/IouMain.java | 11 ++++++----- .../java/com/daml/ledger/rxjava/ContractUtil.java | 10 ++++++---- .../javaapi/data/codegen/ContractCompanion.java | 2 +- .../ledger/javaapi/data/codegen/ValueDecoder.java | 2 +- .../codegen/backend/java/inner/InterfaceClass.scala | 5 +++-- .../lf/codegen/backend/java/inner/TemplateClass.scala | 5 +++-- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/source/app-dev/bindings-java/codegen.rst b/docs/source/app-dev/bindings-java/codegen.rst index 96f2f2360c7b..96003c4e9dec 100644 --- a/docs/source/app-dev/bindings-java/codegen.rst +++ b/docs/source/app-dev/bindings-java/codegen.rst @@ -187,7 +187,7 @@ A file is generated that defines five Java classes and an interface: public static final ContractCompanion.WithKey COMPANION = new ContractCompanion.WithKey<>("com.acme.templates.Bar", - TEMPLATE_ID, ContractId::new, Bar::fromValue, Contract::new, e -> BarKey.fromValue(e), List.of(CHOICE_Archive)); + TEMPLATE_ID, ContractId::new, Bar::fromValue, Contract::new, e -> BarKey.fromValue(e), Arrays.asList(CHOICE_Archive)); public final String owner; public final String name; diff --git a/docs/source/app-dev/bindings-java/quickstart/template-root/src/main/java/com/daml/quickstart/iou/IouMain.java b/docs/source/app-dev/bindings-java/quickstart/template-root/src/main/java/com/daml/quickstart/iou/IouMain.java index a75c2d5fb48d..76f4bdc67cf6 100644 --- a/docs/source/app-dev/bindings-java/quickstart/template-root/src/main/java/com/daml/quickstart/iou/IouMain.java +++ b/docs/source/app-dev/bindings-java/quickstart/template-root/src/main/java/com/daml/quickstart/iou/IouMain.java @@ -4,6 +4,7 @@ package com.daml.quickstart.iou; import com.daml.ledger.javaapi.data.*; +import com.daml.ledger.rxjava.ContractUtil; import com.daml.ledger.rxjava.DamlLedgerClient; import com.daml.ledger.rxjava.LedgerClient; import com.daml.quickstart.model.iou.Iou; @@ -59,14 +60,14 @@ public static void main(String[] args) { client .getActiveContractSetClient() - .getActiveContracts(iouFilter, true) + .getActiveContracts(ContractUtil.of(Iou.COMPANION), Collections.singleton(party), true) .blockingForEach( - response -> { - response + activeContracts -> { + activeContracts .getOffset() .ifPresent(offset -> acsOffset.set(new LedgerOffset.Absolute(offset))); - response.getCreatedEvents().stream() - .map(Iou.Contract::fromCreatedEvent) + activeContracts + .getContracts() .forEach( contract -> { long id = idCounter.getAndIncrement(); diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java index e13e2afec5b2..79216495bc5d 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/ContractUtil.java @@ -28,16 +28,18 @@ private ContractUtil(FromCreatedEventFunc fromCreatedEvent, Fi this.filter = filter; } - static ContractUtil of(ContractCompanion companion) { - Filter filter = new InclusiveFilter(Set.of(companion.TEMPLATE_ID), Collections.emptyMap()); + public static ContractUtil of(ContractCompanion companion) { + Filter filter = + new InclusiveFilter(Collections.singleton(companion.TEMPLATE_ID), Collections.emptyMap()); return new ContractUtil<>(companion::fromCreatedEvent, filter); } - static ContractUtil> of( + public static ContractUtil> of( InterfaceCompanion companion) { Filter filter = new InclusiveFilter( - Collections.emptySet(), Map.of(companion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); + Collections.emptySet(), + Collections.singletonMap(companion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW)); return new ContractUtil<>(companion::fromCreatedEvent, filter); } diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index bb0b3c6838da..d1f3d0d7ba16 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -38,7 +38,7 @@ public abstract class ContractCompanion extends ContractTypeCompan */ public static ValueDecoder valueDecoder( ContractCompanion, Data> companion) { - return new ValueDecoder<>() { + return new ValueDecoder() { @Override public Data decode(Value value) { DamlRecord record = diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java index b2de01af1fdc..ed3ae4d4b25a 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java @@ -50,7 +50,7 @@ default ContractId fromContractId(String contractId) { */ @Deprecated static ValueDecoder fromFunction(Function fromValue) { - return new ValueDecoder<>() { + return new ValueDecoder() { @Override public A decode(Value value) { return fromValue.apply(value); diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index 13933eefc858..b7fae28835b7 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -12,6 +12,7 @@ import com.squareup.javapoet._ import com.typesafe.scalalogging.StrictLogging import scalaz.-\/ +import java.util import javax.lang.model.element.Modifier import scala.jdk.CollectionConverters._ @@ -121,14 +122,14 @@ object InterfaceClass extends StrictLogging { .constructorBuilder() // intentionally package-private .addStatement( - "super($>$Z$S, $T.$N, $T::new, $T.$L(), $T.of($L))$<$Z", + "super($>$Z$S, $T.$N, $T::new, $T.$L(), $T.asList($L))$<$Z", interfaceName, interfaceName, ClassGenUtils.templateIdFieldName, contractIdClassName, interfaceViewTypeName, "valueDecoder", - classOf[java.util.List[_]], + classOf[util.Arrays], CodeBlock .join( choiceNames diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala index af6842c40142..5d5e4825fc35 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala @@ -17,6 +17,7 @@ import com.typesafe.scalalogging.StrictLogging import scalaz.{\/, \/-} import scalaz.syntax.std.option._ +import java.util import javax.lang.model.element.Modifier import scala.jdk.CollectionConverters._ @@ -525,7 +526,7 @@ private[inner] object TemplateClass extends StrictLogging { Modifier.PUBLIC, ) .initializer( - "$Znew $T<>($>$Z$S,$W$N, $T::new, $N -> $T.templateValueDecoder().decode($N), $T::new, $T.of($L)" + keyParams + "$<)", + "$Znew $T<>($>$Z$S,$W$N, $T::new, $N -> $T.templateValueDecoder().decode($N), $T::new, $T.asList($L)" + keyParams + "$<)", Seq( fieldClass, templateClassName, @@ -535,7 +536,7 @@ private[inner] object TemplateClass extends StrictLogging { templateClassName, valueDecoderLambdaArgName, contractName, - classOf[java.util.List[_]], + classOf[util.Arrays], CodeBlock .join( choiceNames From c8b22003565d8193439a120337fbf608adb6ef54 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Wed, 12 Oct 2022 17:17:01 +0100 Subject: [PATCH 23/25] use 1.11, no need to be java 8 compatible --- docs/source/app-dev/bindings-java/codegen.rst | 2 +- .../app-dev/bindings-java/quickstart/template-root/pom.xml | 4 ++-- .../daml/ledger/javaapi/data/codegen/ContractCompanion.java | 2 +- .../com/daml/ledger/javaapi/data/codegen/ValueDecoder.java | 2 +- .../daml/lf/codegen/backend/java/inner/InterfaceClass.scala | 4 ++-- .../daml/lf/codegen/backend/java/inner/TemplateClass.scala | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/source/app-dev/bindings-java/codegen.rst b/docs/source/app-dev/bindings-java/codegen.rst index 96003c4e9dec..96f2f2360c7b 100644 --- a/docs/source/app-dev/bindings-java/codegen.rst +++ b/docs/source/app-dev/bindings-java/codegen.rst @@ -187,7 +187,7 @@ A file is generated that defines five Java classes and an interface: public static final ContractCompanion.WithKey COMPANION = new ContractCompanion.WithKey<>("com.acme.templates.Bar", - TEMPLATE_ID, ContractId::new, Bar::fromValue, Contract::new, e -> BarKey.fromValue(e), Arrays.asList(CHOICE_Archive)); + TEMPLATE_ID, ContractId::new, Bar::fromValue, Contract::new, e -> BarKey.fromValue(e), List.of(CHOICE_Archive)); public final String owner; public final String name; diff --git a/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml b/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml index 786651329093..673aedffbb0f 100644 --- a/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml +++ b/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml @@ -9,8 +9,8 @@ UTF-8 - 1.8 - 1.8 + 1.11 + 1.11 ${project.build.directory}/generated-sources/iou localhost 6865 diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java index d1f3d0d7ba16..bb0b3c6838da 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ContractCompanion.java @@ -38,7 +38,7 @@ public abstract class ContractCompanion extends ContractTypeCompan */ public static ValueDecoder valueDecoder( ContractCompanion, Data> companion) { - return new ValueDecoder() { + return new ValueDecoder<>() { @Override public Data decode(Value value) { DamlRecord record = diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java index ed3ae4d4b25a..b2de01af1fdc 100644 --- a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/codegen/ValueDecoder.java @@ -50,7 +50,7 @@ default ContractId fromContractId(String contractId) { */ @Deprecated static ValueDecoder fromFunction(Function fromValue) { - return new ValueDecoder() { + return new ValueDecoder<>() { @Override public A decode(Value value) { return fromValue.apply(value); diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index b7fae28835b7..dd631bb3cddf 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -122,14 +122,14 @@ object InterfaceClass extends StrictLogging { .constructorBuilder() // intentionally package-private .addStatement( - "super($>$Z$S, $T.$N, $T::new, $T.$L(), $T.asList($L))$<$Z", + "super($>$Z$S, $T.$N, $T::new, $T.$L(), $T.of($L))$<$Z", interfaceName, interfaceName, ClassGenUtils.templateIdFieldName, contractIdClassName, interfaceViewTypeName, "valueDecoder", - classOf[util.Arrays], + classOf[List[_]], CodeBlock .join( choiceNames diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala index 5d5e4825fc35..fd4375dec4bd 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala @@ -526,7 +526,7 @@ private[inner] object TemplateClass extends StrictLogging { Modifier.PUBLIC, ) .initializer( - "$Znew $T<>($>$Z$S,$W$N, $T::new, $N -> $T.templateValueDecoder().decode($N), $T::new, $T.asList($L)" + keyParams + "$<)", + "$Znew $T<>($>$Z$S,$W$N, $T::new, $N -> $T.templateValueDecoder().decode($N), $T::new, $T.of($L)" + keyParams + "$<)", Seq( fieldClass, templateClassName, @@ -536,7 +536,7 @@ private[inner] object TemplateClass extends StrictLogging { templateClassName, valueDecoderLambdaArgName, contractName, - classOf[util.Arrays], + classOf[List[_]], CodeBlock .join( choiceNames From 922d1fd996d51059e6bab48e209f69102693b5c3 Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Wed, 12 Oct 2022 17:36:41 +0100 Subject: [PATCH 24/25] revert --- .../daml/lf/codegen/backend/java/inner/InterfaceClass.scala | 3 +-- .../daml/lf/codegen/backend/java/inner/TemplateClass.scala | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala index dd631bb3cddf..13933eefc858 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/InterfaceClass.scala @@ -12,7 +12,6 @@ import com.squareup.javapoet._ import com.typesafe.scalalogging.StrictLogging import scalaz.-\/ -import java.util import javax.lang.model.element.Modifier import scala.jdk.CollectionConverters._ @@ -129,7 +128,7 @@ object InterfaceClass extends StrictLogging { contractIdClassName, interfaceViewTypeName, "valueDecoder", - classOf[List[_]], + classOf[java.util.List[_]], CodeBlock .join( choiceNames diff --git a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala index fd4375dec4bd..af6842c40142 100644 --- a/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala +++ b/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen/backend/java/inner/TemplateClass.scala @@ -17,7 +17,6 @@ import com.typesafe.scalalogging.StrictLogging import scalaz.{\/, \/-} import scalaz.syntax.std.option._ -import java.util import javax.lang.model.element.Modifier import scala.jdk.CollectionConverters._ @@ -536,7 +535,7 @@ private[inner] object TemplateClass extends StrictLogging { templateClassName, valueDecoderLambdaArgName, contractName, - classOf[List[_]], + classOf[java.util.List[_]], CodeBlock .join( choiceNames From 24bbec2d35ccb6c718c45e980d7019857f9d826a Mon Sep 17 00:00:00 2001 From: Chun Lok Ling Date: Wed, 12 Oct 2022 18:47:03 +0100 Subject: [PATCH 25/25] 11 not 1.11 --- .../app-dev/bindings-java/quickstart/template-root/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml b/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml index 673aedffbb0f..66719a86c11e 100644 --- a/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml +++ b/docs/source/app-dev/bindings-java/quickstart/template-root/pom.xml @@ -9,8 +9,8 @@ UTF-8 - 1.11 - 1.11 + 11 + 11 ${project.build.directory}/generated-sources/iou localhost 6865