mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
update canton to 20231129.11598.0.v78e63449/2.8.0-snapshot.20231129.11598.0.v78e63449 (#17950)
* update canton to 20231129.11598.0.v78e63449/2.8.0-snapshot.20231129.11598.0.v78e63449 CHANGELOG_BEGIN CHANGELOG_END * Add missing dependency * Update canton/BUILD.bazel --------- Co-authored-by: Azure Pipelines Daml Build <support@digitalasset.com> Co-authored-by: Simon Maxen <simon.maxen@digitalasset.com> Co-authored-by: Moisés Ackerman <6054733+akrmn@users.noreply.github.com>
This commit is contained in:
parent
72cefd6f09
commit
e14a9a8fed
@ -319,6 +319,7 @@ scala_library(
|
||||
"//canton:community_util-logging",
|
||||
"//canton:daml-common-staging_daml-errors",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-lf/transaction:transaction_proto_java",
|
||||
"//daml-lf/transaction:value_proto_java",
|
||||
|
@ -1,4 +1,4 @@
|
||||
sdk-version: 2.8.0-snapshot.20231125.12402.0.v9caae0b1
|
||||
sdk-version: 2.9.0-snapshot.20231128.12429.0.vcd189081
|
||||
sandbox-options:
|
||||
- --wall-clock-time
|
||||
name: contact
|
||||
|
@ -1,4 +1,4 @@
|
||||
sdk-version: 2.8.0-snapshot.20231125.12402.0.v9caae0b1
|
||||
sdk-version: 2.9.0-snapshot.20231128.12429.0.vcd189081
|
||||
sandbox-options:
|
||||
- --wall-clock-time
|
||||
name: message
|
||||
|
@ -4,7 +4,8 @@
|
||||
package com.digitalasset.canton.protocol
|
||||
|
||||
import cats.syntax.either.*
|
||||
import com.daml.lf.value.ValueCoder.{CidEncoder as LfDummyCidEncoder}
|
||||
import com.daml.lf.transaction.Util
|
||||
import com.daml.lf.value.ValueCoder.CidEncoder as LfDummyCidEncoder
|
||||
import com.daml.lf.value.{ValueCoder, ValueOuterClass}
|
||||
import com.digitalasset.canton.serialization.ProtoConverter
|
||||
import com.digitalasset.canton.serialization.ProtoConverter.ParsingResult
|
||||
@ -54,7 +55,7 @@ object GlobalKeySerialization {
|
||||
)
|
||||
|
||||
globalKey <- LfGlobalKey
|
||||
.build(templateId, versionedKey.unversioned)
|
||||
.build(templateId, versionedKey.unversioned, Util.sharedKey(versionedKey.version))
|
||||
.leftMap(err =>
|
||||
ProtoDeserializationError.ValueDeserializationError("GlobalKey.key", err.toString)
|
||||
)
|
||||
|
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ActiveContracts<Ct> {
|
||||
|
||||
public final Optional<String> offset;
|
||||
|
||||
public final List<Ct> activeContracts;
|
||||
|
||||
public final String workflowId;
|
||||
|
||||
public ActiveContracts(
|
||||
@NonNull Optional<String> offset,
|
||||
@NonNull List<Ct> activeContracts,
|
||||
@NonNull String workflowId) {
|
||||
this.offset = offset;
|
||||
this.activeContracts = activeContracts;
|
||||
this.workflowId = workflowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ActiveContracts{"
|
||||
+ "offset='"
|
||||
+ offset
|
||||
+ '\''
|
||||
+ ", activeContracts="
|
||||
+ activeContracts
|
||||
+ ", workflowId="
|
||||
+ workflowId
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ActiveContracts<?> that = (ActiveContracts<?>) o;
|
||||
return offset.equals(that.offset)
|
||||
&& Objects.equals(activeContracts, that.activeContracts)
|
||||
&& Objects.equals(workflowId, that.workflowId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(offset, activeContracts, workflowId);
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.EventOuterClass;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ArchivedEvent implements Event {
|
||||
|
||||
private final List<String> witnessParties;
|
||||
|
||||
private final String eventId;
|
||||
|
||||
private final Identifier templateId;
|
||||
|
||||
private final String contractId;
|
||||
|
||||
public ArchivedEvent(
|
||||
@NonNull List<@NonNull String> witnessParties,
|
||||
@NonNull String eventId,
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull String contractId) {
|
||||
this.witnessParties = witnessParties;
|
||||
this.eventId = eventId;
|
||||
this.templateId = templateId;
|
||||
this.contractId = contractId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<@NonNull String> getWitnessParties() {
|
||||
return witnessParties;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getContractId() {
|
||||
return contractId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ArchivedEvent that = (ArchivedEvent) o;
|
||||
return Objects.equals(witnessParties, that.witnessParties)
|
||||
&& Objects.equals(eventId, that.eventId)
|
||||
&& Objects.equals(templateId, that.templateId)
|
||||
&& Objects.equals(contractId, that.contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(witnessParties, eventId, templateId, contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ArchivedEvent{"
|
||||
+ "witnessParties="
|
||||
+ witnessParties
|
||||
+ ", eventId='"
|
||||
+ eventId
|
||||
+ '\''
|
||||
+ ", templateId="
|
||||
+ templateId
|
||||
+ ", contractId='"
|
||||
+ contractId
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
|
||||
public EventOuterClass.ArchivedEvent toProto() {
|
||||
return EventOuterClass.ArchivedEvent.newBuilder()
|
||||
.setContractId(getContractId())
|
||||
.setEventId(getEventId())
|
||||
.setTemplateId(getTemplateId().toProto())
|
||||
.addAllWitnessParties(this.getWitnessParties())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ArchivedEvent fromProto(EventOuterClass.ArchivedEvent archivedEvent) {
|
||||
return new ArchivedEvent(
|
||||
archivedEvent.getWitnessPartiesList(),
|
||||
archivedEvent.getEventId(),
|
||||
Identifier.fromProto(archivedEvent.getTemplateId()),
|
||||
archivedEvent.getContractId());
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Bool extends Value {
|
||||
|
||||
private final boolean value;
|
||||
|
||||
public static final Bool TRUE = new Bool(true);
|
||||
public static final Bool FALSE = new Bool(false);
|
||||
|
||||
// TODO i15639 make private; delete equals/hashCode
|
||||
/** @deprecated Use {@link #of} instead; since Daml 2.5.0 */
|
||||
@Deprecated
|
||||
public Bool(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Bool of(boolean value) {
|
||||
return value ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setBool(this.value).build();
|
||||
}
|
||||
|
||||
public boolean isValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return isValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Bool{" + "value=" + value + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Bool bool = (Bool) o;
|
||||
return value == bool.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandCompletionServiceOuterClass;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Checkpoint {
|
||||
|
||||
private final Instant recordTime;
|
||||
|
||||
private final LedgerOffset offset;
|
||||
|
||||
public Checkpoint(@NonNull Instant recordTime, @NonNull LedgerOffset offset) {
|
||||
this.recordTime = recordTime;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static Checkpoint fromProto(CommandCompletionServiceOuterClass.Checkpoint checkpoint) {
|
||||
LedgerOffset offset = LedgerOffset.fromProto(checkpoint.getOffset());
|
||||
return new Checkpoint(
|
||||
Instant.ofEpochSecond(
|
||||
checkpoint.getRecordTime().getSeconds(), checkpoint.getRecordTime().getNanos()),
|
||||
offset);
|
||||
}
|
||||
|
||||
public CommandCompletionServiceOuterClass.Checkpoint toProto() {
|
||||
return CommandCompletionServiceOuterClass.Checkpoint.newBuilder()
|
||||
.setRecordTime(
|
||||
com.google.protobuf.Timestamp.newBuilder()
|
||||
.setSeconds(this.recordTime.getEpochSecond())
|
||||
.setNanos(this.recordTime.getNano())
|
||||
.build())
|
||||
.setOffset(this.offset.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
public @NonNull Instant getRecordTime() {
|
||||
return recordTime;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public LedgerOffset getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Checkpoint{" + "recordTime=" + recordTime + ", offset=" + offset + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Checkpoint that = (Checkpoint) o;
|
||||
return Objects.equals(recordTime, that.recordTime) && Objects.equals(offset, that.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(recordTime, offset);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import com.daml.ledger.javaapi.data.codegen.HasCommands;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class Command implements HasCommands {
|
||||
|
||||
abstract Identifier getTemplateId();
|
||||
|
||||
@Override
|
||||
public final List<Command> commands() {
|
||||
return List.of(this);
|
||||
}
|
||||
|
||||
public static Command fromProtoCommand(CommandsOuterClass.Command command) {
|
||||
switch (command.getCommandCase()) {
|
||||
case CREATE:
|
||||
return CreateCommand.fromProto(command.getCreate());
|
||||
case EXERCISE:
|
||||
return ExerciseCommand.fromProto(command.getExercise());
|
||||
case CREATEANDEXERCISE:
|
||||
return CreateAndExerciseCommand.fromProto(command.getCreateAndExercise());
|
||||
case EXERCISEBYKEY:
|
||||
return ExerciseByKeyCommand.fromProto(command.getExerciseByKey());
|
||||
case COMMAND_NOT_SET:
|
||||
default:
|
||||
throw new ProtoCommandUnknown(command);
|
||||
}
|
||||
}
|
||||
|
||||
public CommandsOuterClass.Command toProtoCommand() {
|
||||
CommandsOuterClass.Command.Builder builder = CommandsOuterClass.Command.newBuilder();
|
||||
if (this instanceof CreateCommand) {
|
||||
builder.setCreate(((CreateCommand) this).toProto());
|
||||
} else if (this instanceof ExerciseCommand) {
|
||||
builder.setExercise(((ExerciseCommand) this).toProto());
|
||||
} else if (this instanceof CreateAndExerciseCommand) {
|
||||
builder.setCreateAndExercise(((CreateAndExerciseCommand) this).toProto());
|
||||
} else if (this instanceof ExerciseByKeyCommand) {
|
||||
builder.setExerciseByKey(((ExerciseByKeyCommand) this).toProto());
|
||||
} else {
|
||||
throw new CommandUnknown(this);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public final Optional<CreateCommand> asCreateCommand() {
|
||||
return (this instanceof CreateCommand) ? Optional.of((CreateCommand) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<ExerciseCommand> asExerciseCommand() {
|
||||
return (this instanceof ExerciseCommand)
|
||||
? Optional.of((ExerciseCommand) this)
|
||||
: Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
class CommandUnknown extends RuntimeException {
|
||||
public CommandUnknown(Command command) {
|
||||
super("Command unknown " + command.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class ProtoCommandUnknown extends RuntimeException {
|
||||
public ProtoCommandUnknown(CommandsOuterClass.Command command) {
|
||||
super("Command unknown " + command.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,278 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
import static java.util.Optional.empty;
|
||||
|
||||
import com.daml.ledger.javaapi.data.codegen.HasCommands;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* This class can be used to build a valid submission. It provides {@link #create(String, String, List)}
|
||||
* for initial creation and methods to set optional parameters
|
||||
* e.g {@link #withActAs(List)}, {@link #withWorkflowId(String)} etc.
|
||||
*
|
||||
* Usage:
|
||||
* <pre>
|
||||
* var submission = CommandsSubmission.create(applicationId, commandId, commands)
|
||||
* .withAccessToken(token)
|
||||
* .withParty(party)
|
||||
* .with...
|
||||
* <pre/>
|
||||
*/
|
||||
public final class CommandsSubmission {
|
||||
private String applicationId;
|
||||
private String commandId;
|
||||
private List<@NonNull ? extends HasCommands> commands;
|
||||
|
||||
private Optional<String> workflowId;
|
||||
private List<@NonNull String> actAs;
|
||||
private List<@NonNull String> readAs;
|
||||
private Optional<Instant> minLedgerTimeAbs;
|
||||
private Optional<Duration> minLedgerTimeRel;
|
||||
private Optional<Duration> deduplicationTime;
|
||||
private Optional<String> accessToken;
|
||||
private List<DisclosedContract> disclosedContracts;
|
||||
|
||||
protected CommandsSubmission(
|
||||
String applicationId,
|
||||
String commandId,
|
||||
List<@NonNull ? extends HasCommands> commands,
|
||||
List<@NonNull String> actAs,
|
||||
List<@NonNull String> readAs,
|
||||
Optional<String> workflowId,
|
||||
Optional<Instant> minLedgerTimeAbs,
|
||||
Optional<Duration> minLedgerTimeRel,
|
||||
Optional<Duration> deduplicationTime,
|
||||
Optional<String> accessToken,
|
||||
List<@NonNull DisclosedContract> disclosedContracts) {
|
||||
this.workflowId = workflowId;
|
||||
this.applicationId = applicationId;
|
||||
this.commandId = commandId;
|
||||
this.actAs = actAs;
|
||||
this.readAs = readAs;
|
||||
this.minLedgerTimeAbs = minLedgerTimeAbs;
|
||||
this.minLedgerTimeRel = minLedgerTimeRel;
|
||||
this.deduplicationTime = deduplicationTime;
|
||||
this.commands = commands;
|
||||
this.accessToken = accessToken;
|
||||
this.disclosedContracts = disclosedContracts;
|
||||
}
|
||||
|
||||
public static CommandsSubmission create(
|
||||
String applicationId, String commandId, List<@NonNull ? extends HasCommands> commands) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
empty(),
|
||||
empty(),
|
||||
Optional.empty(),
|
||||
empty(),
|
||||
empty(),
|
||||
emptyList());
|
||||
}
|
||||
|
||||
public Optional<String> getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public String getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public List<String> getActAs() {
|
||||
return unmodifiableList(actAs);
|
||||
}
|
||||
|
||||
public List<String> getReadAs() {
|
||||
return unmodifiableList(readAs);
|
||||
}
|
||||
|
||||
public Optional<Instant> getMinLedgerTimeAbs() {
|
||||
return minLedgerTimeAbs;
|
||||
}
|
||||
|
||||
public Optional<Duration> getMinLedgerTimeRel() {
|
||||
return minLedgerTimeRel;
|
||||
}
|
||||
|
||||
public Optional<Duration> getDeduplicationTime() {
|
||||
return deduplicationTime;
|
||||
}
|
||||
|
||||
public List<? extends HasCommands> getCommands() {
|
||||
return unmodifiableList(commands);
|
||||
}
|
||||
|
||||
public Optional<String> getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public List<DisclosedContract> getDisclosedContracts() {
|
||||
return unmodifiableList(disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withWorkflowId(String workflowId) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
Optional.of(workflowId),
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withActAs(String actAs) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
List.of(actAs),
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withActAs(List<@NonNull String> actAs) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withReadAs(List<@NonNull String> readAs) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withMinLedgerTimeAbs(Optional<Instant> minLedgerTimeAbs) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withMinLedgerTimeRel(Optional<Duration> minLedgerTimeRel) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withDeduplicationTime(Optional<Duration> deduplicationTime) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withCommands(List<@NonNull ? extends HasCommands> commands) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withAccessToken(Optional<String> accessToken) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
|
||||
public CommandsSubmission withDisclosedContracts(List<DisclosedContract> disclosedContracts) {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
commands,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
disclosedContracts);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandCompletionServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class CompletionEndResponse {
|
||||
|
||||
private final LedgerOffset offset;
|
||||
|
||||
public CompletionEndResponse(LedgerOffset offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static CompletionEndResponse fromProto(
|
||||
CommandCompletionServiceOuterClass.CompletionEndResponse response) {
|
||||
return new CompletionEndResponse(LedgerOffset.fromProto(response.getOffset()));
|
||||
}
|
||||
|
||||
public LedgerOffset getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CompletionEndResponse{" + "offset=" + offset + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CompletionEndResponse that = (CompletionEndResponse) o;
|
||||
return Objects.equals(offset, that.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(offset);
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandCompletionServiceOuterClass;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public final class CompletionStreamRequest {
|
||||
|
||||
private final String ledgerId;
|
||||
|
||||
private final String applicationId;
|
||||
|
||||
private final Set<String> parties;
|
||||
|
||||
private final Optional<LedgerOffset> offset;
|
||||
|
||||
public static CompletionStreamRequest fromProto(
|
||||
CommandCompletionServiceOuterClass.CompletionStreamRequest request) {
|
||||
String ledgerId = request.getLedgerId();
|
||||
String applicationId = request.getApplicationId();
|
||||
HashSet<String> parties = new HashSet<>(request.getPartiesList());
|
||||
LedgerOffset offset = LedgerOffset.fromProto(request.getOffset());
|
||||
return new CompletionStreamRequest(ledgerId, applicationId, parties, offset);
|
||||
}
|
||||
|
||||
public CommandCompletionServiceOuterClass.CompletionStreamRequest toProto() {
|
||||
CommandCompletionServiceOuterClass.CompletionStreamRequest.Builder protoBuilder =
|
||||
CommandCompletionServiceOuterClass.CompletionStreamRequest.newBuilder()
|
||||
.setLedgerId(this.ledgerId)
|
||||
.setApplicationId(this.applicationId)
|
||||
.addAllParties(this.parties);
|
||||
this.offset.ifPresent(offset -> protoBuilder.setOffset(offset.toProto()));
|
||||
return protoBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CompletionStreamRequest{"
|
||||
+ "ledgerId='"
|
||||
+ ledgerId
|
||||
+ '\''
|
||||
+ ", applicationId='"
|
||||
+ applicationId
|
||||
+ '\''
|
||||
+ ", parties="
|
||||
+ parties
|
||||
+ ", offset="
|
||||
+ offset
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CompletionStreamRequest that = (CompletionStreamRequest) o;
|
||||
return Objects.equals(ledgerId, that.ledgerId)
|
||||
&& Objects.equals(applicationId, that.applicationId)
|
||||
&& Objects.equals(parties, that.parties)
|
||||
&& Objects.equals(offset, that.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(ledgerId, applicationId, parties, offset);
|
||||
}
|
||||
|
||||
public String getLedgerId() {
|
||||
|
||||
return ledgerId;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public Set<String> getParties() {
|
||||
return parties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Legacy, nullable version of {@link #getLedgerOffset()}, which should be used
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public LedgerOffset getOffset() {
|
||||
return offset.orElse(null);
|
||||
}
|
||||
|
||||
public Optional<LedgerOffset> getLedgerOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public CompletionStreamRequest(String ledgerId, String applicationId, Set<String> parties) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.applicationId = applicationId;
|
||||
this.parties = parties;
|
||||
this.offset = Optional.empty();
|
||||
}
|
||||
|
||||
public CompletionStreamRequest(
|
||||
String ledgerId, String applicationId, Set<String> parties, LedgerOffset offset) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.applicationId = applicationId;
|
||||
this.parties = parties;
|
||||
this.offset = Optional.of(offset);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandCompletionServiceOuterClass;
|
||||
import com.daml.ledger.api.v1.CompletionOuterClass;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CompletionStreamResponse {
|
||||
|
||||
private final Optional<Checkpoint> checkpoint;
|
||||
|
||||
private final List<CompletionOuterClass.Completion> completions;
|
||||
|
||||
public CompletionStreamResponse(
|
||||
@NonNull Optional<Checkpoint> checkpoint,
|
||||
@NonNull List<CompletionOuterClass.@NonNull Completion> completions) {
|
||||
this.checkpoint = checkpoint;
|
||||
this.completions = completions;
|
||||
}
|
||||
|
||||
public static CompletionStreamResponse fromProto(
|
||||
CommandCompletionServiceOuterClass.CompletionStreamResponse response) {
|
||||
if (response.hasCheckpoint()) {
|
||||
Checkpoint checkpoint = Checkpoint.fromProto(response.getCheckpoint());
|
||||
return new CompletionStreamResponse(Optional.of(checkpoint), response.getCompletionsList());
|
||||
} else {
|
||||
return new CompletionStreamResponse(Optional.empty(), response.getCompletionsList());
|
||||
}
|
||||
}
|
||||
|
||||
public CommandCompletionServiceOuterClass.CompletionStreamResponse toProto() {
|
||||
CommandCompletionServiceOuterClass.CompletionStreamResponse.Builder builder =
|
||||
CommandCompletionServiceOuterClass.CompletionStreamResponse.newBuilder();
|
||||
this.checkpoint.ifPresent(c -> builder.setCheckpoint(c.toProto()));
|
||||
builder.addAllCompletions(this.completions);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Checkpoint> getCheckpoint() {
|
||||
return checkpoint;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<CompletionOuterClass.@NonNull Completion> getCompletions() {
|
||||
return completions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CompletionStreamResponse{"
|
||||
+ "checkpoint="
|
||||
+ checkpoint
|
||||
+ ", completions="
|
||||
+ completions
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CompletionStreamResponse that = (CompletionStreamResponse) o;
|
||||
return Objects.equals(checkpoint, that.checkpoint)
|
||||
&& Objects.equals(completions, that.completions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(checkpoint, completions);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
public interface Contract {}
|
@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package 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.ContractTypeCompanion;
|
||||
import com.daml.ledger.javaapi.data.codegen.InterfaceCompanion;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This class contains utilities to decode a <code>CreatedEvent</code> and create a <code>
|
||||
* TransactionFilter</code> by provider parties It can only be instantiated with a subtype of <code>
|
||||
* ContractCompanion</code>
|
||||
*/
|
||||
public final class ContractFilter<Ct> {
|
||||
private final ContractTypeCompanion<Ct, ?, ?, ?> companion;
|
||||
|
||||
private final Filter filter;
|
||||
|
||||
private ContractFilter(ContractTypeCompanion<Ct, ?, ?, ?> companion, Filter filter) {
|
||||
this.companion = companion;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public static <Ct> ContractFilter<Ct> of(ContractCompanion<Ct, ?, ?> companion) {
|
||||
Filter filter =
|
||||
new InclusiveFilter(
|
||||
Collections.emptyMap(),
|
||||
Collections.singletonMap(
|
||||
companion.TEMPLATE_ID, Filter.Template.HIDE_CREATED_EVENT_BLOB));
|
||||
return new ContractFilter<>(companion, filter);
|
||||
}
|
||||
|
||||
public static <Cid, View> ContractFilter<Contract<Cid, View>> of(
|
||||
InterfaceCompanion<?, Cid, View> companion) {
|
||||
Filter filter =
|
||||
new InclusiveFilter(
|
||||
Collections.singletonMap(
|
||||
companion.TEMPLATE_ID, Filter.Interface.INCLUDE_VIEW_HIDE_CREATED_EVENT_BLOB),
|
||||
Collections.emptyMap());
|
||||
return new ContractFilter<>(companion, filter);
|
||||
}
|
||||
|
||||
public Ct toContract(CreatedEvent createdEvent) throws IllegalArgumentException {
|
||||
return companion.fromCreatedEvent(createdEvent);
|
||||
}
|
||||
|
||||
public TransactionFilter transactionFilter(Set<String> parties) {
|
||||
return transactionFilter(filter, parties);
|
||||
}
|
||||
|
||||
private static TransactionFilter transactionFilter(Filter filter, Set<String> parties) {
|
||||
Map<String, Filter> partyToFilters =
|
||||
parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter));
|
||||
return new FiltersByParty(partyToFilters);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ContractId extends Value {
|
||||
|
||||
private final String value;
|
||||
|
||||
public ContractId(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setContractId(this.value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContractId{" + "value='" + value + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ContractId that = (ContractId) o;
|
||||
return Objects.equals(value, that.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ContractMetadataOuterClass;
|
||||
import com.google.protobuf.ByteString;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ContractMetadata {
|
||||
|
||||
// Note that we can't use a `com.daml.ledger.javaapi.data.Timestamp` here because
|
||||
// it only supports milliseconds-precision and we require lossless conversions through
|
||||
// from/toProto.
|
||||
public final Instant createdAt;
|
||||
public final ByteString driverMetadata;
|
||||
public final ByteString contractKeyHash;
|
||||
|
||||
public static ContractMetadata Empty() {
|
||||
return new ContractMetadata(Instant.EPOCH, ByteString.EMPTY, ByteString.EMPTY);
|
||||
}
|
||||
|
||||
public ContractMetadata(
|
||||
@NonNull Instant createdAt,
|
||||
@NonNull ByteString contractKeyHash,
|
||||
@NonNull ByteString driverMetadata) {
|
||||
this.createdAt = createdAt;
|
||||
this.contractKeyHash = contractKeyHash;
|
||||
this.driverMetadata = driverMetadata;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ContractMetadata fromProto(ContractMetadataOuterClass.ContractMetadata metadata) {
|
||||
return new ContractMetadata(
|
||||
Instant.ofEpochSecond(
|
||||
metadata.getCreatedAt().getSeconds(), metadata.getCreatedAt().getNanos()),
|
||||
metadata.getContractKeyHash(),
|
||||
metadata.getDriverMetadata());
|
||||
}
|
||||
|
||||
public ContractMetadataOuterClass.ContractMetadata toProto() {
|
||||
return ContractMetadataOuterClass.ContractMetadata.newBuilder()
|
||||
.setCreatedAt(
|
||||
com.google.protobuf.Timestamp.newBuilder()
|
||||
.setSeconds(this.createdAt.getEpochSecond())
|
||||
.setNanos(this.createdAt.getNano())
|
||||
.build())
|
||||
.setContractKeyHash(this.contractKeyHash)
|
||||
.setDriverMetadata(this.driverMetadata)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ContractMetadata that = (ContractMetadata) o;
|
||||
return Objects.equals(createdAt, that.createdAt)
|
||||
&& Objects.equals(contractKeyHash, that.contractKeyHash)
|
||||
&& Objects.equals(driverMetadata, that.driverMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(createdAt, contractKeyHash, driverMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContractMetadata{"
|
||||
+ "createdAt='"
|
||||
+ createdAt
|
||||
+ '\''
|
||||
+ ", contractKeyHash='"
|
||||
+ contractKeyHash
|
||||
+ '\''
|
||||
+ ", driverMetadata='"
|
||||
+ driverMetadata
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CreateAndExerciseCommand extends Command {
|
||||
private final Identifier templateId;
|
||||
|
||||
private final DamlRecord createArguments;
|
||||
|
||||
private final String choice;
|
||||
|
||||
private final Value choiceArgument;
|
||||
|
||||
public CreateAndExerciseCommand(
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull DamlRecord createArguments,
|
||||
@NonNull String choice,
|
||||
@NonNull Value choiceArgument) {
|
||||
this.templateId = templateId;
|
||||
this.createArguments = createArguments;
|
||||
this.choice = choice;
|
||||
this.choiceArgument = choiceArgument;
|
||||
}
|
||||
|
||||
public static CreateAndExerciseCommand fromProto(
|
||||
CommandsOuterClass.CreateAndExerciseCommand command) {
|
||||
Identifier templateId = Identifier.fromProto(command.getTemplateId());
|
||||
DamlRecord createArguments = DamlRecord.fromProto(command.getCreateArguments());
|
||||
String choice = command.getChoice();
|
||||
Value choiceArgument = Value.fromProto(command.getChoiceArgument());
|
||||
return new CreateAndExerciseCommand(templateId, createArguments, choice, choiceArgument);
|
||||
}
|
||||
|
||||
public CommandsOuterClass.CreateAndExerciseCommand toProto() {
|
||||
return CommandsOuterClass.CreateAndExerciseCommand.newBuilder()
|
||||
.setTemplateId(this.templateId.toProto())
|
||||
.setCreateArguments(this.createArguments.toProtoRecord())
|
||||
.setChoice(this.choice)
|
||||
.setChoiceArgument(this.choiceArgument.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public DamlRecord getCreateArguments() {
|
||||
return createArguments;
|
||||
}
|
||||
|
||||
public String getChoice() {
|
||||
return choice;
|
||||
}
|
||||
|
||||
public Value getChoiceArgument() {
|
||||
return choiceArgument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateAndExerciseCommand{"
|
||||
+ "templateId="
|
||||
+ templateId
|
||||
+ ", createArguments="
|
||||
+ createArguments
|
||||
+ ", choice='"
|
||||
+ choice
|
||||
+ '\''
|
||||
+ ", choiceArgument="
|
||||
+ choiceArgument
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CreateAndExerciseCommand that = (CreateAndExerciseCommand) o;
|
||||
return templateId.equals(that.templateId)
|
||||
&& createArguments.equals(that.createArguments)
|
||||
&& choice.equals(that.choice)
|
||||
&& choiceArgument.equals(that.choiceArgument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(templateId, createArguments, choice, choiceArgument);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CreateCommand extends Command {
|
||||
|
||||
private final Identifier templateId;
|
||||
|
||||
private final DamlRecord createArguments;
|
||||
|
||||
public CreateCommand(@NonNull Identifier templateId, @NonNull DamlRecord createArguments) {
|
||||
this.templateId = templateId;
|
||||
this.createArguments = createArguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateCommand{"
|
||||
+ "templateId="
|
||||
+ templateId
|
||||
+ ", createArguments="
|
||||
+ createArguments
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CreateCommand that = (CreateCommand) o;
|
||||
return Objects.equals(templateId, that.templateId)
|
||||
&& Objects.equals(createArguments, that.createArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(templateId, createArguments);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public DamlRecord getCreateArguments() {
|
||||
return createArguments;
|
||||
}
|
||||
|
||||
public static CreateCommand fromProto(CommandsOuterClass.CreateCommand create) {
|
||||
DamlRecord createArgument = DamlRecord.fromProto(create.getCreateArguments());
|
||||
Identifier templateId = Identifier.fromProto(create.getTemplateId());
|
||||
return new CreateCommand(templateId, createArgument);
|
||||
}
|
||||
|
||||
public CommandsOuterClass.CreateCommand toProto() {
|
||||
return CommandsOuterClass.CreateCommand.newBuilder()
|
||||
.setTemplateId(this.templateId.toProto())
|
||||
.setCreateArguments(this.createArguments.toProtoRecord())
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CreateUserRequest {
|
||||
|
||||
private final User user;
|
||||
private final List<User.Right> rights;
|
||||
|
||||
public CreateUserRequest(User user, User.Right right, User.Right... rights) {
|
||||
this.user = user;
|
||||
this.rights = new ArrayList<>(rights.length + 1);
|
||||
this.rights.add(right);
|
||||
this.rights.addAll(Arrays.asList(rights));
|
||||
}
|
||||
|
||||
public CreateUserRequest(@NonNull String id, @NonNull String primaryParty) {
|
||||
this(new User(id, primaryParty), new User.Right.CanActAs(primaryParty));
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public List<User.Right> getRights() {
|
||||
return new ArrayList<>(rights);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.CreateUserRequest toProto() {
|
||||
return UserManagementServiceOuterClass.CreateUserRequest.newBuilder()
|
||||
.setUser(this.user.toProto())
|
||||
.addAllRights(this.rights.stream().map(User.Right::toProto).collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateUserRequest{" + "user=" + user + ", rights=" + rights + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CreateUserRequest that = (CreateUserRequest) o;
|
||||
return user.equals(that.user) && rights.equals(that.rights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(user, rights);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class CreateUserResponse {
|
||||
|
||||
private final User user;
|
||||
|
||||
public CreateUserResponse(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public static CreateUserResponse fromProto(
|
||||
UserManagementServiceOuterClass.CreateUserResponse proto) {
|
||||
return new CreateUserResponse(User.fromProto(proto.getUser()));
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.CreateUserResponse toProto() {
|
||||
return UserManagementServiceOuterClass.CreateUserResponse.newBuilder()
|
||||
.setUser(this.user.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreateUserResponse{" + "user=" + user + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CreateUserResponse that = (CreateUserResponse) o;
|
||||
return user.equals(that.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(user);
|
||||
}
|
||||
}
|
@ -0,0 +1,361 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.EventOuterClass;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.StringValue;
|
||||
import com.google.rpc.Status;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CreatedEvent implements Event, TreeEvent {
|
||||
|
||||
private final @NonNull List<@NonNull String> witnessParties;
|
||||
|
||||
private final String eventId;
|
||||
|
||||
private final Identifier templateId;
|
||||
|
||||
private final String contractId;
|
||||
|
||||
private final DamlRecord arguments;
|
||||
|
||||
private final @NonNull Map<@NonNull Identifier, @NonNull DamlRecord> interfaceViews;
|
||||
|
||||
private final @NonNull Map<@NonNull Identifier, @NonNull Status> failedInterfaceViews;
|
||||
|
||||
private final Optional<String> agreementText;
|
||||
|
||||
private final Optional<Value> contractKey;
|
||||
|
||||
private final @NonNull Set<@NonNull String> signatories;
|
||||
|
||||
private final @NonNull Set<@NonNull String> observers;
|
||||
|
||||
private final @NonNull ByteString createdEventBlob;
|
||||
|
||||
// Note that we can't use a `com.daml.ledger.javaapi.data.Timestamp` here because
|
||||
// it only supports microseconds-precision and we require lossless conversions through
|
||||
// from/toProto.
|
||||
public final @NonNull Instant createdAt;
|
||||
|
||||
public CreatedEvent(
|
||||
@NonNull List<@NonNull String> witnessParties,
|
||||
@NonNull String eventId,
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull String contractId,
|
||||
@NonNull DamlRecord arguments,
|
||||
@NonNull ByteString createdEventBlob,
|
||||
@NonNull Map<@NonNull Identifier, @NonNull DamlRecord> interfaceViews,
|
||||
@NonNull Map<@NonNull Identifier, com.google.rpc.@NonNull Status> failedInterfaceViews,
|
||||
@NonNull Optional<String> agreementText,
|
||||
@NonNull Optional<Value> contractKey,
|
||||
@NonNull Collection<@NonNull String> signatories,
|
||||
@NonNull Collection<@NonNull String> observers,
|
||||
@NonNull Instant createdAt) {
|
||||
this.witnessParties = List.copyOf(witnessParties);
|
||||
this.eventId = eventId;
|
||||
this.templateId = templateId;
|
||||
this.contractId = contractId;
|
||||
this.arguments = arguments;
|
||||
this.createdEventBlob = createdEventBlob;
|
||||
this.interfaceViews = Map.copyOf(interfaceViews);
|
||||
this.failedInterfaceViews = Map.copyOf(failedInterfaceViews);
|
||||
this.agreementText = agreementText;
|
||||
this.contractKey = contractKey;
|
||||
this.signatories = Set.copyOf(signatories);
|
||||
this.observers = Set.copyOf(observers);
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated You should pass {@code createArgumentsBlob} and {@code contractMetadata} arguments
|
||||
* as well. Since Daml 2.6.0
|
||||
*/
|
||||
@Deprecated
|
||||
public CreatedEvent(
|
||||
@NonNull List<@NonNull String> witnessParties,
|
||||
@NonNull String eventId,
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull String contractId,
|
||||
@NonNull DamlRecord arguments,
|
||||
@NonNull Map<@NonNull Identifier, @NonNull DamlRecord> interfaceViews,
|
||||
@NonNull Map<@NonNull Identifier, com.google.rpc.@NonNull Status> failedInterfaceViews,
|
||||
@NonNull Optional<String> agreementText,
|
||||
@NonNull Optional<Value> contractKey,
|
||||
@NonNull Collection<@NonNull String> signatories,
|
||||
@NonNull Collection<@NonNull String> observers) {
|
||||
this(
|
||||
witnessParties,
|
||||
eventId,
|
||||
templateId,
|
||||
contractId,
|
||||
arguments,
|
||||
ByteString.EMPTY,
|
||||
interfaceViews,
|
||||
failedInterfaceViews,
|
||||
agreementText,
|
||||
contractKey,
|
||||
signatories,
|
||||
observers,
|
||||
Instant.EPOCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Pass {@code interfaceViews} and {@code failedInterfaceViews} arguments; empty maps
|
||||
* are reasonable defaults. Since Daml 2.4.0
|
||||
*/
|
||||
@Deprecated
|
||||
public CreatedEvent(
|
||||
@NonNull List<@NonNull String> witnessParties,
|
||||
@NonNull String eventId,
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull String contractId,
|
||||
@NonNull DamlRecord arguments,
|
||||
@NonNull Optional<String> agreementText,
|
||||
@NonNull Optional<Value> contractKey,
|
||||
@NonNull Collection<@NonNull String> signatories,
|
||||
@NonNull Collection<@NonNull String> observers) {
|
||||
this(
|
||||
witnessParties,
|
||||
eventId,
|
||||
templateId,
|
||||
contractId,
|
||||
arguments,
|
||||
Collections.emptyMap(),
|
||||
Collections.emptyMap(),
|
||||
agreementText,
|
||||
contractKey,
|
||||
signatories,
|
||||
observers);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<@NonNull String> getWitnessParties() {
|
||||
return witnessParties;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getContractId() {
|
||||
return contractId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public DamlRecord getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public ByteString getCreatedEventBlob() {
|
||||
return createdEventBlob;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Map<@NonNull Identifier, @NonNull DamlRecord> getInterfaceViews() {
|
||||
return interfaceViews;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Map<@NonNull Identifier, @NonNull Status> getFailedInterfaceViews() {
|
||||
return failedInterfaceViews;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<String> getAgreementText() {
|
||||
return agreementText;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Value> getContractKey() {
|
||||
return contractKey;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Set<@NonNull String> getSignatories() {
|
||||
return signatories;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Set<@NonNull String> getObservers() {
|
||||
return observers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code createdAt} has been introduced in the Ledger API {@link
|
||||
* com.daml.ledger.api.v1.EventOuterClass.CreatedEvent} starting with Canton version 2.8.0. Events
|
||||
* sourced from the Ledger API prior to this version will return the default {@link Instant#EPOCH}
|
||||
* value.
|
||||
*/
|
||||
@NonNull
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CreatedEvent that = (CreatedEvent) o;
|
||||
return Objects.equals(witnessParties, that.witnessParties)
|
||||
&& Objects.equals(eventId, that.eventId)
|
||||
&& Objects.equals(templateId, that.templateId)
|
||||
&& Objects.equals(contractId, that.contractId)
|
||||
&& Objects.equals(arguments, that.arguments)
|
||||
&& Objects.equals(createdEventBlob, that.createdEventBlob)
|
||||
&& Objects.equals(interfaceViews, that.interfaceViews)
|
||||
&& Objects.equals(failedInterfaceViews, that.failedInterfaceViews)
|
||||
&& Objects.equals(agreementText, that.agreementText)
|
||||
&& Objects.equals(contractKey, that.contractKey)
|
||||
&& Objects.equals(signatories, that.signatories)
|
||||
&& Objects.equals(observers, that.observers)
|
||||
&& Objects.equals(createdAt, that.createdAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
witnessParties,
|
||||
eventId,
|
||||
templateId,
|
||||
contractId,
|
||||
arguments,
|
||||
createdEventBlob,
|
||||
interfaceViews,
|
||||
failedInterfaceViews,
|
||||
agreementText,
|
||||
contractKey,
|
||||
signatories,
|
||||
observers,
|
||||
createdAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CreatedEvent{"
|
||||
+ "witnessParties="
|
||||
+ witnessParties
|
||||
+ ", eventId='"
|
||||
+ eventId
|
||||
+ '\''
|
||||
+ ", templateId="
|
||||
+ templateId
|
||||
+ ", contractId='"
|
||||
+ contractId
|
||||
+ '\''
|
||||
+ ", arguments="
|
||||
+ arguments
|
||||
+ ", createdEventBlob="
|
||||
+ createdEventBlob
|
||||
+ ", interfaceViews="
|
||||
+ interfaceViews
|
||||
+ ", failedInterfaceViews="
|
||||
+ failedInterfaceViews
|
||||
+ ", agreementText='"
|
||||
+ agreementText
|
||||
+ "', contractKey="
|
||||
+ contractKey
|
||||
+ ", signatories="
|
||||
+ signatories
|
||||
+ ", observers="
|
||||
+ observers
|
||||
+ ", createdAt="
|
||||
+ createdAt
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public EventOuterClass.@NonNull CreatedEvent toProto() {
|
||||
EventOuterClass.CreatedEvent.Builder builder =
|
||||
EventOuterClass.CreatedEvent.newBuilder()
|
||||
.setContractId(this.getContractId())
|
||||
.setCreateArguments(this.getArguments().toProtoRecord())
|
||||
.setCreatedEventBlob(createdEventBlob)
|
||||
.addAllInterfaceViews(
|
||||
Stream.concat(
|
||||
toProtoInterfaceViews(
|
||||
interfaceViews, (b, dr) -> b.setViewValue(dr.toProtoRecord())),
|
||||
toProtoInterfaceViews(
|
||||
failedInterfaceViews, (b, status) -> b.setViewStatus(status)))
|
||||
.collect(Collectors.toUnmodifiableList()))
|
||||
.setEventId(this.getEventId())
|
||||
.setTemplateId(this.getTemplateId().toProto())
|
||||
.addAllWitnessParties(this.getWitnessParties())
|
||||
.addAllSignatories(this.getSignatories())
|
||||
.addAllObservers(this.getObservers())
|
||||
.setCreatedAt(
|
||||
com.google.protobuf.Timestamp.newBuilder()
|
||||
.setSeconds(this.createdAt.getEpochSecond())
|
||||
.setNanos(this.createdAt.getNano())
|
||||
.build());
|
||||
agreementText.ifPresent(a -> builder.setAgreementText(StringValue.of(a)));
|
||||
contractKey.ifPresent(a -> builder.setContractKey(a.toProto()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static <V> Stream<EventOuterClass.InterfaceView> toProtoInterfaceViews(
|
||||
Map<Identifier, V> views,
|
||||
BiFunction<EventOuterClass.InterfaceView.Builder, V, EventOuterClass.InterfaceView.Builder>
|
||||
addV) {
|
||||
return views.entrySet().stream()
|
||||
.map(
|
||||
e ->
|
||||
addV.apply(
|
||||
EventOuterClass.InterfaceView.newBuilder()
|
||||
.setInterfaceId(e.getKey().toProto()),
|
||||
e.getValue())
|
||||
.build());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static CreatedEvent fromProto(EventOuterClass.CreatedEvent createdEvent) {
|
||||
var splitInterfaceViews =
|
||||
createdEvent.getInterfaceViewsList().stream()
|
||||
.collect(Collectors.partitioningBy(EventOuterClass.InterfaceView::hasViewValue));
|
||||
return new CreatedEvent(
|
||||
createdEvent.getWitnessPartiesList(),
|
||||
createdEvent.getEventId(),
|
||||
Identifier.fromProto(createdEvent.getTemplateId()),
|
||||
createdEvent.getContractId(),
|
||||
DamlRecord.fromProto(createdEvent.getCreateArguments()),
|
||||
createdEvent.getCreatedEventBlob(),
|
||||
splitInterfaceViews.get(true).stream()
|
||||
.collect(
|
||||
Collectors.toUnmodifiableMap(
|
||||
iv -> Identifier.fromProto(iv.getInterfaceId()),
|
||||
iv -> DamlRecord.fromProto(iv.getViewValue()))),
|
||||
splitInterfaceViews.get(false).stream()
|
||||
.collect(
|
||||
Collectors.toUnmodifiableMap(
|
||||
iv -> Identifier.fromProto(iv.getInterfaceId()),
|
||||
EventOuterClass.InterfaceView::getViewStatus)),
|
||||
createdEvent.hasAgreementText()
|
||||
? Optional.of(createdEvent.getAgreementText().getValue())
|
||||
: Optional.empty(),
|
||||
createdEvent.hasContractKey()
|
||||
? Optional.of(Value.fromProto(createdEvent.getContractKey()))
|
||||
: Optional.empty(),
|
||||
createdEvent.getSignatoriesList(),
|
||||
createdEvent.getObserversList(),
|
||||
Instant.ofEpochSecond(
|
||||
createdEvent.getCreatedAt().getSeconds(), createdEvent.getCreatedAt().getNanos()));
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
public final class DamlCollectors {
|
||||
|
||||
// no instantiation
|
||||
private DamlCollectors() {}
|
||||
|
||||
public static <T> Collector<T, List<Value>, DamlList> toDamlList(Function<T, Value> valueMapper) {
|
||||
return Collector.of(
|
||||
ArrayList::new,
|
||||
(acc, entry) -> acc.add(valueMapper.apply(entry)),
|
||||
(left, right) -> {
|
||||
left.addAll(right);
|
||||
return left;
|
||||
},
|
||||
DamlList::fromPrivateList);
|
||||
}
|
||||
|
||||
public static Collector<Value, List<Value>, DamlList> toDamlList() {
|
||||
return toDamlList(Function.identity());
|
||||
}
|
||||
|
||||
public static <T> Collector<T, Map<String, Value>, DamlTextMap> toDamlTextMap(
|
||||
Function<T, String> keyMapper, Function<T, Value> valueMapper) {
|
||||
|
||||
return Collector.of(
|
||||
HashMap::new,
|
||||
(acc, entry) -> acc.put(keyMapper.apply(entry), valueMapper.apply(entry)),
|
||||
(left, right) -> {
|
||||
left.putAll(right);
|
||||
return left;
|
||||
},
|
||||
DamlTextMap::fromPrivateMap);
|
||||
}
|
||||
|
||||
public static Collector<Map.Entry<String, Value>, Map<String, Value>, DamlTextMap>
|
||||
toDamlTextMap() {
|
||||
return toDamlTextMap(Map.Entry::getKey, Map.Entry::getValue);
|
||||
}
|
||||
|
||||
public static <T> Collector<T, Map<Value, Value>, DamlGenMap> toDamlGenMap(
|
||||
Function<T, Value> keyMapper, Function<T, Value> valueMapper) {
|
||||
|
||||
return Collector.of(
|
||||
LinkedHashMap::new,
|
||||
(acc, entry) -> acc.put(keyMapper.apply(entry), valueMapper.apply(entry)),
|
||||
(left, right) -> {
|
||||
left.putAll(right);
|
||||
return left;
|
||||
},
|
||||
DamlGenMap::fromPrivateMap);
|
||||
}
|
||||
|
||||
public static Collector<Map.Entry<Value, Value>, Map<Value, Value>, DamlGenMap> toMap() {
|
||||
return toDamlGenMap(Map.Entry::getKey, Map.Entry::getValue);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class DamlEnum extends Value {
|
||||
|
||||
private final Optional<Identifier> enumId;
|
||||
|
||||
private final String constructor;
|
||||
|
||||
public DamlEnum(@NonNull Identifier enumId, @NonNull String constructor) {
|
||||
this.enumId = Optional.of(enumId);
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
public DamlEnum(@NonNull String constructor) {
|
||||
this.enumId = Optional.empty();
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
public static DamlEnum fromProto(ValueOuterClass.Enum value) {
|
||||
String constructor = value.getConstructor();
|
||||
if (value.hasEnumId()) {
|
||||
Identifier variantId = Identifier.fromProto(value.getEnumId());
|
||||
return new DamlEnum(variantId, constructor);
|
||||
} else {
|
||||
return new DamlEnum(constructor);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Identifier> getEnumId() {
|
||||
return enumId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getConstructor() {
|
||||
return constructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setEnum(this.toProtoEnum()).build();
|
||||
}
|
||||
|
||||
public ValueOuterClass.Enum toProtoEnum() {
|
||||
ValueOuterClass.Enum.Builder builder = ValueOuterClass.Enum.newBuilder();
|
||||
builder.setConstructor(this.getConstructor());
|
||||
this.getEnumId().ifPresent(identifier -> builder.setEnumId(identifier.toProto()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DamlEnum value = (DamlEnum) o;
|
||||
return Objects.equals(enumId, value.enumId) && Objects.equals(constructor, value.constructor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(enumId, constructor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Enum{" + "variantId=" + enumId + ", constructor='" + constructor + "'}";
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class DamlGenMap extends Value {
|
||||
|
||||
private final Map<Value, Value> map;
|
||||
|
||||
private DamlGenMap(@NonNull Map<@NonNull Value, @NonNull Value> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/** The map that is passed to this constructor must not be changed once passed. */
|
||||
static @NonNull DamlGenMap fromPrivateMap(@NonNull Map<@NonNull Value, @NonNull Value> map) {
|
||||
return new DamlGenMap(Collections.unmodifiableMap(map));
|
||||
}
|
||||
|
||||
public static DamlGenMap of(@NonNull Map<@NonNull Value, @NonNull Value> map) {
|
||||
return fromPrivateMap(new LinkedHashMap<>(map));
|
||||
}
|
||||
|
||||
public Stream<Map.Entry<Value, Value>> stream() {
|
||||
return map.entrySet().stream();
|
||||
}
|
||||
|
||||
public @NonNull <K, V> Map<@NonNull K, @NonNull V> toMap(
|
||||
@NonNull Function<@NonNull Value, @NonNull K> keyMapper,
|
||||
@NonNull Function<@NonNull Value, @NonNull V> valueMapper) {
|
||||
return stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
e -> keyMapper.apply(e.getKey()),
|
||||
e -> valueMapper.apply(e.getValue()),
|
||||
(left, right) -> right,
|
||||
LinkedHashMap::new));
|
||||
}
|
||||
|
||||
public @NonNull <V> Map<@NonNull V, @NonNull V> toMap(
|
||||
@NonNull Function<@NonNull Value, @NonNull V> valueMapper) {
|
||||
return toMap(valueMapper, valueMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DamlGenMap other = (DamlGenMap) o;
|
||||
return Objects.equals(map, other.map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return map.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String toString() {
|
||||
StringJoiner sj = new StringJoiner(", ", "GenMap{", "}");
|
||||
map.forEach((key, value) -> sj.add(key.toString() + " -> " + value.toString()));
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
ValueOuterClass.GenMap.Builder mb = ValueOuterClass.GenMap.newBuilder();
|
||||
map.forEach(
|
||||
(key, value) ->
|
||||
mb.addEntries(
|
||||
ValueOuterClass.GenMap.Entry.newBuilder()
|
||||
.setKey(key.toProto())
|
||||
.setValue(value.toProto())));
|
||||
return ValueOuterClass.Value.newBuilder().setGenMap(mb).build();
|
||||
}
|
||||
|
||||
public static @NonNull DamlGenMap fromProto(ValueOuterClass.GenMap map) {
|
||||
return map.getEntriesList().stream()
|
||||
.collect(
|
||||
DamlCollectors.toDamlGenMap(
|
||||
entry -> fromProto(entry.getKey()), entry -> fromProto(entry.getValue())));
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class DamlList extends Value {
|
||||
|
||||
private List<Value> values;
|
||||
|
||||
private DamlList() {}
|
||||
|
||||
/** The list that is passed to this constructor must not be change once passed. */
|
||||
static @NonNull DamlList fromPrivateList(@NonNull List<@NonNull Value> values) {
|
||||
DamlList damlList = new DamlList();
|
||||
damlList.values = Collections.unmodifiableList(values);
|
||||
return damlList;
|
||||
}
|
||||
|
||||
public static DamlList of(@NonNull List<@NonNull Value> values) {
|
||||
return fromPrivateList(new ArrayList<>(values));
|
||||
}
|
||||
|
||||
public static DamlList of(@NonNull Value... values) {
|
||||
return fromPrivateList(Arrays.asList(values));
|
||||
}
|
||||
|
||||
@Deprecated // use DamlList:of
|
||||
public DamlList(@NonNull List<@NonNull Value> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Deprecated // use DamlMap:of
|
||||
public DamlList(@NonNull Value... values) {
|
||||
this(Arrays.asList(values));
|
||||
}
|
||||
|
||||
@Deprecated // use DamlMap::stream or DamlMap::toListf
|
||||
public @NonNull List<@NonNull Value> getValues() {
|
||||
return toList(Function.identity());
|
||||
}
|
||||
|
||||
public @NonNull Stream<Value> stream() {
|
||||
return values.stream();
|
||||
}
|
||||
|
||||
public @NonNull <T> List<T> toList(Function<Value, T> valueMapper) {
|
||||
return stream().map(valueMapper).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DamlList list = (DamlList) o;
|
||||
return Objects.equals(values, list.values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DamlList{" + "values=" + values + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
ValueOuterClass.List.Builder builder = ValueOuterClass.List.newBuilder();
|
||||
for (Value value : this.values) {
|
||||
builder.addElements(value.toProto());
|
||||
}
|
||||
return ValueOuterClass.Value.newBuilder().setList(builder.build()).build();
|
||||
}
|
||||
|
||||
public static @NonNull DamlList fromProto(ValueOuterClass.List list) {
|
||||
return list.getElementsList().stream().collect(DamlCollectors.toDamlList(Value::fromProto));
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.*;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
// FIXME When removing this after the deprecation period is over, make DamlTextMap final
|
||||
/** @deprecated Use {@link DamlTextMap} instead. */
|
||||
@Deprecated
|
||||
public final class DamlMap extends DamlTextMap {
|
||||
|
||||
public DamlMap(Map<@NonNull String, @NonNull Value> value) {
|
||||
super(Collections.unmodifiableMap(new HashMap<>(value)));
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class DamlOptional extends Value {
|
||||
|
||||
public static DamlOptional EMPTY = new DamlOptional(Optional.empty());
|
||||
|
||||
private final Value value;
|
||||
|
||||
DamlOptional(Value value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Deprecated // use DamlOptional.of
|
||||
public DamlOptional(Optional<@NonNull Value> value) {
|
||||
this(value.orElse(null));
|
||||
}
|
||||
|
||||
public static DamlOptional of(@NonNull Optional<@NonNull Value> value) {
|
||||
if (value.isPresent()) return new DamlOptional((value.get()));
|
||||
else return EMPTY;
|
||||
}
|
||||
|
||||
public static DamlOptional of(Value value) {
|
||||
return new DamlOptional(value);
|
||||
}
|
||||
|
||||
public java.util.Optional<Value> getValue() {
|
||||
return java.util.Optional.ofNullable(value);
|
||||
}
|
||||
|
||||
public @NonNull <V> Optional<V> toOptional(Function<@NonNull Value, @NonNull V> valueMapper) {
|
||||
return (value == null) ? Optional.empty() : Optional.of(valueMapper.apply(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DamlOptional optional = (DamlOptional) o;
|
||||
return Objects.equals(value, optional.value);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return value == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (value == null) ? 0 : value.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String toString() {
|
||||
return "Optional{" + "value=" + value + '}';
|
||||
}
|
||||
|
||||
@Deprecated // use DamlOptional::EMPTY
|
||||
public static @NonNull DamlOptional empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
ValueOuterClass.Optional.Builder ob = ValueOuterClass.Optional.newBuilder();
|
||||
if (value != null) ob.setValue(value.toProto());
|
||||
return ValueOuterClass.Value.newBuilder().setOptional(ob.build()).build();
|
||||
}
|
||||
|
||||
public static DamlOptional fromProto(ValueOuterClass.Optional optional) {
|
||||
return (optional.hasValue()) ? new DamlOptional(fromProto(optional.getValue())) : EMPTY;
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.*;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class DamlRecord extends Value {
|
||||
|
||||
private final Optional<Identifier> recordId;
|
||||
|
||||
private final Map<String, Value> fieldsMap;
|
||||
|
||||
private final List<Field> fields;
|
||||
|
||||
public DamlRecord(@NonNull Identifier recordId, @NonNull Field... fields) {
|
||||
this(recordId, Arrays.asList(fields));
|
||||
}
|
||||
|
||||
public DamlRecord(@NonNull Field... fields) {
|
||||
this(Arrays.asList(fields));
|
||||
}
|
||||
|
||||
public DamlRecord(@NonNull Identifier recordId, @NonNull List<@NonNull Field> fields) {
|
||||
this(Optional.of(recordId), fields, fieldsListToHashMap(fields));
|
||||
}
|
||||
|
||||
public DamlRecord(@NonNull List<@NonNull Field> fields) {
|
||||
this(Optional.empty(), fields, fieldsListToHashMap(fields));
|
||||
}
|
||||
|
||||
public DamlRecord(
|
||||
@NonNull Optional<Identifier> recordId,
|
||||
@NonNull List<@NonNull Field> fields,
|
||||
Map<String, Value> fieldsMap) {
|
||||
this.recordId = recordId;
|
||||
this.fields = fields;
|
||||
this.fieldsMap = fieldsMap;
|
||||
}
|
||||
|
||||
private static Map<String, Value> fieldsListToHashMap(@NonNull List<@NonNull Field> fields) {
|
||||
if (fields.isEmpty() || !fields.get(0).getLabel().isPresent()) {
|
||||
return Collections.emptyMap();
|
||||
} else {
|
||||
HashMap<String, Value> fieldsMap = new HashMap<>(fields.size());
|
||||
for (Field field : fields) {
|
||||
fieldsMap.put(field.getLabel().get(), field.getValue());
|
||||
}
|
||||
return fieldsMap;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static DamlRecord fromProto(ValueOuterClass.Record record) {
|
||||
ArrayList<Field> fields = new ArrayList<>(record.getFieldsCount());
|
||||
HashMap<String, Value> fieldsMap = new HashMap<>(record.getFieldsCount());
|
||||
for (ValueOuterClass.RecordField recordField : record.getFieldsList()) {
|
||||
Field field = Field.fromProto(recordField);
|
||||
fields.add(field);
|
||||
if (field.getLabel().isPresent()) {
|
||||
fieldsMap.put(field.getLabel().get(), field.getValue());
|
||||
}
|
||||
}
|
||||
if (record.hasRecordId()) {
|
||||
Identifier recordId = Identifier.fromProto(record.getRecordId());
|
||||
return new DamlRecord(Optional.of(recordId), fields, fieldsMap);
|
||||
} else {
|
||||
return new DamlRecord(Optional.empty(), fields, fieldsMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setRecord(this.toProtoRecord()).build();
|
||||
}
|
||||
|
||||
public ValueOuterClass.Record toProtoRecord() {
|
||||
ValueOuterClass.Record.Builder recordBuilder = ValueOuterClass.Record.newBuilder();
|
||||
this.recordId.ifPresent(recordId -> recordBuilder.setRecordId(recordId.toProto()));
|
||||
for (Field field : this.fields) {
|
||||
recordBuilder.addFields(field.toProto());
|
||||
}
|
||||
return recordBuilder.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Identifier> getRecordId() {
|
||||
return recordId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Field> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
/** @return the Map of this DamlRecord fields containing the records that have the label */
|
||||
@NonNull
|
||||
public Map<@NonNull String, @NonNull Value> getFieldsMap() {
|
||||
return fieldsMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DamlRecord{" + "recordId=" + recordId + ", fields=" + fields + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DamlRecord record = (DamlRecord) o;
|
||||
return Objects.equals(recordId, record.recordId) && Objects.equals(fields, record.fields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(recordId, fields);
|
||||
}
|
||||
|
||||
public static class Field {
|
||||
|
||||
private final Optional<String> label;
|
||||
|
||||
private final Value value;
|
||||
|
||||
public Field(@NonNull String label, @NonNull Value value) {
|
||||
this.label = Optional.of(label);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Field(@NonNull Value value) {
|
||||
this.label = Optional.empty();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<String> getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Field fromProto(ValueOuterClass.RecordField field) {
|
||||
String label = field.getLabel();
|
||||
Value value = Value.fromProto(field.getValue());
|
||||
return label.isEmpty() ? new Field(value) : new Field(label, value);
|
||||
}
|
||||
|
||||
public ValueOuterClass.RecordField toProto() {
|
||||
ValueOuterClass.RecordField.Builder builder = ValueOuterClass.RecordField.newBuilder();
|
||||
this.label.ifPresent(builder::setLabel);
|
||||
builder.setValue(this.value.toProto());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Field field = (Field) o;
|
||||
return Objects.equals(label, field.label) && Objects.equals(value, field.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(label, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Field{" + "label=" + label + ", value=" + value + '}';
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class DamlTextMap extends Value {
|
||||
|
||||
private final Map<String, Value> map;
|
||||
|
||||
DamlTextMap(Map<String, Value> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/** The map that is passed to this constructor must not be changed once passed. */
|
||||
static @NonNull DamlTextMap fromPrivateMap(Map<@NonNull String, @NonNull Value> value) {
|
||||
return new DamlTextMap(Collections.unmodifiableMap(value));
|
||||
}
|
||||
|
||||
private static @NonNull DamlTextMap EMPTY = fromPrivateMap(Collections.emptyMap());
|
||||
|
||||
public static DamlTextMap of(@NonNull Map<@NonNull String, @NonNull Value> value) {
|
||||
return fromPrivateMap(new HashMap<>(value));
|
||||
}
|
||||
|
||||
@Deprecated // use DamlTextMap::toMap or DamlTextMap::stream
|
||||
public final @NonNull Map<@NonNull String, @NonNull Value> getMap() {
|
||||
return toMap(Function.identity());
|
||||
}
|
||||
|
||||
public Stream<Map.Entry<String, Value>> stream() {
|
||||
return map.entrySet().stream();
|
||||
}
|
||||
|
||||
public final @NonNull <K, V> Map<K, V> toMap(
|
||||
@NonNull Function<@NonNull String, @NonNull K> keyMapper,
|
||||
@NonNull Function<@NonNull Value, @NonNull V> valueMapper) {
|
||||
return stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
e -> keyMapper.apply(e.getKey()), e -> valueMapper.apply(e.getValue())));
|
||||
}
|
||||
|
||||
public final @NonNull <V> Map<@NonNull String, @NonNull V> toMap(
|
||||
@NonNull Function<@NonNull Value, @NonNull V> valueMapper) {
|
||||
return toMap(Function.identity(), valueMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DamlTextMap other = (DamlTextMap) o;
|
||||
return Objects.equals(map, other.map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return map.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NonNull String toString() {
|
||||
StringJoiner sj = new StringJoiner(", ", "TextMap{", "}");
|
||||
map.forEach((key, value) -> sj.add(key + "->" + value.toString()));
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ValueOuterClass.Value toProto() {
|
||||
ValueOuterClass.Map.Builder mb = ValueOuterClass.Map.newBuilder();
|
||||
map.forEach(
|
||||
(k, v) ->
|
||||
mb.addEntries(ValueOuterClass.Map.Entry.newBuilder().setKey(k).setValue(v.toProto())));
|
||||
return ValueOuterClass.Value.newBuilder().setMap(mb).build();
|
||||
}
|
||||
|
||||
public static @NonNull DamlTextMap fromProto(ValueOuterClass.Map map) {
|
||||
return map.getEntriesList().stream()
|
||||
.collect(
|
||||
DamlCollectors.toDamlTextMap(
|
||||
ValueOuterClass.Map.Entry::getKey, entry -> fromProto(entry.getValue())));
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Date extends Value {
|
||||
|
||||
private final LocalDate value;
|
||||
|
||||
public Date(int value) {
|
||||
this.value = LocalDate.ofEpochDay(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setDate((int) this.value.toEpochDay()).build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public LocalDate getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Date{" + "value=" + value + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Date date = (Date) o;
|
||||
return Objects.equals(value, date.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
// FIXME When removing this after the deprecation period is over, make Numeric final
|
||||
/** @deprecated Use {@link Numeric} instead. */
|
||||
@Deprecated
|
||||
public final class Decimal extends Numeric {
|
||||
public Decimal(@NonNull BigDecimal value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class DeleteUserRequest {
|
||||
|
||||
private final String userId;
|
||||
|
||||
public DeleteUserRequest(@NonNull String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeleteUserRequest{" + "userId='" + userId + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DeleteUserRequest that = (DeleteUserRequest) o;
|
||||
return Objects.equals(userId, that.userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.DeleteUserRequest toProto() {
|
||||
return UserManagementServiceOuterClass.DeleteUserRequest.newBuilder()
|
||||
.setUserId(this.userId)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
|
||||
public final class DeleteUserResponse {
|
||||
|
||||
private static final DeleteUserResponse INSTANCE = new DeleteUserResponse();
|
||||
|
||||
private DeleteUserResponse() {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeleteUserResponse{}";
|
||||
}
|
||||
|
||||
public static DeleteUserResponse fromProto(
|
||||
UserManagementServiceOuterClass.DeleteUserResponse response) {
|
||||
// As this is so far a singleton, we just ignore the response
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
public final class DisclosedContract {
|
||||
public final Identifier templateId;
|
||||
public final String contractId;
|
||||
public final ByteString createdEventBlob;
|
||||
|
||||
public DisclosedContract(Identifier templateId, String contractId, ByteString createdEventBlob) {
|
||||
this.templateId = templateId;
|
||||
this.contractId = contractId;
|
||||
this.createdEventBlob = createdEventBlob;
|
||||
}
|
||||
|
||||
public CommandsOuterClass.DisclosedContract toProto() {
|
||||
return CommandsOuterClass.DisclosedContract.newBuilder()
|
||||
.setTemplateId(this.templateId.toProto())
|
||||
.setContractId(this.contractId)
|
||||
.setCreatedEventBlob(this.createdEventBlob)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.EventOuterClass;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* This interface represents events in {@link Transaction}s.
|
||||
*
|
||||
* @see CreatedEvent
|
||||
* @see ArchivedEvent
|
||||
* @see Transaction
|
||||
*/
|
||||
public interface Event {
|
||||
|
||||
@NonNull
|
||||
List<@NonNull String> getWitnessParties();
|
||||
|
||||
@NonNull
|
||||
String getEventId();
|
||||
|
||||
@NonNull
|
||||
Identifier getTemplateId();
|
||||
|
||||
@NonNull
|
||||
String getContractId();
|
||||
|
||||
default EventOuterClass.Event toProtoEvent() {
|
||||
EventOuterClass.Event.Builder eventBuilder = EventOuterClass.Event.newBuilder();
|
||||
if (this instanceof ArchivedEvent) {
|
||||
ArchivedEvent event = (ArchivedEvent) this;
|
||||
eventBuilder.setArchived(event.toProto());
|
||||
} else if (this instanceof CreatedEvent) {
|
||||
CreatedEvent event = (CreatedEvent) this;
|
||||
eventBuilder.setCreated(event.toProto());
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"this should be ArchivedEvent or CreatedEvent or ExercisedEvent, found "
|
||||
+ this.toString());
|
||||
}
|
||||
return eventBuilder.build();
|
||||
}
|
||||
|
||||
static Event fromProtoEvent(EventOuterClass.Event event) {
|
||||
if (event.hasCreated()) {
|
||||
return CreatedEvent.fromProto(event.getCreated());
|
||||
} else if (event.hasArchived()) {
|
||||
return ArchivedEvent.fromProto(event.getArchived());
|
||||
} else {
|
||||
throw new UnsupportedEventTypeException(event.toString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventUtils {
|
||||
|
||||
private EventUtils() {}
|
||||
|
||||
/** @hidden */
|
||||
public static CreatedEvent singleCreatedEvent(List<? extends Event> events) {
|
||||
if (events.size() == 1 && events.get(0) instanceof CreatedEvent)
|
||||
return (CreatedEvent) events.get(0);
|
||||
throw new IllegalArgumentException(
|
||||
"Expected exactly one created event from the transaction, got: " + events);
|
||||
}
|
||||
|
||||
/** @hidden */
|
||||
public static ExercisedEvent firstExercisedEvent(TransactionTree txTree) {
|
||||
var maybeExercisedEvent =
|
||||
txTree.getRootEventIds().stream()
|
||||
.map(eventId -> txTree.getEventsById().get(eventId))
|
||||
.filter(e -> e instanceof ExercisedEvent)
|
||||
.map(e -> (ExercisedEvent) e)
|
||||
.findFirst();
|
||||
|
||||
return maybeExercisedEvent.orElseThrow(
|
||||
() ->
|
||||
new IllegalArgumentException("Expect an exercised event but not found. tx: " + txTree));
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ExerciseByKeyCommand extends Command {
|
||||
|
||||
private final Identifier templateId;
|
||||
|
||||
private final Value contractKey;
|
||||
|
||||
private final String choice;
|
||||
|
||||
private final Value choiceArgument;
|
||||
|
||||
public ExerciseByKeyCommand(
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull Value contractKey,
|
||||
@NonNull String choice,
|
||||
@NonNull Value choiceArgument) {
|
||||
this.templateId = templateId;
|
||||
this.contractKey = contractKey;
|
||||
this.choice = choice;
|
||||
this.choiceArgument = choiceArgument;
|
||||
}
|
||||
|
||||
public static ExerciseByKeyCommand fromProto(CommandsOuterClass.ExerciseByKeyCommand command) {
|
||||
Identifier templateId = Identifier.fromProto(command.getTemplateId());
|
||||
Value contractKey = Value.fromProto(command.getContractKey());
|
||||
String choice = command.getChoice();
|
||||
Value choiceArgument = Value.fromProto(command.getChoiceArgument());
|
||||
return new ExerciseByKeyCommand(templateId, contractKey, choice, choiceArgument);
|
||||
}
|
||||
|
||||
public CommandsOuterClass.ExerciseByKeyCommand toProto() {
|
||||
return CommandsOuterClass.ExerciseByKeyCommand.newBuilder()
|
||||
.setTemplateId(this.templateId.toProto())
|
||||
.setContractKey(this.contractKey.toProto())
|
||||
.setChoice(this.choice)
|
||||
.setChoiceArgument(this.choiceArgument.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getContractKey() {
|
||||
return contractKey;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getChoice() {
|
||||
return choice;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getChoiceArgument() {
|
||||
return choiceArgument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExerciseByKeyCommand{"
|
||||
+ "templateId="
|
||||
+ templateId
|
||||
+ ", contractKey='"
|
||||
+ contractKey
|
||||
+ '\''
|
||||
+ ", choice='"
|
||||
+ choice
|
||||
+ '\''
|
||||
+ ", choiceArgument="
|
||||
+ choiceArgument
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ExerciseByKeyCommand that = (ExerciseByKeyCommand) o;
|
||||
return Objects.equals(templateId, that.templateId)
|
||||
&& Objects.equals(contractKey, that.contractKey)
|
||||
&& Objects.equals(choice, that.choice)
|
||||
&& Objects.equals(choiceArgument, that.choiceArgument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(templateId, contractKey, choice, choiceArgument);
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ExerciseCommand extends Command {
|
||||
|
||||
private final Identifier templateId;
|
||||
|
||||
private final String contractId;
|
||||
|
||||
private final String choice;
|
||||
|
||||
private final Value choiceArgument;
|
||||
|
||||
public ExerciseCommand(
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull String contractId,
|
||||
@NonNull String choice,
|
||||
@NonNull Value choiceArgument) {
|
||||
this.templateId = templateId;
|
||||
this.contractId = contractId;
|
||||
this.choice = choice;
|
||||
this.choiceArgument = choiceArgument;
|
||||
}
|
||||
|
||||
public static ExerciseCommand fromProto(CommandsOuterClass.ExerciseCommand command) {
|
||||
Identifier templateId = Identifier.fromProto(command.getTemplateId());
|
||||
String contractId = command.getContractId();
|
||||
String choice = command.getChoice();
|
||||
Value choiceArgument = Value.fromProto(command.getChoiceArgument());
|
||||
return new ExerciseCommand(templateId, contractId, choice, choiceArgument);
|
||||
}
|
||||
|
||||
public CommandsOuterClass.ExerciseCommand toProto() {
|
||||
return CommandsOuterClass.ExerciseCommand.newBuilder()
|
||||
.setTemplateId(this.templateId.toProto())
|
||||
.setContractId(this.contractId)
|
||||
.setChoice(this.choice)
|
||||
.setChoiceArgument(this.choiceArgument.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getContractId() {
|
||||
return contractId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getChoice() {
|
||||
return choice;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getChoiceArgument() {
|
||||
return choiceArgument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExerciseCommand{"
|
||||
+ "templateId="
|
||||
+ templateId
|
||||
+ ", contractId='"
|
||||
+ contractId
|
||||
+ '\''
|
||||
+ ", choice='"
|
||||
+ choice
|
||||
+ '\''
|
||||
+ ", choiceArgument="
|
||||
+ choiceArgument
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ExerciseCommand that = (ExerciseCommand) o;
|
||||
return Objects.equals(templateId, that.templateId)
|
||||
&& Objects.equals(contractId, that.contractId)
|
||||
&& Objects.equals(choice, that.choice)
|
||||
&& Objects.equals(choiceArgument, that.choiceArgument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(templateId, contractId, choice, choiceArgument);
|
||||
}
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.EventOuterClass;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ExercisedEvent implements TreeEvent {
|
||||
|
||||
private final List<String> witnessParties;
|
||||
|
||||
private final String eventId;
|
||||
|
||||
private final Identifier templateId;
|
||||
|
||||
private final Optional<Identifier> interfaceId;
|
||||
|
||||
private final String contractId;
|
||||
|
||||
private final String choice;
|
||||
|
||||
private final Value choiceArgument;
|
||||
|
||||
private final java.util.List<String> actingParties;
|
||||
|
||||
private final boolean consuming;
|
||||
|
||||
private final List<String> childEventIds;
|
||||
|
||||
private final Value exerciseResult;
|
||||
|
||||
public ExercisedEvent(
|
||||
@NonNull List<@NonNull String> witnessParties,
|
||||
@NonNull String eventId,
|
||||
@NonNull Identifier templateId,
|
||||
@NonNull Optional<Identifier> interfaceId,
|
||||
@NonNull String contractId,
|
||||
@NonNull String choice,
|
||||
@NonNull Value choiceArgument,
|
||||
@NonNull List<@NonNull String> actingParties,
|
||||
boolean consuming,
|
||||
@NonNull List<@NonNull String> childEventIds,
|
||||
@NonNull Value exerciseResult) {
|
||||
this.witnessParties = witnessParties;
|
||||
this.eventId = eventId;
|
||||
this.templateId = templateId;
|
||||
this.interfaceId = interfaceId;
|
||||
this.contractId = contractId;
|
||||
this.choice = choice;
|
||||
this.choiceArgument = choiceArgument;
|
||||
this.actingParties = actingParties;
|
||||
this.consuming = consuming;
|
||||
this.childEventIds = childEventIds;
|
||||
this.exerciseResult = exerciseResult;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<@NonNull String> getWitnessParties() {
|
||||
return witnessParties;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Identifier getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Identifier> getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getContractId() {
|
||||
return contractId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getChoice() {
|
||||
return choice;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull String> getChildEventIds() {
|
||||
return childEventIds;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getChoiceArgument() {
|
||||
return choiceArgument;
|
||||
}
|
||||
|
||||
public @NonNull List<@NonNull String> getActingParties() {
|
||||
return actingParties;
|
||||
}
|
||||
|
||||
public boolean isConsuming() {
|
||||
return consuming;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getExerciseResult() {
|
||||
return exerciseResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ExercisedEvent that = (ExercisedEvent) o;
|
||||
return consuming == that.consuming
|
||||
&& Objects.equals(witnessParties, that.witnessParties)
|
||||
&& Objects.equals(eventId, that.eventId)
|
||||
&& Objects.equals(templateId, that.templateId)
|
||||
&& Objects.equals(interfaceId, that.interfaceId)
|
||||
&& Objects.equals(contractId, that.contractId)
|
||||
&& Objects.equals(choice, that.choice)
|
||||
&& Objects.equals(choiceArgument, that.choiceArgument)
|
||||
&& Objects.equals(actingParties, that.actingParties)
|
||||
&& Objects.equals(childEventIds, that.childEventIds)
|
||||
&& Objects.equals(exerciseResult, that.exerciseResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(
|
||||
witnessParties,
|
||||
eventId,
|
||||
templateId,
|
||||
interfaceId,
|
||||
contractId,
|
||||
choice,
|
||||
choiceArgument,
|
||||
actingParties,
|
||||
childEventIds,
|
||||
consuming,
|
||||
exerciseResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExercisedEvent{"
|
||||
+ "witnessParties="
|
||||
+ witnessParties
|
||||
+ ", eventId='"
|
||||
+ eventId
|
||||
+ '\''
|
||||
+ ", templateId="
|
||||
+ templateId
|
||||
+ ", interfaceId="
|
||||
+ interfaceId
|
||||
+ ", contractId='"
|
||||
+ contractId
|
||||
+ '\''
|
||||
+ ", choice='"
|
||||
+ choice
|
||||
+ '\''
|
||||
+ ", choiceArgument="
|
||||
+ choiceArgument
|
||||
+ ", actingParties="
|
||||
+ actingParties
|
||||
+ ", consuming="
|
||||
+ consuming
|
||||
+ ", childEventIds="
|
||||
+ childEventIds
|
||||
+ ", exerciseResult="
|
||||
+ exerciseResult
|
||||
+ '}';
|
||||
}
|
||||
|
||||
public EventOuterClass.@NonNull ExercisedEvent toProto() {
|
||||
EventOuterClass.ExercisedEvent.Builder builder = EventOuterClass.ExercisedEvent.newBuilder();
|
||||
builder.setEventId(getEventId());
|
||||
builder.setChoice(getChoice());
|
||||
builder.setChoiceArgument(getChoiceArgument().toProto());
|
||||
builder.setConsuming(isConsuming());
|
||||
builder.setContractId(getContractId());
|
||||
builder.setTemplateId(getTemplateId().toProto());
|
||||
interfaceId.ifPresent(i -> builder.setInterfaceId(i.toProto()));
|
||||
builder.addAllActingParties(getActingParties());
|
||||
builder.addAllWitnessParties(getWitnessParties());
|
||||
builder.addAllChildEventIds(getChildEventIds());
|
||||
builder.setExerciseResult(getExerciseResult().toProto());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static ExercisedEvent fromProto(EventOuterClass.ExercisedEvent exercisedEvent) {
|
||||
return new ExercisedEvent(
|
||||
exercisedEvent.getWitnessPartiesList(),
|
||||
exercisedEvent.getEventId(),
|
||||
Identifier.fromProto(exercisedEvent.getTemplateId()),
|
||||
exercisedEvent.hasInterfaceId()
|
||||
? Optional.of(Identifier.fromProto(exercisedEvent.getInterfaceId()))
|
||||
: Optional.empty(),
|
||||
exercisedEvent.getContractId(),
|
||||
exercisedEvent.getChoice(),
|
||||
Value.fromProto(exercisedEvent.getChoiceArgument()),
|
||||
exercisedEvent.getActingPartiesList(),
|
||||
exercisedEvent.getConsuming(),
|
||||
exercisedEvent.getChildEventIdsList(),
|
||||
Value.fromProto(exercisedEvent.getExerciseResult()));
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionFilterOuterClass;
|
||||
|
||||
public abstract class Filter {
|
||||
|
||||
public static Filter fromProto(TransactionFilterOuterClass.Filters filters) {
|
||||
if (filters.hasInclusive()) {
|
||||
return InclusiveFilter.fromProto(filters.getInclusive());
|
||||
} else {
|
||||
return NoFilter.instance;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract TransactionFilterOuterClass.Filters toProto();
|
||||
|
||||
/**
|
||||
* Settings for including an interface in {@link InclusiveFilter}. There are four possible values:
|
||||
* {@link #HIDE_VIEW_HIDE_CREATED_EVENT_BLOB} and {@link #INCLUDE_VIEW_HIDE_CREATED_EVENT_BLOB}
|
||||
* and {@link #HIDE_VIEW_INCLUDE_CREATED_EVENT_BLOB} and {@link
|
||||
* #INCLUDE_VIEW_INCLUDE_CREATED_EVENT_BLOB}.
|
||||
*/
|
||||
public static enum Interface {
|
||||
HIDE_VIEW_HIDE_CREATED_EVENT_BLOB(false, false),
|
||||
INCLUDE_VIEW_HIDE_CREATED_EVENT_BLOB(true, false),
|
||||
HIDE_VIEW_INCLUDE_CREATED_EVENT_BLOB(false, true),
|
||||
INCLUDE_VIEW_INCLUDE_CREATED_EVENT_BLOB(true, true);
|
||||
|
||||
public final boolean includeInterfaceView;
|
||||
public final boolean includeCreatedEventBlob;
|
||||
|
||||
Interface(boolean includeInterfaceView, boolean includeCreatedEventBlob) {
|
||||
this.includeInterfaceView = includeInterfaceView;
|
||||
this.includeCreatedEventBlob = includeCreatedEventBlob;
|
||||
}
|
||||
|
||||
private static Interface includeInterfaceView(
|
||||
boolean includeInterfaceView, boolean includeCreatedEventBlob) {
|
||||
if (!includeInterfaceView && !includeCreatedEventBlob)
|
||||
return HIDE_VIEW_HIDE_CREATED_EVENT_BLOB;
|
||||
else if (includeInterfaceView && !includeCreatedEventBlob)
|
||||
return INCLUDE_VIEW_HIDE_CREATED_EVENT_BLOB;
|
||||
else if (!includeInterfaceView) return HIDE_VIEW_INCLUDE_CREATED_EVENT_BLOB;
|
||||
else return INCLUDE_VIEW_INCLUDE_CREATED_EVENT_BLOB;
|
||||
}
|
||||
|
||||
public TransactionFilterOuterClass.InterfaceFilter toProto(Identifier interfaceId) {
|
||||
return TransactionFilterOuterClass.InterfaceFilter.newBuilder()
|
||||
.setInterfaceId(interfaceId.toProto())
|
||||
.setIncludeInterfaceView(includeInterfaceView)
|
||||
.build();
|
||||
}
|
||||
|
||||
static Interface fromProto(TransactionFilterOuterClass.InterfaceFilter proto) {
|
||||
return includeInterfaceView(
|
||||
proto.getIncludeInterfaceView(), proto.getIncludeCreatedEventBlob());
|
||||
}
|
||||
|
||||
Interface merge(Interface other) {
|
||||
return includeInterfaceView(
|
||||
includeInterfaceView || other.includeInterfaceView,
|
||||
includeCreatedEventBlob || other.includeCreatedEventBlob);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Template {
|
||||
INCLUDE_CREATED_EVENT_BLOB(true),
|
||||
HIDE_CREATED_EVENT_BLOB(false);
|
||||
public final boolean includeCreatedEventBlob;
|
||||
|
||||
Template(boolean includeCreatedEventBlob) {
|
||||
this.includeCreatedEventBlob = includeCreatedEventBlob;
|
||||
}
|
||||
|
||||
private static Template includeCreatedEventBlob(boolean includeCreatedEventBlob) {
|
||||
return includeCreatedEventBlob ? INCLUDE_CREATED_EVENT_BLOB : HIDE_CREATED_EVENT_BLOB;
|
||||
}
|
||||
|
||||
public TransactionFilterOuterClass.TemplateFilter toProto(Identifier templateId) {
|
||||
return TransactionFilterOuterClass.TemplateFilter.newBuilder()
|
||||
.setTemplateId(templateId.toProto())
|
||||
.setIncludeCreatedEventBlob(includeCreatedEventBlob)
|
||||
.build();
|
||||
}
|
||||
|
||||
static Template fromProto(TransactionFilterOuterClass.TemplateFilter proto) {
|
||||
return includeCreatedEventBlob(proto.getIncludeCreatedEventBlob());
|
||||
}
|
||||
|
||||
Template merge(Template other) {
|
||||
return includeCreatedEventBlob(includeCreatedEventBlob || other.includeCreatedEventBlob);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionFilterOuterClass;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class FiltersByParty extends TransactionFilter {
|
||||
|
||||
private Map<String, Filter> partyToFilters;
|
||||
|
||||
@Override
|
||||
public Set<String> getParties() {
|
||||
return partyToFilters.keySet();
|
||||
}
|
||||
|
||||
public FiltersByParty(@NonNull Map<@NonNull String, @NonNull Filter> partyToFilters) {
|
||||
this.partyToFilters = partyToFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionFilterOuterClass.TransactionFilter toProto() {
|
||||
HashMap<String, TransactionFilterOuterClass.Filters> partyToFilters =
|
||||
new HashMap<>(this.partyToFilters.size());
|
||||
for (Map.Entry<String, Filter> entry : this.partyToFilters.entrySet()) {
|
||||
partyToFilters.put(entry.getKey(), entry.getValue().toProto());
|
||||
}
|
||||
return TransactionFilterOuterClass.TransactionFilter.newBuilder()
|
||||
.putAllFiltersByParty(partyToFilters)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static FiltersByParty fromProto(
|
||||
TransactionFilterOuterClass.TransactionFilter transactionFilter) {
|
||||
Map<String, TransactionFilterOuterClass.Filters> partyToFilters =
|
||||
transactionFilter.getFiltersByPartyMap();
|
||||
HashMap<String, Filter> converted = new HashMap<>(partyToFilters.size());
|
||||
for (Map.Entry<String, TransactionFilterOuterClass.Filters> entry : partyToFilters.entrySet()) {
|
||||
converted.put(entry.getKey(), Filter.fromProto(entry.getValue()));
|
||||
}
|
||||
return new FiltersByParty(converted);
|
||||
}
|
||||
|
||||
public Map<String, Filter> getPartyToFilters() {
|
||||
return partyToFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FiltersByParty{" + "partyToFilters=" + partyToFilters + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FiltersByParty that = (FiltersByParty) o;
|
||||
return Objects.equals(partyToFilters, that.partyToFilters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(partyToFilters);
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ActiveContractsServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetActiveContractsRequest {
|
||||
|
||||
private final String ledgerId;
|
||||
|
||||
private final TransactionFilter transactionFilter;
|
||||
|
||||
private final boolean verbose;
|
||||
|
||||
public GetActiveContractsRequest(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull TransactionFilter transactionFilter,
|
||||
@NonNull boolean verbose) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.transactionFilter = transactionFilter;
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public static GetActiveContractsRequest fromProto(
|
||||
ActiveContractsServiceOuterClass.GetActiveContractsRequest request) {
|
||||
String ledgerId = request.getLedgerId();
|
||||
TransactionFilter filters = TransactionFilter.fromProto(request.getFilter());
|
||||
boolean verbose = request.getVerbose();
|
||||
return new GetActiveContractsRequest(ledgerId, filters, verbose);
|
||||
}
|
||||
|
||||
public ActiveContractsServiceOuterClass.GetActiveContractsRequest toProto() {
|
||||
return ActiveContractsServiceOuterClass.GetActiveContractsRequest.newBuilder()
|
||||
.setLedgerId(this.ledgerId)
|
||||
.setFilter(this.transactionFilter.toProto())
|
||||
.setVerbose(this.verbose)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getLedgerId() {
|
||||
return ledgerId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TransactionFilter getTransactionFilter() {
|
||||
return transactionFilter;
|
||||
}
|
||||
|
||||
public boolean isVerbose() {
|
||||
return verbose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetActiveContractsRequest that = (GetActiveContractsRequest) o;
|
||||
return verbose == that.verbose
|
||||
&& Objects.equals(ledgerId, that.ledgerId)
|
||||
&& Objects.equals(transactionFilter, that.transactionFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(ledgerId, transactionFilter, verbose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetActiveContractsRequest{"
|
||||
+ "ledgerId='"
|
||||
+ ledgerId
|
||||
+ '\''
|
||||
+ ", transactionFilter="
|
||||
+ transactionFilter
|
||||
+ ", verbose="
|
||||
+ verbose
|
||||
+ '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ActiveContractsServiceOuterClass;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetActiveContractsResponse implements WorkflowEvent {
|
||||
|
||||
private final String offset;
|
||||
|
||||
private final java.util.List<CreatedEvent> activeContracts;
|
||||
|
||||
private final String workflowId;
|
||||
|
||||
public GetActiveContractsResponse(
|
||||
@NonNull String offset, @NonNull List<CreatedEvent> activeContracts, String workflowId) {
|
||||
this.offset = offset;
|
||||
this.activeContracts = activeContracts;
|
||||
this.workflowId = workflowId;
|
||||
}
|
||||
|
||||
public static GetActiveContractsResponse fromProto(
|
||||
ActiveContractsServiceOuterClass.GetActiveContractsResponse response) {
|
||||
List<CreatedEvent> events =
|
||||
response.getActiveContractsList().stream()
|
||||
.map(CreatedEvent::fromProto)
|
||||
.collect(Collectors.toList());
|
||||
return new GetActiveContractsResponse(response.getOffset(), events, response.getWorkflowId());
|
||||
}
|
||||
|
||||
public ActiveContractsServiceOuterClass.GetActiveContractsResponse toProto() {
|
||||
return ActiveContractsServiceOuterClass.GetActiveContractsResponse.newBuilder()
|
||||
.setOffset(this.offset)
|
||||
.addAllActiveContracts(
|
||||
this.activeContracts.stream().map(CreatedEvent::toProto).collect(Collectors.toList()))
|
||||
.setWorkflowId(this.workflowId)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<String> getOffset() {
|
||||
// Empty string indicates that the field is not present in the protobuf.
|
||||
return Optional.of(offset).filter(off -> !offset.equals(""));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull CreatedEvent> getCreatedEvents() {
|
||||
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;
|
||||
GetActiveContractsResponse that = (GetActiveContractsResponse) 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class GetEventsByContractIdResponse {
|
||||
private final Optional<CreatedEvent> createEvent;
|
||||
|
||||
private final Optional<ArchivedEvent> archiveEvent;
|
||||
|
||||
public GetEventsByContractIdResponse(
|
||||
Optional<CreatedEvent> createEvent, Optional<ArchivedEvent> archiveEvent) {
|
||||
this.createEvent = createEvent;
|
||||
this.archiveEvent = archiveEvent;
|
||||
}
|
||||
|
||||
public Optional<CreatedEvent> getCreateEvent() {
|
||||
return createEvent;
|
||||
}
|
||||
|
||||
public Optional<ArchivedEvent> getArchiveEvent() {
|
||||
return archiveEvent;
|
||||
}
|
||||
|
||||
public static GetEventsByContractIdResponse fromProto(
|
||||
com.daml.ledger.api.v1.EventQueryServiceOuterClass.GetEventsByContractIdResponse response) {
|
||||
return new GetEventsByContractIdResponse(
|
||||
response.hasCreateEvent()
|
||||
? Optional.of(CreatedEvent.fromProto(response.getCreateEvent()))
|
||||
: Optional.empty(),
|
||||
response.hasArchiveEvent()
|
||||
? Optional.of(ArchivedEvent.fromProto(response.getArchiveEvent()))
|
||||
: Optional.empty());
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class GetEventsByContractKeyResponse {
|
||||
private final Optional<CreatedEvent> createEvent;
|
||||
private final Optional<ArchivedEvent> archiveEvent;
|
||||
private final Optional<String> continuationToken;
|
||||
|
||||
public GetEventsByContractKeyResponse(
|
||||
Optional<CreatedEvent> createEvent,
|
||||
Optional<ArchivedEvent> archiveEvent,
|
||||
Optional<String> continuationToken) {
|
||||
this.createEvent = createEvent;
|
||||
this.archiveEvent = archiveEvent;
|
||||
this.continuationToken = continuationToken;
|
||||
}
|
||||
|
||||
public Optional<CreatedEvent> getCreateEvent() {
|
||||
return createEvent;
|
||||
}
|
||||
|
||||
public Optional<ArchivedEvent> getArchiveEvent() {
|
||||
return archiveEvent;
|
||||
}
|
||||
|
||||
public Optional<String> getContinuationToken() {
|
||||
return continuationToken;
|
||||
}
|
||||
|
||||
public static GetEventsByContractKeyResponse fromProto(
|
||||
com.daml.ledger.api.v1.EventQueryServiceOuterClass.GetEventsByContractKeyResponse response) {
|
||||
return new GetEventsByContractKeyResponse(
|
||||
response.hasCreateEvent()
|
||||
? Optional.of(CreatedEvent.fromProto(response.getCreateEvent()))
|
||||
: Optional.empty(),
|
||||
response.hasArchiveEvent()
|
||||
? Optional.of(ArchivedEvent.fromProto(response.getArchiveEvent()))
|
||||
: Optional.empty(),
|
||||
response.getContinuationToken().isEmpty()
|
||||
? Optional.of(response.getContinuationToken())
|
||||
: Optional.empty());
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetFlatTransactionResponse {
|
||||
|
||||
private final Transaction transaction;
|
||||
|
||||
public GetFlatTransactionResponse(@NonNull Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public static GetFlatTransactionResponse fromProto(
|
||||
TransactionServiceOuterClass.GetFlatTransactionResponse response) {
|
||||
return new GetFlatTransactionResponse(Transaction.fromProto(response.getTransaction()));
|
||||
}
|
||||
|
||||
public TransactionServiceOuterClass.GetFlatTransactionResponse toProto() {
|
||||
return TransactionServiceOuterClass.GetFlatTransactionResponse.newBuilder()
|
||||
.setTransaction(this.transaction.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
public Transaction getTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetFlatTransactionResponse{" + "transaction=" + transaction + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetFlatTransactionResponse that = (GetFlatTransactionResponse) o;
|
||||
return Objects.equals(transaction, that.transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(transaction);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetLedgerEndResponse {
|
||||
|
||||
private final LedgerOffset offset;
|
||||
|
||||
public GetLedgerEndResponse(@NonNull LedgerOffset offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static GetLedgerEndResponse fromProto(
|
||||
TransactionServiceOuterClass.GetLedgerEndResponse response) {
|
||||
return new GetLedgerEndResponse(LedgerOffset.fromProto(response.getOffset()));
|
||||
}
|
||||
|
||||
public TransactionServiceOuterClass.GetLedgerEndResponse toProto() {
|
||||
return TransactionServiceOuterClass.GetLedgerEndResponse.newBuilder()
|
||||
.setOffset(this.offset.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public LedgerOffset getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetLedgerEndResponse{" + "offset=" + offset + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetLedgerEndResponse that = (GetLedgerEndResponse) o;
|
||||
return Objects.equals(offset, that.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(offset);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetPackageResponse {
|
||||
|
||||
// Clone of the PackageServiceOuterClass.HashFunction enumeration
|
||||
public enum HashFunction {
|
||||
SHA256(0),
|
||||
UNRECOGNIZED(-1),
|
||||
;
|
||||
|
||||
private final int value;
|
||||
|
||||
private static Map<Integer, GetPackageResponse.HashFunction> valueToEnumMap =
|
||||
EnumSet.allOf(GetPackageResponse.HashFunction.class).stream()
|
||||
.collect(Collectors.toMap(e -> e.value, Function.identity()));
|
||||
|
||||
private HashFunction(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static GetPackageResponse.HashFunction valueOf(int value) {
|
||||
return valueToEnumMap.getOrDefault(value, UNRECOGNIZED);
|
||||
}
|
||||
}
|
||||
|
||||
private final HashFunction hashFunction;
|
||||
private final String hash;
|
||||
private final ByteString archivePayload;
|
||||
|
||||
public GetPackageResponse(
|
||||
HashFunction hashFunction, @NonNull String hash, @NonNull ByteString archivePayload) {
|
||||
this.hashFunction = hashFunction;
|
||||
this.hash = hash;
|
||||
this.archivePayload = archivePayload;
|
||||
}
|
||||
|
||||
public HashFunction getHashFunction() {
|
||||
return hashFunction;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public byte[] getArchivePayload() {
|
||||
return archivePayload.toByteArray();
|
||||
}
|
||||
|
||||
public static GetPackageResponse fromProto(
|
||||
com.daml.ledger.api.v1.PackageServiceOuterClass.GetPackageResponse p) {
|
||||
return new GetPackageResponse(
|
||||
HashFunction.valueOf(p.getHashFunctionValue()), p.getHash(), p.getArchivePayload());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class GetPackageStatusResponse {
|
||||
|
||||
// Clone of the PackageServiceOuterClass.PackageStatus enumeration
|
||||
public enum PackageStatus {
|
||||
UNKNOWN(0),
|
||||
REGISTERED(1),
|
||||
UNRECOGNIZED(-1),
|
||||
;
|
||||
|
||||
private final int value;
|
||||
|
||||
private static Map<Integer, PackageStatus> valueToEnumMap =
|
||||
EnumSet.allOf(PackageStatus.class).stream()
|
||||
.collect(Collectors.toMap(e -> e.value, Function.identity()));
|
||||
|
||||
private PackageStatus(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static PackageStatus valueOf(int value) {
|
||||
return valueToEnumMap.getOrDefault(value, UNRECOGNIZED);
|
||||
}
|
||||
}
|
||||
|
||||
private final PackageStatus packageStatus;
|
||||
|
||||
public GetPackageStatusResponse(PackageStatus packageStatus) {
|
||||
this.packageStatus = packageStatus;
|
||||
}
|
||||
|
||||
public PackageStatus getPackageStatusValue() {
|
||||
return packageStatus;
|
||||
}
|
||||
|
||||
public static GetPackageStatusResponse fromProto(
|
||||
com.daml.ledger.api.v1.PackageServiceOuterClass.GetPackageStatusResponse p) {
|
||||
return new GetPackageStatusResponse(PackageStatus.valueOf(p.getPackageStatusValue()));
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetTransactionResponse {
|
||||
|
||||
private final TransactionTree transaction;
|
||||
|
||||
public GetTransactionResponse(@NonNull TransactionTree transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public static GetTransactionResponse fromProto(
|
||||
TransactionServiceOuterClass.GetTransactionResponse response) {
|
||||
return new GetTransactionResponse(TransactionTree.fromProto(response.getTransaction()));
|
||||
}
|
||||
|
||||
public TransactionServiceOuterClass.GetTransactionResponse toProto() {
|
||||
return TransactionServiceOuterClass.GetTransactionResponse.newBuilder()
|
||||
.setTransaction(this.transaction.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
public TransactionTree getTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetTransactionResponse{" + "transaction=" + transaction + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetTransactionResponse that = (GetTransactionResponse) o;
|
||||
return Objects.equals(transaction, that.transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(transaction);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionOuterClass;
|
||||
import com.daml.ledger.api.v1.TransactionServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetTransactionTreesResponse {
|
||||
|
||||
private final List<TransactionTree> transactions;
|
||||
|
||||
public GetTransactionTreesResponse(@NonNull List<@NonNull TransactionTree> transactions) {
|
||||
this.transactions = transactions;
|
||||
}
|
||||
|
||||
public static GetTransactionTreesResponse fromProto(
|
||||
TransactionServiceOuterClass.GetTransactionTreesResponse response) {
|
||||
ArrayList<TransactionTree> transactionTrees = new ArrayList<>(response.getTransactionsCount());
|
||||
for (TransactionOuterClass.TransactionTree transactionTree : response.getTransactionsList()) {
|
||||
transactionTrees.add(TransactionTree.fromProto(transactionTree));
|
||||
}
|
||||
return new GetTransactionTreesResponse(transactionTrees);
|
||||
}
|
||||
|
||||
public TransactionServiceOuterClass.GetTransactionTreesResponse toProto() {
|
||||
ArrayList<TransactionOuterClass.TransactionTree> transactionTrees =
|
||||
new ArrayList<>(this.transactions.size());
|
||||
for (TransactionTree transactionTree : this.transactions) {
|
||||
transactionTrees.add(transactionTree.toProto());
|
||||
}
|
||||
return TransactionServiceOuterClass.GetTransactionTreesResponse.newBuilder()
|
||||
.addAllTransactions(transactionTrees)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull TransactionTree> getTransactions() {
|
||||
return transactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetTransactionTreesResponse{" + "transactions=" + transactions + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetTransactionTreesResponse that = (GetTransactionTreesResponse) o;
|
||||
return Objects.equals(transactions, that.transactions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(transactions);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionServiceOuterClass;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetTransactionsRequest {
|
||||
|
||||
private final String ledgerId;
|
||||
|
||||
private final LedgerOffset begin;
|
||||
|
||||
private final Optional<LedgerOffset> end;
|
||||
|
||||
private final TransactionFilter filter;
|
||||
|
||||
private final boolean verbose;
|
||||
|
||||
public GetTransactionsRequest(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull LedgerOffset begin,
|
||||
@NonNull LedgerOffset end,
|
||||
@NonNull TransactionFilter filter,
|
||||
boolean verbose) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.begin = begin;
|
||||
this.end = Optional.of(end);
|
||||
this.filter = filter;
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public GetTransactionsRequest(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull LedgerOffset begin,
|
||||
@NonNull TransactionFilter filter,
|
||||
boolean verbose) {
|
||||
this.ledgerId = ledgerId;
|
||||
this.begin = begin;
|
||||
this.end = Optional.empty();
|
||||
this.filter = filter;
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public static GetTransactionsRequest fromProto(
|
||||
TransactionServiceOuterClass.GetTransactionsRequest request) {
|
||||
String ledgerId = request.getLedgerId();
|
||||
LedgerOffset begin = LedgerOffset.fromProto(request.getBegin());
|
||||
TransactionFilter filter = TransactionFilter.fromProto(request.getFilter());
|
||||
boolean verbose = request.getVerbose();
|
||||
if (request.hasEnd()) {
|
||||
LedgerOffset end = LedgerOffset.fromProto(request.getEnd());
|
||||
return new GetTransactionsRequest(ledgerId, begin, end, filter, verbose);
|
||||
} else {
|
||||
return new GetTransactionsRequest(ledgerId, begin, filter, verbose);
|
||||
}
|
||||
}
|
||||
|
||||
public TransactionServiceOuterClass.GetTransactionsRequest toProto() {
|
||||
TransactionServiceOuterClass.GetTransactionsRequest.Builder builder =
|
||||
TransactionServiceOuterClass.GetTransactionsRequest.newBuilder();
|
||||
builder.setLedgerId(this.ledgerId);
|
||||
builder.setBegin(this.begin.toProto());
|
||||
this.end.ifPresent(end -> builder.setEnd(end.toProto()));
|
||||
builder.setFilter(this.filter.toProto());
|
||||
builder.setVerbose(this.verbose);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionOuterClass;
|
||||
import com.daml.ledger.api.v1.TransactionServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetTransactionsResponse {
|
||||
|
||||
private final List<Transaction> transactions;
|
||||
|
||||
public GetTransactionsResponse(@NonNull List<@NonNull Transaction> transactions) {
|
||||
this.transactions = transactions;
|
||||
}
|
||||
|
||||
public static GetTransactionsResponse fromProto(
|
||||
TransactionServiceOuterClass.GetTransactionsResponse response) {
|
||||
ArrayList<Transaction> transactions = new ArrayList<>(response.getTransactionsCount());
|
||||
for (TransactionOuterClass.Transaction transaction : response.getTransactionsList()) {
|
||||
transactions.add(Transaction.fromProto(transaction));
|
||||
}
|
||||
return new GetTransactionsResponse(transactions);
|
||||
}
|
||||
|
||||
public TransactionServiceOuterClass.GetTransactionsResponse toProto() {
|
||||
ArrayList<TransactionOuterClass.Transaction> transactions =
|
||||
new ArrayList<>(this.transactions.size());
|
||||
for (Transaction transaction : this.transactions) {
|
||||
transactions.add(transaction.toProto());
|
||||
}
|
||||
return TransactionServiceOuterClass.GetTransactionsResponse.newBuilder()
|
||||
.addAllTransactions(transactions)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull Transaction> getTransactions() {
|
||||
return transactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetTransactionsResponse{" + "transactions=" + transactions + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetTransactionsResponse that = (GetTransactionsResponse) o;
|
||||
return Objects.equals(transactions, that.transactions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(transactions);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GetUserRequest {
|
||||
|
||||
private final String userId;
|
||||
|
||||
public GetUserRequest(@NonNull String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetUserRequest{" + "userId='" + userId + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetUserRequest that = (GetUserRequest) o;
|
||||
return Objects.equals(userId, that.userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.GetUserRequest toProto() {
|
||||
return UserManagementServiceOuterClass.GetUserRequest.newBuilder()
|
||||
.setUserId(this.userId)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class GetUserResponse {
|
||||
|
||||
private final User user;
|
||||
|
||||
public GetUserResponse(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public static GetUserResponse fromProto(UserManagementServiceOuterClass.GetUserResponse proto) {
|
||||
return new GetUserResponse(User.fromProto(proto.getUser()));
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.GetUserResponse toProto() {
|
||||
return UserManagementServiceOuterClass.GetUserResponse.newBuilder()
|
||||
.setUser(this.user.toProto())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetUserResponse{" + "user=" + user + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetUserResponse that = (GetUserResponse) o;
|
||||
return user.equals(that.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(user);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class GrantUserRightsRequest {
|
||||
|
||||
private final String userId;
|
||||
private final List<User.Right> rights;
|
||||
|
||||
public GrantUserRightsRequest(String userId, User.Right right, User.Right... rights) {
|
||||
this.userId = userId;
|
||||
this.rights = new ArrayList<>(rights.length + 1);
|
||||
this.rights.add(right);
|
||||
this.rights.addAll(Arrays.asList(rights));
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public List<User.Right> getRights() {
|
||||
return new ArrayList<>(rights);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.GrantUserRightsRequest toProto() {
|
||||
return UserManagementServiceOuterClass.GrantUserRightsRequest.newBuilder()
|
||||
.setUserId(this.userId)
|
||||
.addAllRights(this.rights.stream().map(User.Right::toProto).collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GrantUserRightsRequest{" + "userId=" + userId + ", rights=" + rights + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GrantUserRightsRequest that = (GrantUserRightsRequest) o;
|
||||
return userId.equals(that.userId) && rights.equals(that.rights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, rights);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class GrantUserRightsResponse {
|
||||
|
||||
private final List<User.Right> newlyGrantedRights;
|
||||
|
||||
public GrantUserRightsResponse(@NonNull List<User.Right> newlyGrantedRights) {
|
||||
this.newlyGrantedRights = new ArrayList<>(newlyGrantedRights);
|
||||
}
|
||||
|
||||
public List<User.Right> getNewlyGrantedRights() {
|
||||
return new ArrayList<>(this.newlyGrantedRights);
|
||||
}
|
||||
|
||||
public static GrantUserRightsResponse fromProto(
|
||||
UserManagementServiceOuterClass.GrantUserRightsResponse proto) {
|
||||
return new GrantUserRightsResponse(
|
||||
proto.getNewlyGrantedRightsList().stream()
|
||||
.map(User.Right::fromProto)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GrantUserRightsResponse{" + "newlyGrantedRights=" + newlyGrantedRights + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GrantUserRightsResponse that = (GrantUserRightsResponse) o;
|
||||
return Objects.equals(newlyGrantedRights, that.newlyGrantedRights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(newlyGrantedRights);
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Identifier {
|
||||
|
||||
private final String packageId;
|
||||
private final String moduleName;
|
||||
private final String entityName;
|
||||
|
||||
/**
|
||||
* This constructor is deprecated in favor of {@link Identifier#Identifier(String, String,
|
||||
* String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Identifier(@NonNull String packageId, @NonNull String name) {
|
||||
this.packageId = packageId;
|
||||
int lastDot = name.lastIndexOf('.');
|
||||
if (lastDot <= 0) {
|
||||
// The module component of the name must be at least 1 character long.
|
||||
// if no '.' is found or it is on the first position, then the name is not a valid identifier.
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Identifier name [%s] has wrong format. Dot-separated module and entity name"
|
||||
+ " expected (e.g.: Foo.Bar)",
|
||||
name));
|
||||
}
|
||||
this.moduleName = name.substring(0, lastDot);
|
||||
this.entityName = name.substring(lastDot + 1);
|
||||
}
|
||||
|
||||
public Identifier(
|
||||
@NonNull String packageId, @NonNull String moduleName, @NonNull String entityName) {
|
||||
this.packageId = packageId;
|
||||
this.moduleName = moduleName;
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Identifier fromProto(ValueOuterClass.Identifier identifier) {
|
||||
if (!identifier.getModuleName().isEmpty() && !identifier.getEntityName().isEmpty()) {
|
||||
return new Identifier(
|
||||
identifier.getPackageId(), identifier.getModuleName(), identifier.getEntityName());
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Invalid identifier [%s]: both module_name and entity_name must be set.",
|
||||
identifier));
|
||||
}
|
||||
}
|
||||
|
||||
public ValueOuterClass.Identifier toProto() {
|
||||
return ValueOuterClass.Identifier.newBuilder()
|
||||
.setPackageId(this.packageId)
|
||||
.setModuleName(this.moduleName)
|
||||
.setEntityName(this.entityName)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getPackageId() {
|
||||
return packageId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Deprecated
|
||||
public String getName() {
|
||||
return moduleName.concat(".").concat(entityName);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getModuleName() {
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Identifier that = (Identifier) o;
|
||||
return Objects.equals(packageId, that.packageId)
|
||||
&& Objects.equals(moduleName, that.moduleName)
|
||||
&& Objects.equals(entityName, that.entityName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(packageId, moduleName, entityName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Identifier{"
|
||||
+ "packageId='"
|
||||
+ packageId
|
||||
+ '\''
|
||||
+ ", moduleName='"
|
||||
+ moduleName
|
||||
+ '\''
|
||||
+ ", entityName='"
|
||||
+ entityName
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionFilterOuterClass;
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class InclusiveFilter extends Filter {
|
||||
|
||||
private Set<Identifier> templateIds;
|
||||
private Map<@NonNull Identifier, Filter.@NonNull Interface> interfaceFilters;
|
||||
private Map<@NonNull Identifier, Filter.@NonNull Template> templateFilters;
|
||||
|
||||
private InclusiveFilter(
|
||||
@NonNull Set<@NonNull Identifier> templateIds,
|
||||
@NonNull Map<@NonNull Identifier, Filter.@NonNull Interface> interfaceFilters,
|
||||
@NonNull Map<@NonNull Identifier, Filter.@NonNull Template> templateFilters) {
|
||||
this.templateIds = templateIds;
|
||||
this.interfaceFilters = interfaceFilters;
|
||||
this.templateFilters = templateFilters;
|
||||
}
|
||||
|
||||
public InclusiveFilter(
|
||||
@NonNull Map<@NonNull Identifier, Filter.@NonNull Interface> interfaceFilters,
|
||||
@NonNull Map<@NonNull Identifier, Filter.@NonNull Template> templateFilters) {
|
||||
this(Collections.emptySet(), interfaceFilters, templateFilters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #ofTemplateIds} instead; {@code templateIds} must not include interface
|
||||
* IDs. Since Daml 2.4.0
|
||||
*/
|
||||
@Deprecated
|
||||
public InclusiveFilter(@NonNull Set<@NonNull Identifier> templateIds) {
|
||||
this(templateIds, Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use the constructor with {@link #templateFilters} instead of IDs. Since Daml 2.8.0
|
||||
*/
|
||||
@Deprecated
|
||||
public InclusiveFilter(
|
||||
@NonNull Set<@NonNull Identifier> templateIds,
|
||||
@NonNull Map<@NonNull Identifier, Filter.@NonNull Interface> interfaceIds) {
|
||||
this(templateIds, interfaceIds, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static InclusiveFilter ofTemplateIds(@NonNull Set<@NonNull Identifier> templateIds) {
|
||||
return new InclusiveFilter(
|
||||
Collections.emptyMap(),
|
||||
templateIds.stream()
|
||||
.collect(
|
||||
Collectors.toUnmodifiableMap(
|
||||
Function.identity(), tId -> Template.HIDE_CREATED_EVENT_BLOB)));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Set<@NonNull Identifier> getTemplateIds() {
|
||||
return templateIds;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Map<@NonNull Identifier, Filter.@NonNull Interface> getInterfaceFilters() {
|
||||
return interfaceFilters;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Map<@NonNull Identifier, Filter.@NonNull Template> getTemplateFilters() {
|
||||
return templateFilters;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public TransactionFilterOuterClass.Filters toProto() {
|
||||
ArrayList<ValueOuterClass.Identifier> templateIds = new ArrayList<>(this.templateIds.size());
|
||||
for (Identifier identifier : this.templateIds) {
|
||||
templateIds.add(identifier.toProto());
|
||||
}
|
||||
TransactionFilterOuterClass.InclusiveFilters inclusiveFilter =
|
||||
TransactionFilterOuterClass.InclusiveFilters.newBuilder()
|
||||
.addAllTemplateIds(templateIds)
|
||||
.addAllInterfaceFilters(
|
||||
interfaceFilters.entrySet().stream()
|
||||
.map(idFilt -> idFilt.getValue().toProto(idFilt.getKey()))
|
||||
.collect(Collectors.toUnmodifiableList()))
|
||||
.addAllTemplateFilters(
|
||||
templateFilters.entrySet().stream()
|
||||
.map(
|
||||
templateFilter ->
|
||||
templateFilter.getValue().toProto(templateFilter.getKey()))
|
||||
.collect(Collectors.toUnmodifiableList()))
|
||||
.build();
|
||||
return TransactionFilterOuterClass.Filters.newBuilder().setInclusive(inclusiveFilter).build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static InclusiveFilter fromProto(
|
||||
TransactionFilterOuterClass.InclusiveFilters inclusiveFilters) {
|
||||
HashSet<Identifier> templateIds = new HashSet<>(inclusiveFilters.getTemplateIdsCount());
|
||||
for (ValueOuterClass.Identifier templateId : inclusiveFilters.getTemplateIdsList()) {
|
||||
templateIds.add(Identifier.fromProto(templateId));
|
||||
}
|
||||
var interfaceIds =
|
||||
inclusiveFilters.getInterfaceFiltersList().stream()
|
||||
.collect(
|
||||
Collectors.toUnmodifiableMap(
|
||||
ifFilt -> Identifier.fromProto(ifFilt.getInterfaceId()),
|
||||
Filter.Interface::fromProto,
|
||||
Filter.Interface::merge));
|
||||
var templateFilters =
|
||||
inclusiveFilters.getTemplateFiltersList().stream()
|
||||
.collect(
|
||||
Collectors.toUnmodifiableMap(
|
||||
templateFilter -> Identifier.fromProto(templateFilter.getTemplateId()),
|
||||
Filter.Template::fromProto,
|
||||
Filter.Template::merge));
|
||||
return new InclusiveFilter(templateIds, interfaceIds, templateFilters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InclusiveFilter{"
|
||||
+ "templateIds="
|
||||
+ templateIds
|
||||
+ ", interfaceFilters="
|
||||
+ interfaceFilters
|
||||
+ ", templateFilters="
|
||||
+ templateFilters
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
InclusiveFilter that = (InclusiveFilter) o;
|
||||
return Objects.equals(templateIds, that.templateIds)
|
||||
&& Objects.equals(interfaceFilters, that.interfaceFilters)
|
||||
&& Objects.equals(templateFilters, that.templateFilters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(templateIds, interfaceFilters, templateFilters);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Int64 extends Value {
|
||||
|
||||
private long value;
|
||||
|
||||
public Int64(long int64) {
|
||||
this.value = int64;
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setInt64(this.value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Int64{" + "value=" + value + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Int64 int64 = (Int64) o;
|
||||
return value == int64.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.LedgerOffsetOuterClass;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class LedgerOffset {
|
||||
|
||||
public static final class LedgerBegin extends LedgerOffset {
|
||||
static LedgerBegin instance = new LedgerBegin();
|
||||
|
||||
private LedgerBegin() {}
|
||||
|
||||
public static LedgerBegin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LedgerOffset.Begin";
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LedgerEnd extends LedgerOffset {
|
||||
static LedgerEnd instance = new LedgerEnd();
|
||||
|
||||
private LedgerEnd() {}
|
||||
|
||||
public static LedgerEnd getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LedgerOffset.End";
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Absolute extends LedgerOffset {
|
||||
private final String offset;
|
||||
|
||||
public Absolute(String offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public String getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LedgerOffset.Absolute(" + offset + ')';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Absolute absolute = (Absolute) o;
|
||||
return Objects.equals(offset, absolute.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(offset);
|
||||
}
|
||||
}
|
||||
|
||||
public static LedgerOffset fromProto(LedgerOffsetOuterClass.LedgerOffset ledgerOffset) {
|
||||
switch (ledgerOffset.getValueCase()) {
|
||||
case ABSOLUTE:
|
||||
return new Absolute(ledgerOffset.getAbsolute());
|
||||
case BOUNDARY:
|
||||
switch (ledgerOffset.getBoundary()) {
|
||||
case LEDGER_BEGIN:
|
||||
return LedgerBegin.instance;
|
||||
case LEDGER_END:
|
||||
return LedgerEnd.instance;
|
||||
case UNRECOGNIZED:
|
||||
default:
|
||||
throw new LedgerBoundaryUnrecognized(ledgerOffset.getBoundary());
|
||||
}
|
||||
case VALUE_NOT_SET:
|
||||
default:
|
||||
throw new LedgerBoundaryUnset(ledgerOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public final LedgerOffsetOuterClass.LedgerOffset toProto() {
|
||||
if (this instanceof LedgerBegin) {
|
||||
return LedgerOffsetOuterClass.LedgerOffset.newBuilder()
|
||||
.setBoundary(LedgerOffsetOuterClass.LedgerOffset.LedgerBoundary.LEDGER_BEGIN)
|
||||
.build();
|
||||
} else if (this instanceof LedgerEnd) {
|
||||
return LedgerOffsetOuterClass.LedgerOffset.newBuilder()
|
||||
.setBoundary(LedgerOffsetOuterClass.LedgerOffset.LedgerBoundary.LEDGER_END)
|
||||
.build();
|
||||
} else if (this instanceof Absolute) {
|
||||
Absolute absolute = (Absolute) this;
|
||||
return LedgerOffsetOuterClass.LedgerOffset.newBuilder().setAbsolute(absolute.offset).build();
|
||||
} else {
|
||||
throw new LedgerOffsetUnknown(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LedgerBoundaryUnrecognized extends RuntimeException {
|
||||
public LedgerBoundaryUnrecognized(LedgerOffsetOuterClass.LedgerOffset.LedgerBoundary boundary) {
|
||||
super("Ledger Boundary unknown " + boundary.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class LedgerBoundaryUnset extends RuntimeException {
|
||||
public LedgerBoundaryUnset(LedgerOffsetOuterClass.LedgerOffset offset) {
|
||||
super("Ledger Offset unset " + offset.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class LedgerOffsetUnknown extends RuntimeException {
|
||||
public LedgerOffsetUnknown(LedgerOffset offset) {
|
||||
super("Ledger offset unkwnown " + offset.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ListUserRightsRequest {
|
||||
|
||||
private final String userId;
|
||||
|
||||
public ListUserRightsRequest(@NonNull String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListUserRightsRequest{" + "userId='" + userId + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ListUserRightsRequest that = (ListUserRightsRequest) o;
|
||||
return Objects.equals(userId, that.userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.ListUserRightsRequest toProto() {
|
||||
return UserManagementServiceOuterClass.ListUserRightsRequest.newBuilder()
|
||||
.setUserId(this.userId)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ListUserRightsResponse {
|
||||
|
||||
private final List<User.Right> rights;
|
||||
|
||||
public ListUserRightsResponse(@NonNull List<User.Right> rights) {
|
||||
this.rights = new ArrayList<>(rights);
|
||||
}
|
||||
|
||||
public List<User.Right> getRights() {
|
||||
return new ArrayList<>(this.rights);
|
||||
}
|
||||
|
||||
public static ListUserRightsResponse fromProto(
|
||||
UserManagementServiceOuterClass.ListUserRightsResponse proto) {
|
||||
return new ListUserRightsResponse(
|
||||
proto.getRightsList().stream().map(User.Right::fromProto).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListUserRightsResponse{" + "rights=" + rights + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ListUserRightsResponse that = (ListUserRightsResponse) o;
|
||||
return Objects.equals(rights, that.rights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(rights);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ListUsersRequest {
|
||||
|
||||
private final Optional<String> pageToken;
|
||||
|
||||
private final Integer pageSize;
|
||||
|
||||
public ListUsersRequest(@NonNull Optional<String> pageToken, @NonNull Integer pageSize) {
|
||||
this.pageToken = pageToken;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Optional<String> getPageToken() {
|
||||
return pageToken;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListUsersRequest{" + "pageToken=" + pageToken + ", pageSize=" + pageSize + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ListUsersRequest that = (ListUsersRequest) o;
|
||||
return Objects.equals(pageToken, that.pageToken) && Objects.equals(pageSize, that.pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(pageToken, pageSize);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.ListUsersRequest toProto() {
|
||||
UserManagementServiceOuterClass.ListUsersRequest.Builder builder =
|
||||
UserManagementServiceOuterClass.ListUsersRequest.newBuilder();
|
||||
pageToken.ifPresent(builder::setPageToken);
|
||||
builder.setPageSize(pageSize);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class ListUsersResponse {
|
||||
|
||||
private final List<User> users;
|
||||
|
||||
public ListUsersResponse(@NonNull List<User> users) {
|
||||
this.users = new ArrayList<>(users);
|
||||
}
|
||||
|
||||
public List<User> getUsers() {
|
||||
return new ArrayList<>(this.users);
|
||||
}
|
||||
|
||||
public static ListUsersResponse fromProto(
|
||||
UserManagementServiceOuterClass.ListUsersResponse proto) {
|
||||
return new ListUsersResponse(
|
||||
proto.getUsersList().stream().map(User::fromProto).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListUsersResponse{" + "users=" + users + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ListUsersResponse that = (ListUsersResponse) o;
|
||||
return Objects.equals(users, that.users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(users);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionFilterOuterClass;
|
||||
|
||||
public final class NoFilter extends Filter {
|
||||
|
||||
public static final NoFilter instance = new NoFilter();
|
||||
|
||||
private NoFilter() {}
|
||||
|
||||
@Override
|
||||
public TransactionFilterOuterClass.Filters toProto() {
|
||||
return TransactionFilterOuterClass.Filters.getDefaultInstance();
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class Numeric extends Value {
|
||||
|
||||
private final BigDecimal value;
|
||||
|
||||
public Numeric(@NonNull BigDecimal value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Numeric fromProto(String numeric) {
|
||||
return new Numeric(new BigDecimal(numeric));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setNumeric(this.value.toPlainString()).build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Numeric{" + "value=" + value + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Numeric numeric = (Numeric) o;
|
||||
return Objects.equals(value, numeric.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Party extends Value {
|
||||
|
||||
private final String value;
|
||||
|
||||
public Party(@NonNull String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setParty(this.value).build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Party{" + "value='" + value + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Party party = (Party) o;
|
||||
return Objects.equals(value, party.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
// FIXME When removing this after the deprecation period is over, make DamlRecord final
|
||||
/** @deprecated Use {@link DamlRecord} instead. */
|
||||
@Deprecated
|
||||
public final class Record extends DamlRecord {
|
||||
|
||||
public Record(@NonNull Identifier recordId, @NonNull Field... fields) {
|
||||
this(recordId, Arrays.asList(fields));
|
||||
}
|
||||
|
||||
public Record(@NonNull Field... fields) {
|
||||
super(Arrays.asList(fields));
|
||||
}
|
||||
|
||||
public Record(@NonNull Identifier recordId, @NonNull List<@NonNull Field> fields) {
|
||||
super(recordId, unmodifiableList(fields));
|
||||
}
|
||||
|
||||
public Record(@NonNull List<@NonNull Field> fields) {
|
||||
super(unmodifiableList(fields));
|
||||
}
|
||||
|
||||
public Record(
|
||||
@NonNull Optional<Identifier> recordId,
|
||||
@NonNull List<@NonNull Field> fields,
|
||||
Map<String, Value> fieldsMap) {
|
||||
super(recordId, unmodifiableList(fields), fieldsMap);
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link DamlRecord#fromProto(ValueOuterClass.Record)} instead */
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public static Record fromProto(ValueOuterClass.Record record) {
|
||||
ArrayList<Field> fields = new ArrayList<>(record.getFieldsCount());
|
||||
HashMap<String, Value> fieldsMap = new HashMap<>(record.getFieldsCount());
|
||||
for (ValueOuterClass.RecordField recordField : record.getFieldsList()) {
|
||||
Field field = Field.fromProto(recordField);
|
||||
fields.add(field);
|
||||
if (field.getLabel().isPresent()) {
|
||||
fieldsMap.put(field.getLabel().get(), field.getValue());
|
||||
}
|
||||
}
|
||||
if (record.hasRecordId()) {
|
||||
Identifier recordId = Identifier.fromProto(record.getRecordId());
|
||||
return new Record(Optional.of(recordId), fields, fieldsMap);
|
||||
} else {
|
||||
return new Record(Optional.empty(), fields, fieldsMap);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME When removing this after the deprecation period is over, make DamlTextMap.Field final
|
||||
/** @deprecated Use {@link DamlRecord.Field} instead. */
|
||||
@Deprecated
|
||||
public static final class Field extends DamlRecord.Field {
|
||||
|
||||
public Field(@NonNull String label, @NonNull Value value) {
|
||||
super(label, value);
|
||||
}
|
||||
|
||||
public Field(@NonNull Value value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link DamlRecord.Field#fromProto(ValueOuterClass.Record)} instead */
|
||||
@Deprecated
|
||||
public static Field fromProto(ValueOuterClass.RecordField field) {
|
||||
String label = field.getLabel();
|
||||
Value value = Value.fromProto(field.getValue());
|
||||
return label.isEmpty() ? new Field(value) : new Field(label, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class RevokeUserRightsRequest {
|
||||
|
||||
private final String userId;
|
||||
private final List<User.Right> rights;
|
||||
|
||||
public RevokeUserRightsRequest(String userId, User.Right right, User.Right... rights) {
|
||||
this.userId = userId;
|
||||
this.rights = new ArrayList<>(rights.length + 1);
|
||||
this.rights.add(right);
|
||||
this.rights.addAll(Arrays.asList(rights));
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public List<User.Right> getRights() {
|
||||
return new ArrayList<>(rights);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.RevokeUserRightsRequest toProto() {
|
||||
return UserManagementServiceOuterClass.RevokeUserRightsRequest.newBuilder()
|
||||
.setUserId(this.userId)
|
||||
.addAllRights(this.rights.stream().map(User.Right::toProto).collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RevokeUserRightsRequest{" + "userId=" + userId + ", rights=" + rights + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
RevokeUserRightsRequest that = (RevokeUserRightsRequest) o;
|
||||
return userId.equals(that.userId) && rights.equals(that.rights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, rights);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class RevokeUserRightsResponse {
|
||||
|
||||
private final List<User.Right> newlyRevokedRights;
|
||||
|
||||
public RevokeUserRightsResponse(@NonNull List<User.Right> newlyRevokedRights) {
|
||||
this.newlyRevokedRights = new ArrayList<>(newlyRevokedRights);
|
||||
}
|
||||
|
||||
public List<User.Right> getNewlyRevokedRights() {
|
||||
return new ArrayList<>(this.newlyRevokedRights);
|
||||
}
|
||||
|
||||
public static RevokeUserRightsResponse fromProto(
|
||||
UserManagementServiceOuterClass.RevokeUserRightsResponse proto) {
|
||||
return new RevokeUserRightsResponse(
|
||||
proto.getNewlyRevokedRightsList().stream()
|
||||
.map(User.Right::fromProto)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RevokeUserRightsResponse{" + "newlyRevokedRights=" + newlyRevokedRights + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
RevokeUserRightsResponse that = (RevokeUserRightsResponse) o;
|
||||
return Objects.equals(newlyRevokedRights, that.newlyRevokedRights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(newlyRevokedRights);
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandServiceOuterClass;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class SubmitAndWaitRequest {
|
||||
|
||||
public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
|
||||
@NonNull String ledgerId, @NonNull CommandsSubmission submission) {
|
||||
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
|
||||
.setCommands(SubmitCommandsRequest.toProto(ledgerId, submission))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull CommandsSubmission submission) {
|
||||
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
|
||||
.setCommands(SubmitCommandsRequest.toProto(ledgerId, submissionId, submission))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
party,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
submissionId,
|
||||
party,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
submissionId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,571 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import static com.daml.ledger.javaapi.data.codegen.HasCommands.toCommands;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandsOuterClass;
|
||||
import com.google.protobuf.Timestamp;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class SubmitCommandsRequest {
|
||||
|
||||
private final String workflowId;
|
||||
|
||||
private final String applicationId;
|
||||
|
||||
private final String commandId;
|
||||
|
||||
private final String party;
|
||||
private final List<String> actAs;
|
||||
private final List<String> readAs;
|
||||
|
||||
private final Optional<Instant> minLedgerTimeAbsolute;
|
||||
private final Optional<Duration> minLedgerTimeRelative;
|
||||
private final Optional<Duration> deduplicationTime;
|
||||
private final Optional<String> submissionId;
|
||||
private final List<Command> commands;
|
||||
|
||||
public SubmitCommandsRequest(
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
this(
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
asList(party),
|
||||
asList(),
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
commands);
|
||||
}
|
||||
|
||||
public SubmitCommandsRequest(
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
this(
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
asList(party),
|
||||
asList(),
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.of(submissionId),
|
||||
commands);
|
||||
}
|
||||
|
||||
public SubmitCommandsRequest(
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
this(
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.empty(),
|
||||
commands);
|
||||
}
|
||||
|
||||
public SubmitCommandsRequest(
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
this(
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.of(submissionId),
|
||||
commands);
|
||||
}
|
||||
|
||||
private SubmitCommandsRequest(
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull Optional<String> submissionId,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
if (actAs.size() == 0) {
|
||||
throw new IllegalArgumentException("actAs must have at least one element");
|
||||
}
|
||||
this.workflowId = workflowId;
|
||||
this.applicationId = applicationId;
|
||||
this.commandId = commandId;
|
||||
this.party = actAs.get(0);
|
||||
this.actAs = List.copyOf(actAs);
|
||||
this.readAs = List.copyOf(readAs);
|
||||
this.minLedgerTimeAbsolute = minLedgerTimeAbsolute;
|
||||
this.minLedgerTimeRelative = minLedgerTimeRelative;
|
||||
this.deduplicationTime = deduplicationTime;
|
||||
this.submissionId = submissionId;
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public static SubmitCommandsRequest fromProto(CommandsOuterClass.Commands commands) {
|
||||
String workflowId = commands.getWorkflowId();
|
||||
String applicationId = commands.getApplicationId();
|
||||
String commandId = commands.getCommandId();
|
||||
String party = commands.getParty();
|
||||
List<String> actAs = commands.getActAsList();
|
||||
List<String> readAs = commands.getReadAsList();
|
||||
Optional<Instant> minLedgerTimeAbs =
|
||||
commands.hasMinLedgerTimeAbs()
|
||||
? Optional.of(
|
||||
Instant.ofEpochSecond(
|
||||
commands.getMinLedgerTimeAbs().getSeconds(),
|
||||
commands.getMinLedgerTimeAbs().getNanos()))
|
||||
: Optional.empty();
|
||||
Optional<Duration> minLedgerTimeRel =
|
||||
commands.hasMinLedgerTimeRel()
|
||||
? Optional.of(
|
||||
Duration.ofSeconds(
|
||||
commands.getMinLedgerTimeRel().getSeconds(),
|
||||
commands.getMinLedgerTimeRel().getNanos()))
|
||||
: Optional.empty();
|
||||
Optional<Duration> deduplicationPeriod = Optional.empty();
|
||||
switch (commands.getDeduplicationPeriodCase()) {
|
||||
case DEDUPLICATION_DURATION:
|
||||
com.google.protobuf.Duration d = commands.getDeduplicationDuration();
|
||||
deduplicationPeriod = Optional.of(Duration.ofSeconds(d.getSeconds(), d.getNanos()));
|
||||
break;
|
||||
case DEDUPLICATION_TIME:
|
||||
@SuppressWarnings("deprecation")
|
||||
com.google.protobuf.Duration t = commands.getDeduplicationTime();
|
||||
deduplicationPeriod = Optional.of(Duration.ofSeconds(t.getSeconds(), t.getNanos()));
|
||||
break;
|
||||
case DEDUPLICATIONPERIOD_NOT_SET:
|
||||
default:
|
||||
// Backwards compatibility: do not throw, this field could be empty from a previous version
|
||||
}
|
||||
String submissionId = commands.getSubmissionId();
|
||||
ArrayList<Command> listOfCommands = new ArrayList<>(commands.getCommandsCount());
|
||||
for (CommandsOuterClass.Command command : commands.getCommandsList()) {
|
||||
listOfCommands.add(Command.fromProtoCommand(command));
|
||||
}
|
||||
if (!actAs.contains(party)) {
|
||||
actAs.add(0, party);
|
||||
}
|
||||
return new SubmitCommandsRequest(
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationPeriod,
|
||||
submissionId.isEmpty() ? Optional.empty() : Optional.of(submissionId),
|
||||
listOfCommands);
|
||||
}
|
||||
|
||||
// TODO i15642 Refactor this to take CommmandsSubmission when deprecated methods using it below are
|
||||
// removed
|
||||
private static CommandsOuterClass.Commands deprecatedToProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull Optional<String> submissionId,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
if (actAs.size() == 0) {
|
||||
throw new IllegalArgumentException("actAs must have at least one element");
|
||||
}
|
||||
List<CommandsOuterClass.Command> commandsConverted =
|
||||
commands.stream().map(Command::toProtoCommand).collect(Collectors.toList());
|
||||
CommandsOuterClass.Commands.Builder builder =
|
||||
CommandsOuterClass.Commands.newBuilder()
|
||||
.setLedgerId(ledgerId)
|
||||
.setWorkflowId(workflowId)
|
||||
.setApplicationId(applicationId)
|
||||
.setCommandId(commandId)
|
||||
.setParty(actAs.get(0))
|
||||
.addAllActAs(actAs)
|
||||
.addAllReadAs(readAs)
|
||||
.addAllCommands(commandsConverted);
|
||||
minLedgerTimeAbsolute.ifPresent(
|
||||
abs ->
|
||||
builder.setMinLedgerTimeAbs(
|
||||
Timestamp.newBuilder().setSeconds(abs.getEpochSecond()).setNanos(abs.getNano())));
|
||||
minLedgerTimeRelative.ifPresent(
|
||||
rel ->
|
||||
builder.setMinLedgerTimeRel(
|
||||
com.google.protobuf.Duration.newBuilder()
|
||||
.setSeconds(rel.getSeconds())
|
||||
.setNanos(rel.getNano())));
|
||||
deduplicationTime.ifPresent(
|
||||
dedup -> {
|
||||
@SuppressWarnings("deprecation")
|
||||
var unused =
|
||||
builder.setDeduplicationTime(
|
||||
com.google.protobuf.Duration.newBuilder()
|
||||
.setSeconds(dedup.getSeconds())
|
||||
.setNanos(dedup.getNano()));
|
||||
});
|
||||
submissionId.ifPresent(builder::setSubmissionId);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull Optional<String> submissionId,
|
||||
@NonNull CommandsSubmission submission) {
|
||||
|
||||
if (submission.getActAs().size() == 0) {
|
||||
throw new IllegalArgumentException("actAs must have at least one element");
|
||||
}
|
||||
|
||||
List<Command> commands = toCommands(submission.getCommands());
|
||||
List<CommandsOuterClass.Command> commandsConverted =
|
||||
commands.stream().map(Command::toProtoCommand).collect(Collectors.toList());
|
||||
List<CommandsOuterClass.DisclosedContract> disclosedContracts =
|
||||
submission.getDisclosedContracts().stream()
|
||||
.map(DisclosedContract::toProto)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
CommandsOuterClass.Commands.Builder builder =
|
||||
CommandsOuterClass.Commands.newBuilder()
|
||||
.setLedgerId(ledgerId)
|
||||
.setApplicationId(submission.getApplicationId())
|
||||
.setCommandId(submission.getCommandId())
|
||||
.setParty(submission.getActAs().get(0))
|
||||
.addAllActAs(submission.getActAs())
|
||||
.addAllReadAs(submission.getReadAs())
|
||||
.addAllCommands(commandsConverted)
|
||||
.addAllDisclosedContracts(disclosedContracts);
|
||||
|
||||
submission
|
||||
.getMinLedgerTimeAbs()
|
||||
.ifPresent(
|
||||
abs ->
|
||||
builder.setMinLedgerTimeAbs(
|
||||
Timestamp.newBuilder()
|
||||
.setSeconds(abs.getEpochSecond())
|
||||
.setNanos(abs.getNano())));
|
||||
|
||||
submission
|
||||
.getMinLedgerTimeRel()
|
||||
.ifPresent(
|
||||
rel ->
|
||||
builder.setMinLedgerTimeRel(
|
||||
com.google.protobuf.Duration.newBuilder()
|
||||
.setSeconds(rel.getSeconds())
|
||||
.setNanos(rel.getNano())));
|
||||
|
||||
submission
|
||||
.getDeduplicationTime()
|
||||
.ifPresent(
|
||||
dedup -> {
|
||||
@SuppressWarnings("deprecation")
|
||||
var unused =
|
||||
builder.setDeduplicationTime(
|
||||
com.google.protobuf.Duration.newBuilder()
|
||||
.setSeconds(dedup.getSeconds())
|
||||
.setNanos(dedup.getNano()));
|
||||
});
|
||||
|
||||
submission.getWorkflowId().ifPresent(builder::setWorkflowId);
|
||||
submissionId.ifPresent(builder::setSubmissionId);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId, @NonNull CommandsSubmission submission) {
|
||||
return toProto(ledgerId, Optional.empty(), submission);
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return deprecatedToProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.empty(),
|
||||
commands);
|
||||
}
|
||||
|
||||
public static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull CommandsSubmission submission) {
|
||||
return toProto(ledgerId, Optional.of(submissionId), submission);
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return deprecatedToProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.of(submissionId),
|
||||
commands);
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
List<String> empty_read_as = new ArrayList<>();
|
||||
List<String> act_as = new ArrayList<>();
|
||||
act_as.add(party);
|
||||
return deprecatedToProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
act_as,
|
||||
empty_read_as,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.of(submissionId),
|
||||
commands);
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandsOuterClass.Commands toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbsolute,
|
||||
@NonNull Optional<Duration> minLedgerTimeRelative,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
List<String> empty_read_as = new ArrayList<>();
|
||||
List<String> act_as = new ArrayList<>();
|
||||
act_as.add(party);
|
||||
return deprecatedToProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
act_as,
|
||||
empty_read_as,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
Optional.empty(),
|
||||
commands);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getParty() {
|
||||
return party;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<String> getActAs() {
|
||||
return actAs;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<String> getReadAs() {
|
||||
return readAs;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Instant> getMinLedgerTimeAbsolute() {
|
||||
return minLedgerTimeAbsolute;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Duration> getMinLedgerTimeRelative() {
|
||||
return minLedgerTimeRelative;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Duration> getDeduplicationTime() {
|
||||
return deduplicationTime;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<String> getSubmissionId() {
|
||||
return submissionId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull Command> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SubmitCommandsRequest{"
|
||||
+ "workflowId='"
|
||||
+ workflowId
|
||||
+ '\''
|
||||
+ ", applicationId='"
|
||||
+ applicationId
|
||||
+ '\''
|
||||
+ ", commandId='"
|
||||
+ commandId
|
||||
+ '\''
|
||||
+ ", party='"
|
||||
+ party
|
||||
+ '\''
|
||||
+ ", minLedgerTimeAbs="
|
||||
+ minLedgerTimeAbsolute
|
||||
+ ", minLedgerTimeRel="
|
||||
+ minLedgerTimeRelative
|
||||
+ ", deduplicationTime="
|
||||
+ deduplicationTime
|
||||
+ ", submissionId="
|
||||
+ submissionId
|
||||
+ ", commands="
|
||||
+ commands
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SubmitCommandsRequest submitCommandsRequest1 = (SubmitCommandsRequest) o;
|
||||
return Objects.equals(workflowId, submitCommandsRequest1.workflowId)
|
||||
&& Objects.equals(applicationId, submitCommandsRequest1.applicationId)
|
||||
&& Objects.equals(commandId, submitCommandsRequest1.commandId)
|
||||
&& Objects.equals(party, submitCommandsRequest1.party)
|
||||
&& Objects.equals(actAs, submitCommandsRequest1.actAs)
|
||||
&& Objects.equals(readAs, submitCommandsRequest1.readAs)
|
||||
&& Objects.equals(minLedgerTimeAbsolute, submitCommandsRequest1.minLedgerTimeAbsolute)
|
||||
&& Objects.equals(minLedgerTimeRelative, submitCommandsRequest1.minLedgerTimeRelative)
|
||||
&& Objects.equals(deduplicationTime, submitCommandsRequest1.deduplicationTime)
|
||||
&& Objects.equals(submissionId, submitCommandsRequest1.submissionId)
|
||||
&& Objects.equals(commands, submitCommandsRequest1.commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
party,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbsolute,
|
||||
minLedgerTimeRelative,
|
||||
deduplicationTime,
|
||||
submissionId,
|
||||
commands);
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.CommandSubmissionServiceOuterClass;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class SubmitRequest {
|
||||
|
||||
public static CommandSubmissionServiceOuterClass.SubmitRequest toProto(
|
||||
@NonNull String ledgerId, @NonNull CommandsSubmission submission) {
|
||||
return CommandSubmissionServiceOuterClass.SubmitRequest.newBuilder()
|
||||
.setCommands(SubmitCommandsRequest.toProto(ledgerId, submission))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CommandSubmissionServiceOuterClass.SubmitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull CommandsSubmission submission) {
|
||||
return CommandSubmissionServiceOuterClass.SubmitRequest.newBuilder()
|
||||
.setCommands(SubmitCommandsRequest.toProto(ledgerId, submissionId, submission))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandSubmissionServiceOuterClass.SubmitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbs,
|
||||
@NonNull Optional<Duration> minLedgerTimeRel,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandSubmissionServiceOuterClass.SubmitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
party,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandSubmissionServiceOuterClass.SubmitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbs,
|
||||
@NonNull Optional<Duration> minLedgerTimeRel,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandSubmissionServiceOuterClass.SubmitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandSubmissionServiceOuterClass.SubmitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull String party,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbs,
|
||||
@NonNull Optional<Duration> minLedgerTimeRel,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandSubmissionServiceOuterClass.SubmitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
submissionId,
|
||||
party,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
|
||||
/** @deprecated since 2.5. Please use {@link #toProto(String, String, CommandsSubmission)} */
|
||||
@Deprecated
|
||||
public static CommandSubmissionServiceOuterClass.SubmitRequest toProto(
|
||||
@NonNull String ledgerId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull String applicationId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String submissionId,
|
||||
@NonNull List<@NonNull String> actAs,
|
||||
@NonNull List<@NonNull String> readAs,
|
||||
@NonNull Optional<Instant> minLedgerTimeAbs,
|
||||
@NonNull Optional<Duration> minLedgerTimeRel,
|
||||
@NonNull Optional<Duration> deduplicationTime,
|
||||
@NonNull List<@NonNull Command> commands) {
|
||||
return CommandSubmissionServiceOuterClass.SubmitRequest.newBuilder()
|
||||
.setCommands(
|
||||
SubmitCommandsRequest.toProto(
|
||||
ledgerId,
|
||||
workflowId,
|
||||
applicationId,
|
||||
commandId,
|
||||
submissionId,
|
||||
actAs,
|
||||
readAs,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
commands))
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package 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.ContractId;
|
||||
import com.daml.ledger.javaapi.data.codegen.CreateAnd;
|
||||
import com.daml.ledger.javaapi.data.codegen.Created;
|
||||
import com.daml.ledger.javaapi.data.codegen.Update;
|
||||
|
||||
public abstract class Template extends com.daml.ledger.javaapi.data.codegen.DamlRecord<Template> {
|
||||
|
||||
public abstract Update<? extends Created<? extends ContractId<? extends Template>>> create();
|
||||
|
||||
/**
|
||||
* Set up a {@link CreateAndExerciseCommand}; invoke an {@code exercise} method on the result of
|
||||
* this to finish creating the command, or convert to an interface first with {@code toInterface}
|
||||
* to invoke an interface {@code exercise} method.
|
||||
*/
|
||||
public abstract CreateAnd createAnd();
|
||||
|
||||
// with a self-type tparam to Template, that could replace every occurrence of
|
||||
// ? extends Template below
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by {@link ContractCompanion} and {@link
|
||||
* com.daml.ledger.javaapi.data.codegen.InterfaceCompanion}, and <em>should not be referenced
|
||||
* directly</em>. Applications should refer to other methods like {@link #getContractTypeId}
|
||||
* instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected abstract ContractCompanion<
|
||||
? extends
|
||||
Contract<
|
||||
? extends com.daml.ledger.javaapi.data.codegen.ContractId<? extends Template>,
|
||||
? extends Template>,
|
||||
? extends com.daml.ledger.javaapi.data.codegen.ContractId<? extends Template>,
|
||||
? extends Template>
|
||||
getCompanion();
|
||||
|
||||
/** The template ID for this template. */
|
||||
public final Identifier getContractTypeId() {
|
||||
return getCompanion().TEMPLATE_ID;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Text extends Value {
|
||||
|
||||
private final String value;
|
||||
|
||||
public Text(@NonNull String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setText(this.value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Text{" + "value='" + value + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Text text = (Text) o;
|
||||
return Objects.equals(value, text.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* A Timestamp value is represented as microseconds since the UNIX epoch.
|
||||
*
|
||||
* @see com.daml.ledger.api.v1.ValueOuterClass.Value#getTimestamp()
|
||||
*/
|
||||
public final class Timestamp extends Value {
|
||||
|
||||
/**
|
||||
* Constructs a {@link Timestamp} from milliseconds since UNIX epoch.
|
||||
*
|
||||
* @param millis milliseconds since UNIX epoch.
|
||||
*/
|
||||
@NonNull
|
||||
public static Timestamp fromMillis(long millis) {
|
||||
return new Timestamp(millis * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link Timestamp} value from an {@link Instant} up to microsecond precision. This
|
||||
* is a lossy conversion as nanoseconds are not preserved.
|
||||
*/
|
||||
@NonNull
|
||||
public static Timestamp fromInstant(@NonNull Instant instant) {
|
||||
return new Timestamp(instant.getEpochSecond() * 1_000_000L + instant.getNano() / 1000L);
|
||||
}
|
||||
|
||||
private final long value;
|
||||
|
||||
/**
|
||||
* Constructs a {@link Timestamp} from a microsecond value.
|
||||
*
|
||||
* @param value The number of microseconds since UNIX epoch.
|
||||
*/
|
||||
public Timestamp(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an alias for {@link Timestamp#toInstant()}
|
||||
*
|
||||
* @return the microseconds stored in this timestamp
|
||||
*/
|
||||
@NonNull
|
||||
public Instant getValue() {
|
||||
return toInstant();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public long getMicroseconds() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/** @return The point in time represented by this timestamp as {@link Instant}. */
|
||||
public Instant toInstant() {
|
||||
return Instant.ofEpochSecond(TimeUnit.MICROSECONDS.toSeconds(value), value % 1_000_000 * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setTimestamp(this.value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Timestamp{" + "value=" + value + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Timestamp timestamp = (Timestamp) o;
|
||||
return value == timestamp.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionOuterClass;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Transaction implements WorkflowEvent {
|
||||
|
||||
private final String transactionId;
|
||||
|
||||
private final String commandId;
|
||||
|
||||
private final String workflowId;
|
||||
|
||||
private final Instant effectiveAt;
|
||||
|
||||
private final java.util.List<Event> events;
|
||||
|
||||
private final String offset;
|
||||
|
||||
public Transaction(
|
||||
@NonNull String transactionId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull Instant effectiveAt,
|
||||
@NonNull List<@NonNull Event> events,
|
||||
@NonNull String offset) {
|
||||
this.transactionId = transactionId;
|
||||
this.commandId = commandId;
|
||||
this.workflowId = workflowId;
|
||||
this.effectiveAt = effectiveAt;
|
||||
this.events = events;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static Transaction fromProto(TransactionOuterClass.Transaction transaction) {
|
||||
String transactionId = transaction.getTransactionId();
|
||||
String commandId = transaction.getCommandId();
|
||||
Instant effectiveAt =
|
||||
Instant.ofEpochSecond(
|
||||
transaction.getEffectiveAt().getSeconds(), transaction.getEffectiveAt().getNanos());
|
||||
String workflowId = transaction.getWorkflowId();
|
||||
java.util.List<Event> events =
|
||||
transaction.getEventsList().stream()
|
||||
.map(Event::fromProtoEvent)
|
||||
.collect(Collectors.toList());
|
||||
String offset = transaction.getOffset();
|
||||
return new Transaction(transactionId, commandId, workflowId, effectiveAt, events, offset);
|
||||
}
|
||||
|
||||
public TransactionOuterClass.Transaction toProto() {
|
||||
return TransactionOuterClass.Transaction.newBuilder()
|
||||
.setTransactionId(this.transactionId)
|
||||
.setCommandId(this.commandId)
|
||||
.setEffectiveAt(
|
||||
com.google.protobuf.Timestamp.newBuilder()
|
||||
.setSeconds(this.effectiveAt.getEpochSecond())
|
||||
.setNanos(this.effectiveAt.getNano())
|
||||
.build())
|
||||
.addAllEvents(this.events.stream().map(Event::toProtoEvent).collect(Collectors.toList()))
|
||||
.setOffset(this.offset)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Instant getEffectiveAt() {
|
||||
return effectiveAt;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Event> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Transaction{"
|
||||
+ "transactionId='"
|
||||
+ transactionId
|
||||
+ '\''
|
||||
+ ", commandId='"
|
||||
+ commandId
|
||||
+ '\''
|
||||
+ ", workflowId='"
|
||||
+ workflowId
|
||||
+ '\''
|
||||
+ ", effectiveAt="
|
||||
+ effectiveAt
|
||||
+ ", events="
|
||||
+ events
|
||||
+ ", offset='"
|
||||
+ offset
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Transaction that = (Transaction) o;
|
||||
return Objects.equals(transactionId, that.transactionId)
|
||||
&& Objects.equals(commandId, that.commandId)
|
||||
&& Objects.equals(workflowId, that.workflowId)
|
||||
&& Objects.equals(effectiveAt, that.effectiveAt)
|
||||
&& Objects.equals(events, that.events)
|
||||
&& Objects.equals(offset, that.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(transactionId, commandId, workflowId, effectiveAt, events, offset);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
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 {
|
||||
|
||||
public static TransactionFilter fromProto(
|
||||
TransactionFilterOuterClass.TransactionFilter transactionFilter) {
|
||||
// at the moment, the only transaction filter supported is FiltersByParty
|
||||
return FiltersByParty.fromProto(transactionFilter);
|
||||
}
|
||||
|
||||
public abstract TransactionFilterOuterClass.TransactionFilter toProto();
|
||||
|
||||
public abstract Set<String> getParties();
|
||||
|
||||
public static TransactionFilter transactionFilter(
|
||||
ContractTypeCompanion<?, ?, ?, ?> contractCompanion, Set<String> parties) {
|
||||
Filter filter =
|
||||
(contractCompanion instanceof ContractCompanion)
|
||||
? new InclusiveFilter(
|
||||
Collections.emptyMap(),
|
||||
Collections.singletonMap(
|
||||
contractCompanion.TEMPLATE_ID, Filter.Template.HIDE_CREATED_EVENT_BLOB))
|
||||
: new InclusiveFilter(
|
||||
Map.of(
|
||||
contractCompanion.TEMPLATE_ID,
|
||||
Filter.Interface.INCLUDE_VIEW_HIDE_CREATED_EVENT_BLOB),
|
||||
Collections.emptyMap());
|
||||
Map<String, Filter> partyToFilters =
|
||||
parties.stream().collect(Collectors.toMap(Function.identity(), x -> filter));
|
||||
return new FiltersByParty(partyToFilters);
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionOuterClass;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class TransactionTree {
|
||||
|
||||
private final String transactionId;
|
||||
|
||||
private final String commandId;
|
||||
|
||||
private final String workflowId;
|
||||
|
||||
private final Instant effectiveAt;
|
||||
|
||||
private final Map<String, TreeEvent> eventsById;
|
||||
|
||||
private final List<String> rootEventIds;
|
||||
|
||||
private final String offset;
|
||||
|
||||
public TransactionTree(
|
||||
@NonNull String transactionId,
|
||||
@NonNull String commandId,
|
||||
@NonNull String workflowId,
|
||||
@NonNull Instant effectiveAt,
|
||||
@NonNull Map<@NonNull String, @NonNull TreeEvent> eventsById,
|
||||
List<String> rootEventIds,
|
||||
@NonNull String offset) {
|
||||
this.transactionId = transactionId;
|
||||
this.commandId = commandId;
|
||||
this.workflowId = workflowId;
|
||||
this.effectiveAt = effectiveAt;
|
||||
this.eventsById = eventsById;
|
||||
this.rootEventIds = rootEventIds;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static TransactionTree fromProto(TransactionOuterClass.TransactionTree tree) {
|
||||
String transactionId = tree.getTransactionId();
|
||||
String commandId = tree.getCommandId();
|
||||
String workflowId = tree.getWorkflowId();
|
||||
Instant effectiveAt =
|
||||
Instant.ofEpochSecond(tree.getEffectiveAt().getSeconds(), tree.getEffectiveAt().getNanos());
|
||||
Map<String, TreeEvent> eventsById =
|
||||
tree.getEventsByIdMap().values().stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
e -> {
|
||||
if (e.hasCreated()) return e.getCreated().getEventId();
|
||||
else if (e.hasExercised()) return e.getExercised().getEventId();
|
||||
else
|
||||
throw new IllegalArgumentException(
|
||||
"Event is neither created not exercied: " + e);
|
||||
},
|
||||
TreeEvent::fromProtoTreeEvent));
|
||||
List<String> rootEventIds = tree.getRootEventIdsList();
|
||||
String offset = tree.getOffset();
|
||||
return new TransactionTree(
|
||||
transactionId, commandId, workflowId, effectiveAt, eventsById, rootEventIds, offset);
|
||||
}
|
||||
|
||||
public TransactionOuterClass.TransactionTree toProto() {
|
||||
return TransactionOuterClass.TransactionTree.newBuilder()
|
||||
.setTransactionId(this.transactionId)
|
||||
.setCommandId(this.commandId)
|
||||
.setWorkflowId(this.workflowId)
|
||||
.setEffectiveAt(
|
||||
com.google.protobuf.Timestamp.newBuilder()
|
||||
.setSeconds(this.effectiveAt.getEpochSecond())
|
||||
.setNanos(this.effectiveAt.getNano())
|
||||
.build())
|
||||
.putAllEventsById(
|
||||
this.eventsById.values().stream()
|
||||
.collect(Collectors.toMap(TreeEvent::getEventId, TreeEvent::toProtoTreeEvent)))
|
||||
.addAllRootEventIds(this.rootEventIds)
|
||||
.setOffset(this.offset)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Instant getEffectiveAt() {
|
||||
return effectiveAt;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Map<String, TreeEvent> getEventsById() {
|
||||
return eventsById;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<String> getRootEventIds() {
|
||||
return rootEventIds;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TransactionTree{"
|
||||
+ "transactionId='"
|
||||
+ transactionId
|
||||
+ '\''
|
||||
+ ", commandId='"
|
||||
+ commandId
|
||||
+ '\''
|
||||
+ ", workflowId='"
|
||||
+ workflowId
|
||||
+ '\''
|
||||
+ ", effectiveAt="
|
||||
+ effectiveAt
|
||||
+ ", eventsById="
|
||||
+ eventsById
|
||||
+ ", rootEventIds="
|
||||
+ rootEventIds
|
||||
+ ", offset='"
|
||||
+ offset
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
TransactionTree that = (TransactionTree) o;
|
||||
return Objects.equals(transactionId, that.transactionId)
|
||||
&& Objects.equals(commandId, that.commandId)
|
||||
&& Objects.equals(workflowId, that.workflowId)
|
||||
&& Objects.equals(effectiveAt, that.effectiveAt)
|
||||
&& Objects.equals(eventsById, that.eventsById)
|
||||
&& Objects.equals(rootEventIds, that.rootEventIds)
|
||||
&& Objects.equals(offset, that.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
transactionId, commandId, workflowId, effectiveAt, eventsById, rootEventIds, offset);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.TransactionOuterClass;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* This interface represents events in {@link TransactionTree}s.
|
||||
*
|
||||
* @see CreatedEvent
|
||||
* @see ExercisedEvent
|
||||
* @see TransactionTree
|
||||
*/
|
||||
public interface TreeEvent {
|
||||
|
||||
@NonNull
|
||||
List<@NonNull String> getWitnessParties();
|
||||
|
||||
@NonNull
|
||||
String getEventId();
|
||||
|
||||
@NonNull
|
||||
Identifier getTemplateId();
|
||||
|
||||
@NonNull
|
||||
String getContractId();
|
||||
|
||||
default TransactionOuterClass.TreeEvent toProtoTreeEvent() {
|
||||
TransactionOuterClass.TreeEvent.Builder eventBuilder =
|
||||
TransactionOuterClass.TreeEvent.newBuilder();
|
||||
if (this instanceof CreatedEvent) {
|
||||
CreatedEvent event = (CreatedEvent) this;
|
||||
eventBuilder.setCreated(event.toProto());
|
||||
} else if (this instanceof ExercisedEvent) {
|
||||
ExercisedEvent event = (ExercisedEvent) this;
|
||||
eventBuilder.setExercised(event.toProto());
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"this should be CreatedEvent or ExercisedEvent, found " + this.toString());
|
||||
}
|
||||
return eventBuilder.build();
|
||||
}
|
||||
|
||||
static TreeEvent fromProtoTreeEvent(TransactionOuterClass.TreeEvent event) {
|
||||
if (event.hasCreated()) {
|
||||
return CreatedEvent.fromProto(event.getCreated());
|
||||
} else if (event.hasExercised()) {
|
||||
return ExercisedEvent.fromProto(event.getExercised());
|
||||
} else {
|
||||
throw new UnsupportedEventTypeException(event.toString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import com.google.protobuf.Empty;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Unit extends Value {
|
||||
|
||||
private static Unit instance = new Unit();
|
||||
|
||||
private Unit() {}
|
||||
|
||||
@NonNull
|
||||
public static Unit getInstance() {
|
||||
return Unit.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
Empty empty = Empty.newBuilder().build();
|
||||
ValueOuterClass.Value value = ValueOuterClass.Value.newBuilder().setUnit(empty).build();
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Unit{}";
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
public final class UnsupportedEventTypeException extends RuntimeException {
|
||||
public UnsupportedEventTypeException(String eventStr) {
|
||||
super("Unsupported event " + eventStr);
|
||||
}
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
import static java.util.Optional.empty;
|
||||
|
||||
import com.daml.ledger.javaapi.data.codegen.Update;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* This class can be used to build a valid submission for an Update. It provides {@link #create(String, String, Update)}
|
||||
* for initial creation and methods to set optional parameters
|
||||
* e.g {@link #withActAs(List)}, {@link #withWorkflowId(String)} etc.
|
||||
*
|
||||
* Usage:
|
||||
* <pre>
|
||||
* var submission = UpdateSubmission.create(applicationId, commandId, update)
|
||||
* .withAccessToken(token)
|
||||
* .withParty(party)
|
||||
* .with...
|
||||
* <pre/>
|
||||
*/
|
||||
public final class UpdateSubmission<U> {
|
||||
private String applicationId;
|
||||
private String commandId;
|
||||
private Update<U> update;
|
||||
|
||||
private Optional<String> workflowId;
|
||||
private List<@NonNull String> actAs;
|
||||
private List<@NonNull String> readAs;
|
||||
private Optional<Instant> minLedgerTimeAbs;
|
||||
private Optional<Duration> minLedgerTimeRel;
|
||||
private Optional<Duration> deduplicationTime;
|
||||
private Optional<String> accessToken;
|
||||
|
||||
private UpdateSubmission(
|
||||
String applicationId,
|
||||
String commandId,
|
||||
Update<U> update,
|
||||
List<@NonNull String> actAs,
|
||||
List<@NonNull String> readAs,
|
||||
Optional<String> workflowId,
|
||||
Optional<Instant> minLedgerTimeAbs,
|
||||
Optional<Duration> minLedgerTimeRel,
|
||||
Optional<Duration> deduplicationTime,
|
||||
Optional<String> accessToken) {
|
||||
this.workflowId = workflowId;
|
||||
this.applicationId = applicationId;
|
||||
this.commandId = commandId;
|
||||
this.actAs = actAs;
|
||||
this.readAs = readAs;
|
||||
this.minLedgerTimeAbs = minLedgerTimeAbs;
|
||||
this.minLedgerTimeRel = minLedgerTimeRel;
|
||||
this.deduplicationTime = deduplicationTime;
|
||||
this.update = update;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public static <U> UpdateSubmission<U> create(
|
||||
String applicationId, String commandId, Update<U> update) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
empty(),
|
||||
empty(),
|
||||
Optional.empty(),
|
||||
empty(),
|
||||
empty());
|
||||
}
|
||||
|
||||
public Optional<String> getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public String getCommandId() {
|
||||
return commandId;
|
||||
}
|
||||
|
||||
public List<String> getActAs() {
|
||||
return unmodifiableList(actAs);
|
||||
}
|
||||
|
||||
public List<String> getReadAs() {
|
||||
return unmodifiableList(readAs);
|
||||
}
|
||||
|
||||
public Optional<Instant> getMinLedgerTimeAbs() {
|
||||
return minLedgerTimeAbs;
|
||||
}
|
||||
|
||||
public Optional<Duration> getMinLedgerTimeRel() {
|
||||
return minLedgerTimeRel;
|
||||
}
|
||||
|
||||
public Optional<Duration> getDeduplicationTime() {
|
||||
return deduplicationTime;
|
||||
}
|
||||
|
||||
public Update<U> getUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
public Optional<String> getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withWorkflowId(String workflowId) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
Optional.of(workflowId),
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withActAs(String actAs) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
List.of(actAs),
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withActAs(List<@NonNull String> actAs) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withReadAs(List<@NonNull String> readAs) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withMinLedgerTimeAbs(Optional<Instant> minLedgerTimeAbs) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withMinLedgerTimeRel(Optional<Duration> minLedgerTimeRel) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withDeduplicationTime(Optional<Duration> deduplicationTime) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public UpdateSubmission<U> withAccessToken(Optional<String> accessToken) {
|
||||
return new UpdateSubmission<U>(
|
||||
applicationId,
|
||||
commandId,
|
||||
update,
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public CommandsSubmission toCommandsSubmission() {
|
||||
return new CommandsSubmission(
|
||||
applicationId,
|
||||
commandId,
|
||||
update.commands(),
|
||||
actAs,
|
||||
readAs,
|
||||
workflowId,
|
||||
minLedgerTimeAbs,
|
||||
minLedgerTimeRel,
|
||||
deduplicationTime,
|
||||
accessToken,
|
||||
emptyList());
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class User {
|
||||
|
||||
private final String id;
|
||||
private final Optional<String> primaryParty;
|
||||
|
||||
public User(@NonNull String id) {
|
||||
this.id = id;
|
||||
this.primaryParty = Optional.empty();
|
||||
}
|
||||
|
||||
public User(@NonNull String id, @NonNull String primaryParty) {
|
||||
this.id = id;
|
||||
this.primaryParty = Optional.of(primaryParty);
|
||||
}
|
||||
|
||||
public UserManagementServiceOuterClass.User toProto() {
|
||||
return UserManagementServiceOuterClass.User.newBuilder()
|
||||
.setId(id)
|
||||
.setPrimaryParty(primaryParty.orElse(null))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static User fromProto(UserManagementServiceOuterClass.User proto) {
|
||||
String id = proto.getId();
|
||||
String primaryParty = proto.getPrimaryParty();
|
||||
if (primaryParty == null || primaryParty.isEmpty()) {
|
||||
return new User(id);
|
||||
} else {
|
||||
return new User(id, primaryParty);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Optional<String> getPrimaryParty() {
|
||||
return primaryParty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{"
|
||||
+ "id='"
|
||||
+ id
|
||||
+ '\''
|
||||
+ primaryParty.map(p -> ", primaryParty='" + p + '\'').orElse("")
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
User user = (User) o;
|
||||
return Objects.equals(id, user.id) && Objects.equals(primaryParty, user.primaryParty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, primaryParty);
|
||||
}
|
||||
|
||||
public abstract static class Right {
|
||||
|
||||
abstract UserManagementServiceOuterClass.Right toProto();
|
||||
|
||||
public static Right fromProto(UserManagementServiceOuterClass.Right proto) {
|
||||
UserManagementServiceOuterClass.Right.KindCase kindCase = proto.getKindCase();
|
||||
Right right;
|
||||
switch (kindCase) {
|
||||
case CAN_ACT_AS:
|
||||
right = new CanActAs(proto.getCanActAs().getParty());
|
||||
break;
|
||||
case CAN_READ_AS:
|
||||
right = new CanReadAs(proto.getCanReadAs().getParty());
|
||||
break;
|
||||
case PARTICIPANT_ADMIN:
|
||||
// since this is a singleton so far we simply ignore the actual object
|
||||
right = ParticipantAdmin.INSTANCE;
|
||||
break;
|
||||
case IDENTITY_PROVIDER_ADMIN:
|
||||
// since this is a singleton so far we simply ignore the actual object
|
||||
right = IdentityProviderAdmin.INSTANCE;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized user right case: " + kindCase.name());
|
||||
}
|
||||
return right;
|
||||
}
|
||||
|
||||
public static final class IdentityProviderAdmin extends Right {
|
||||
// empty private constructor, singleton object
|
||||
private IdentityProviderAdmin() {}
|
||||
// not built lazily on purpose, close to no overhead here
|
||||
public static final IdentityProviderAdmin INSTANCE = new IdentityProviderAdmin();
|
||||
|
||||
@Override
|
||||
UserManagementServiceOuterClass.Right toProto() {
|
||||
return UserManagementServiceOuterClass.Right.newBuilder()
|
||||
.setIdentityProviderAdmin(
|
||||
UserManagementServiceOuterClass.Right.IdentityProviderAdmin.getDefaultInstance())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParticipantAdmin extends Right {
|
||||
// empty private constructor, singleton object
|
||||
private ParticipantAdmin() {}
|
||||
// not built lazily on purpose, close to no overhead here
|
||||
public static final ParticipantAdmin INSTANCE = new ParticipantAdmin();
|
||||
|
||||
@Override
|
||||
UserManagementServiceOuterClass.Right toProto() {
|
||||
return UserManagementServiceOuterClass.Right.newBuilder()
|
||||
.setParticipantAdmin(
|
||||
UserManagementServiceOuterClass.Right.ParticipantAdmin.getDefaultInstance())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CanActAs extends Right {
|
||||
public final String party;
|
||||
|
||||
public CanActAs(String party) {
|
||||
this.party = party;
|
||||
}
|
||||
|
||||
@Override
|
||||
UserManagementServiceOuterClass.Right toProto() {
|
||||
return UserManagementServiceOuterClass.Right.newBuilder()
|
||||
.setCanActAs(
|
||||
UserManagementServiceOuterClass.Right.CanActAs.newBuilder().setParty(this.party))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CanReadAs extends Right {
|
||||
public final String party;
|
||||
|
||||
public CanReadAs(String party) {
|
||||
this.party = party;
|
||||
}
|
||||
|
||||
@Override
|
||||
UserManagementServiceOuterClass.Right toProto() {
|
||||
return UserManagementServiceOuterClass.Right.newBuilder()
|
||||
.setCanReadAs(
|
||||
UserManagementServiceOuterClass.Right.CanReadAs.newBuilder().setParty(this.party))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class Value {
|
||||
|
||||
public static Value fromProto(ValueOuterClass.Value value) {
|
||||
switch (value.getSumCase()) {
|
||||
case RECORD:
|
||||
return DamlRecord.fromProto(value.getRecord());
|
||||
case VARIANT:
|
||||
return Variant.fromProto(value.getVariant());
|
||||
case ENUM:
|
||||
return DamlEnum.fromProto(value.getEnum());
|
||||
case CONTRACT_ID:
|
||||
return new ContractId(value.getContractId());
|
||||
case LIST:
|
||||
return DamlList.fromProto(value.getList());
|
||||
case INT64:
|
||||
return new Int64(value.getInt64());
|
||||
case NUMERIC:
|
||||
return Numeric.fromProto(value.getNumeric());
|
||||
case TEXT:
|
||||
return new Text(value.getText());
|
||||
case TIMESTAMP:
|
||||
return new Timestamp(value.getTimestamp());
|
||||
case PARTY:
|
||||
return new Party(value.getParty());
|
||||
case BOOL:
|
||||
return Bool.of(value.getBool());
|
||||
case UNIT:
|
||||
return Unit.getInstance();
|
||||
case DATE:
|
||||
return new Date(value.getDate());
|
||||
case OPTIONAL:
|
||||
return DamlOptional.fromProto(value.getOptional());
|
||||
case MAP:
|
||||
return DamlTextMap.fromProto(value.getMap());
|
||||
case GEN_MAP:
|
||||
return DamlGenMap.fromProto(value.getGenMap());
|
||||
case SUM_NOT_SET:
|
||||
throw new SumNotSetException(value);
|
||||
default:
|
||||
throw new UnknownValueException(value);
|
||||
}
|
||||
}
|
||||
|
||||
public final Optional<Bool> asBool() {
|
||||
return (this instanceof Bool) ? Optional.of((Bool) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<DamlRecord> asRecord() {
|
||||
return (this instanceof DamlRecord) ? Optional.of((DamlRecord) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Variant> asVariant() {
|
||||
return (this instanceof Variant) ? Optional.of((Variant) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<DamlEnum> asEnum() {
|
||||
return (this instanceof DamlEnum) ? Optional.of((DamlEnum) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<ContractId> asContractId() {
|
||||
return (this instanceof ContractId) ? Optional.of((ContractId) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<DamlList> asList() {
|
||||
return (this instanceof DamlList) ? Optional.of((DamlList) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Int64> asInt64() {
|
||||
return (this instanceof Int64) ? Optional.of((Int64) this) : Optional.empty();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public final Optional<Decimal> asDecimal() {
|
||||
return (this instanceof Decimal) ? Optional.of((Decimal) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Numeric> asNumeric() {
|
||||
return (this instanceof Numeric) ? Optional.of((Numeric) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Text> asText() {
|
||||
return (this instanceof Text) ? Optional.of((Text) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Timestamp> asTimestamp() {
|
||||
return (this instanceof Timestamp) ? Optional.of((Timestamp) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Party> asParty() {
|
||||
return (this instanceof Party) ? Optional.of((Party) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Unit> asUnit() {
|
||||
return (this instanceof Unit) ? Optional.of((Unit) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<Date> asDate() {
|
||||
return (this instanceof Date) ? Optional.of((Date) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<DamlOptional> asOptional() {
|
||||
return (this instanceof DamlOptional) ? Optional.of((DamlOptional) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public final Optional<DamlTextMap> asTextMap() {
|
||||
return (this instanceof DamlTextMap) ? Optional.of((DamlTextMap) this) : Optional.empty();
|
||||
}
|
||||
|
||||
/** Use {@link Value#asTextMap()} */
|
||||
@Deprecated
|
||||
public final Optional<DamlTextMap> asMap() {
|
||||
return asTextMap();
|
||||
}
|
||||
|
||||
public final Optional<DamlGenMap> asGenMap() {
|
||||
return (this instanceof DamlGenMap) ? Optional.of((DamlGenMap) this) : Optional.empty();
|
||||
}
|
||||
|
||||
public abstract ValueOuterClass.Value toProto();
|
||||
}
|
||||
|
||||
class SumNotSetException extends RuntimeException {
|
||||
public SumNotSetException(ValueOuterClass.Value value) {
|
||||
super("Sum not set for value " + value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class UnknownValueException extends RuntimeException {
|
||||
public UnknownValueException(ValueOuterClass.Value value) {
|
||||
super("value unknown " + value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidKeyValue extends RuntimeException {
|
||||
public InvalidKeyValue(ValueOuterClass.Value value) {
|
||||
super("invalid key value, expected TEXT, found " + value.getSumCase().name());
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
import com.daml.ledger.api.v1.ValueOuterClass;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class Variant extends Value {
|
||||
|
||||
private final Optional<Identifier> variantId;
|
||||
|
||||
private final String constructor;
|
||||
|
||||
private final Value value;
|
||||
|
||||
public Variant(@NonNull Identifier variantId, @NonNull String constructor, @NonNull Value value) {
|
||||
this.variantId = Optional.of(variantId);
|
||||
this.constructor = constructor;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Variant(@NonNull String constructor, @NonNull Value value) {
|
||||
this.variantId = Optional.empty();
|
||||
this.constructor = constructor;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Variant fromProto(ValueOuterClass.Variant variant) {
|
||||
String constructor = variant.getConstructor();
|
||||
Value value = Value.fromProto(variant.getValue());
|
||||
if (variant.hasVariantId()) {
|
||||
Identifier variantId = Identifier.fromProto(variant.getVariantId());
|
||||
return new Variant(variantId, constructor, value);
|
||||
} else {
|
||||
return new Variant(constructor, value);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Identifier> getVariantId() {
|
||||
return variantId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getConstructor() {
|
||||
return constructor;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Value getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOuterClass.Value toProto() {
|
||||
return ValueOuterClass.Value.newBuilder().setVariant(this.toProtoVariant()).build();
|
||||
}
|
||||
|
||||
public ValueOuterClass.Variant toProtoVariant() {
|
||||
ValueOuterClass.Variant.Builder builder = ValueOuterClass.Variant.newBuilder();
|
||||
builder.setConstructor(this.getConstructor());
|
||||
this.getVariantId().ifPresent(identifier -> builder.setVariantId(identifier.toProto()));
|
||||
builder.setValue(this.value.toProto());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Variant variant = (Variant) o;
|
||||
return Objects.equals(variantId, variant.variantId)
|
||||
&& Objects.equals(constructor, variant.constructor)
|
||||
&& Objects.equals(value, variant.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(variantId, constructor, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Variant{"
|
||||
+ "variantId="
|
||||
+ variantId
|
||||
+ ", constructor='"
|
||||
+ constructor
|
||||
+ '\''
|
||||
+ ", value="
|
||||
+ value
|
||||
+ '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data;
|
||||
|
||||
/** A Ledger event regarding a workflow identified by the {@link WorkflowEvent#getWorkflowId()}. */
|
||||
public interface WorkflowEvent {
|
||||
|
||||
String getWorkflowId();
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.ExerciseByKeyCommand;
|
||||
import com.daml.ledger.javaapi.data.Value;
|
||||
|
||||
/** Parent of all generated {@code ByKey} classes within templates and interfaces. */
|
||||
public abstract class ByKey implements Exercises<ExerciseByKeyCommand> {
|
||||
protected final Value contractKey;
|
||||
|
||||
protected ByKey(Value contractKey) {
|
||||
this.contractKey = contractKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, R> Update<Exercised<R>> makeExerciseCmd(
|
||||
Choice<?, ? super A, R> choice, A choiceArgument) {
|
||||
var command =
|
||||
new ExerciseByKeyCommand(
|
||||
getCompanion().TEMPLATE_ID,
|
||||
contractKey,
|
||||
choice.name,
|
||||
choice.encodeArg.apply(choiceArgument));
|
||||
return new Update.ExerciseUpdate<>(command, x -> x, choice.returnTypeDecoder);
|
||||
}
|
||||
|
||||
/** The origin of the choice, not the template relevant to contractKey. */
|
||||
protected abstract ContractTypeCompanion<?, ?, ?, ?> getCompanion();
|
||||
|
||||
/**
|
||||
* Parent of all generated {@code ByKey} classes within interfaces. These need to pass both the
|
||||
* template and interface ID.
|
||||
*/
|
||||
public abstract static class ToInterface extends ByKey {
|
||||
private final ContractCompanion<?, ?, ?> keySource;
|
||||
|
||||
protected ToInterface(ContractCompanion<?, ?, ?> keySource, Value contractKey) {
|
||||
super(contractKey);
|
||||
this.keySource = keySource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, R> Update<Exercised<R>> makeExerciseCmd(
|
||||
Choice<?, ? super A, R> choice, A choiceArgument) {
|
||||
// TODO i15638 use getCompanion().TEMPLATE_ID as the interface ID
|
||||
var command =
|
||||
new ExerciseByKeyCommand(
|
||||
keySource.TEMPLATE_ID,
|
||||
contractKey,
|
||||
choice.name,
|
||||
choice.encodeArg.apply(choiceArgument));
|
||||
return new Update.ExerciseUpdate<>(command, x -> x, choice.returnTypeDecoder);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.Value;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* This represents a Daml choice that can be exercised on {@link ContractId}s of type {@code
|
||||
* ContractId<Tpl>}.
|
||||
*
|
||||
* @param <Tpl> The generated template class or marker interface for a Daml interface
|
||||
* @param <ArgType> The choice's argument type
|
||||
* @param <ResType> The result from exercising the choice
|
||||
*/
|
||||
public final class Choice<Tpl, ArgType, ResType> {
|
||||
|
||||
/** The choice name * */
|
||||
public final String name;
|
||||
|
||||
final Function<ArgType, Value> encodeArg;
|
||||
|
||||
final ValueDecoder<ArgType> argTypeDecoder;
|
||||
final ValueDecoder<ResType> returnTypeDecoder;
|
||||
|
||||
private Choice(
|
||||
final String name,
|
||||
final Function<ArgType, Value> encodeArg,
|
||||
ValueDecoder<ArgType> argTypeDecoder,
|
||||
ValueDecoder<ResType> returnTypeDecoder) {
|
||||
this.name = name;
|
||||
this.encodeArg = encodeArg;
|
||||
this.argTypeDecoder = argTypeDecoder;
|
||||
this.returnTypeDecoder = returnTypeDecoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by <a
|
||||
* href="https://docs.daml.com/app-dev/bindings-java/codegen.html">the Java code generator</a>,
|
||||
* and <em>should not be referenced directly</em>. Applications should refer to the generated
|
||||
* {@code CHOICE_*} fields on templates or interfaces.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
public static <Tpl, ArgType, ResType> Choice<Tpl, ArgType, ResType> create(
|
||||
final String name,
|
||||
final Function<ArgType, Value> encodeArg,
|
||||
ValueDecoder<ArgType> argTypeDecoder,
|
||||
ValueDecoder<ResType> returnTypeDecoder) {
|
||||
return new Choice<>(name, encodeArg, argTypeDecoder, returnTypeDecoder);
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.Identifier;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A superclass for all codegen-generated Contracts.
|
||||
*
|
||||
* @param <Id> The generated contract ID class alongside the generated Contract class.
|
||||
* @param <Data> The containing template's associated record type.
|
||||
*/
|
||||
public abstract class Contract<Id, Data> implements com.daml.ledger.javaapi.data.Contract {
|
||||
/** The contract ID retrieved from the event. */
|
||||
public final Id id;
|
||||
|
||||
/** The contract payload, as declared after {@code template X with}. */
|
||||
public final Data data;
|
||||
|
||||
/** If defined, the contract's agreement text. */
|
||||
public final Optional<String> agreementText;
|
||||
|
||||
/** The party IDs of this contract's signatories. */
|
||||
public final Set<String> signatories;
|
||||
|
||||
/** The party IDs of this contract's observers. */
|
||||
public final Set<String> observers;
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by <a
|
||||
* href="https://docs.daml.com/app-dev/bindings-java/codegen.html">the Java code generator</a>,
|
||||
* and <em>should not be referenced directly</em>. Applications should refer to the constructors
|
||||
* of code-generated subclasses, or {@link ContractCompanion#fromCreatedEvent}, instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected Contract(
|
||||
Id id,
|
||||
Data data,
|
||||
Optional<String> agreementText,
|
||||
Set<String> signatories,
|
||||
Set<String> observers) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
this.agreementText = agreementText;
|
||||
this.signatories = signatories;
|
||||
this.observers = observers;
|
||||
}
|
||||
|
||||
/** The template or interface ID for this contract or interface view. */
|
||||
public final Identifier getContractTypeId() {
|
||||
return getCompanion().TEMPLATE_ID;
|
||||
}
|
||||
|
||||
// concrete 3rd type param would need a self-reference type param in Contract
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by {@link Contract}, and <em>should not be
|
||||
* referenced directly</em>. Applications should refer to other methods like {@link
|
||||
* #getContractTypeId} instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected abstract ContractTypeCompanion<? extends Contract<?, Data>, Id, ?, Data> getCompanion();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(object instanceof Contract)) {
|
||||
return false;
|
||||
}
|
||||
Contract<?, ?> other = (Contract<?, ?>) object;
|
||||
// a bespoke Contract-specific equals is unneeded, as 'data' here
|
||||
// already compares the associated record types' classes
|
||||
return this.id.equals(other.id)
|
||||
&& this.data.equals(other.data)
|
||||
&& this.agreementText.equals(other.agreementText)
|
||||
&& this.signatories.equals(other.signatories)
|
||||
&& this.observers.equals(other.observers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.id, this.data, this.agreementText, this.signatories, this.observers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"%s.Contract(%s, %s, %s, %s, %s)",
|
||||
getCompanion().TEMPLATE_CLASS_NAME,
|
||||
this.id,
|
||||
this.data,
|
||||
this.agreementText,
|
||||
this.signatories,
|
||||
this.observers);
|
||||
}
|
||||
}
|
@ -0,0 +1,214 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
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 com.daml.ledger.javaapi.data.codegen.json.JsonLfDecoder;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Metadata and utilities associated with a template as a whole, rather than one single contract
|
||||
* made from that template.
|
||||
*
|
||||
* <p>Application code <em>should not</em> instantiate or subclass; instead, refer to the {@code
|
||||
* COMPANION} field on generated {@link com.daml.ledger.javaapi.data.Template} subclasses. All
|
||||
* {@code protected} members herein are considered part of the <strong>INTERNAL API</strong>.
|
||||
*
|
||||
* <p>Every instance is either a {@link WithKey} or {@link WithoutKey}, depending on whether the
|
||||
* template defined a {@code key} type. {@link WithKey} defines extra utilities for working with
|
||||
* contract keys.
|
||||
*
|
||||
* @param <Ct> The {@link Contract} subclass generated within the template class.
|
||||
* @param <Id> The {@link ContractId} subclass generated within the template class.
|
||||
* @param <Data> The generated {@link com.daml.ledger.javaapi.data.Template} subclass named after
|
||||
* the template, whose instances contain only the payload.
|
||||
*/
|
||||
public abstract class ContractCompanion<Ct, Id, Data>
|
||||
extends ContractTypeCompanion<Ct, Id, Data, Data> {
|
||||
/** @hidden */
|
||||
protected final Function<DamlRecord, Data> fromValue;
|
||||
|
||||
@FunctionalInterface // Defines the function type which throws.
|
||||
public static interface FromJson<T> {
|
||||
T decode(String s) throws JsonLfDecoder.Error;
|
||||
}
|
||||
|
||||
protected final FromJson<Data> fromJson;
|
||||
|
||||
/**
|
||||
* Static method to generate an implementation of {@code ValueDecoder} of type {@code Data} with
|
||||
* metadata from the provided {@code ContractCompanion}.
|
||||
*
|
||||
* @param companion an instance of {@code ContractCompanion}.
|
||||
* @return The {@code ValueDecoder} for parsing {@code Value} to get an instance of {@code Data}.
|
||||
*/
|
||||
public static <Data> ValueDecoder<Data> valueDecoder(
|
||||
ContractCompanion<?, ? extends ContractId<Data>, Data> companion) {
|
||||
return new ValueDecoder<>() {
|
||||
@Override
|
||||
public Data decode(Value value) {
|
||||
DamlRecord record =
|
||||
value
|
||||
.asRecord()
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new IllegalArgumentException("Contracts must be constructed from Records"));
|
||||
return companion.fromValue.apply(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractId<Data> fromContractId(String contractId) {
|
||||
return companion.newContractId.apply(contractId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by {@link WithoutKey} and {@link WithKey},
|
||||
* and <em>should not be referenced directly</em>. Applications should refer to the {@code
|
||||
* COMPANION} field on generated {@link com.daml.ledger.javaapi.data.Template} subclasses instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected ContractCompanion(
|
||||
String templateClassName,
|
||||
Identifier templateId,
|
||||
Function<String, Id> newContractId,
|
||||
Function<DamlRecord, Data> fromValue,
|
||||
FromJson<Data> fromJson,
|
||||
List<Choice<Data, ?, ?>> choices) {
|
||||
super(templateId, templateClassName, newContractId, choices);
|
||||
this.fromValue = fromValue;
|
||||
this.fromJson = fromJson;
|
||||
}
|
||||
|
||||
public Data fromJson(String json) throws JsonLfDecoder.Error {
|
||||
return this.fromJson.decode(json);
|
||||
}
|
||||
|
||||
public static final class WithoutKey<Ct, Id, Data> extends ContractCompanion<Ct, Id, Data> {
|
||||
private final NewContract<Ct, Id, Data> newContract;
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by <a
|
||||
* href="https://docs.daml.com/app-dev/bindings-java/codegen.html">the Java code generator</a>,
|
||||
* and <em>should not be referenced directly</em>. Applications should refer to the {@code
|
||||
* COMPANION} field on generated {@link com.daml.ledger.javaapi.data.Template} subclasses
|
||||
* instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
public WithoutKey(
|
||||
String templateClassName,
|
||||
Identifier templateId,
|
||||
Function<String, Id> newContractId,
|
||||
Function<DamlRecord, Data> fromValue,
|
||||
FromJson<Data> fromJson,
|
||||
NewContract<Ct, Id, Data> newContract,
|
||||
List<Choice<Data, ?, ?>> choices) {
|
||||
super(templateClassName, templateId, newContractId, fromValue, fromJson, choices);
|
||||
this.newContract = newContract;
|
||||
}
|
||||
|
||||
public Ct fromIdAndRecord(
|
||||
String contractId,
|
||||
DamlRecord record$,
|
||||
Optional<String> agreementText,
|
||||
Set<String> signatories,
|
||||
Set<String> observers) {
|
||||
Id id = newContractId.apply(contractId);
|
||||
Data data = fromValue.apply(record$);
|
||||
return newContract.newContract(id, data, agreementText, signatories, observers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ct fromCreatedEvent(CreatedEvent event) {
|
||||
return fromIdAndRecord(
|
||||
event.getContractId(),
|
||||
event.getArguments(),
|
||||
event.getAgreementText(),
|
||||
event.getSignatories(),
|
||||
event.getObservers());
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NewContract<Ct, Id, Data> {
|
||||
Ct newContract(
|
||||
Id id,
|
||||
Data data,
|
||||
Optional<String> agreementText,
|
||||
Set<String> signatories,
|
||||
Set<String> observers);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param <Key> {@code Data}'s key type as represented in Java codegen. */
|
||||
public static final class WithKey<Ct, Id, Data, Key> extends ContractCompanion<Ct, Id, Data> {
|
||||
private final NewContract<Ct, Id, Data, Key> newContract;
|
||||
private final Function<Value, Key> keyFromValue;
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by <a
|
||||
* href="https://docs.daml.com/app-dev/bindings-java/codegen.html">the Java code generator</a>,
|
||||
* and <em>should not be referenced directly</em>. Applications should refer to the {@code
|
||||
* COMPANION} field on generated {@link com.daml.ledger.javaapi.data.Template} subclasses
|
||||
* instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
public WithKey(
|
||||
String templateClassName,
|
||||
Identifier templateId,
|
||||
Function<String, Id> newContractId,
|
||||
Function<DamlRecord, Data> fromValue,
|
||||
FromJson<Data> fromJson,
|
||||
NewContract<Ct, Id, Data, Key> newContract,
|
||||
List<Choice<Data, ?, ?>> choices,
|
||||
Function<Value, Key> keyFromValue) {
|
||||
super(templateClassName, templateId, newContractId, fromValue, fromJson, choices);
|
||||
this.newContract = newContract;
|
||||
this.keyFromValue = keyFromValue;
|
||||
}
|
||||
|
||||
public Ct fromIdAndRecord(
|
||||
String contractId,
|
||||
DamlRecord record$,
|
||||
Optional<String> agreementText,
|
||||
Optional<Key> key,
|
||||
Set<String> signatories,
|
||||
Set<String> observers) {
|
||||
Id id = newContractId.apply(contractId);
|
||||
Data data = fromValue.apply(record$);
|
||||
return newContract.newContract(id, data, agreementText, key, signatories, observers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ct fromCreatedEvent(CreatedEvent event) {
|
||||
return fromIdAndRecord(
|
||||
event.getContractId(),
|
||||
event.getArguments(),
|
||||
event.getAgreementText(),
|
||||
event.getContractKey().map(keyFromValue),
|
||||
event.getSignatories(),
|
||||
event.getObservers());
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NewContract<Ct, Id, Data, Key> {
|
||||
Ct newContract(
|
||||
Id id,
|
||||
Data data,
|
||||
Optional<String> agreementText,
|
||||
Optional<Key> key,
|
||||
Set<String> signatories,
|
||||
Set<String> observers);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.CreatedEvent;
|
||||
import com.daml.ledger.javaapi.data.Identifier;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class ContractDecoder {
|
||||
private final Map<
|
||||
Identifier,
|
||||
? extends ContractCompanion<? extends Contract<?, ?>, ?, ? extends DamlRecord<?>>>
|
||||
companions;
|
||||
|
||||
public ContractDecoder(
|
||||
Iterable<? extends ContractCompanion<? extends Contract<?, ?>, ?, ? extends DamlRecord<?>>>
|
||||
companions) {
|
||||
this.companions =
|
||||
StreamSupport.stream(companions.spliterator(), false)
|
||||
.collect(Collectors.toMap(c -> c.TEMPLATE_ID, Function.identity()));
|
||||
}
|
||||
|
||||
public Contract<?, ?> fromCreatedEvent(CreatedEvent event) throws IllegalArgumentException {
|
||||
Identifier templateId = event.getTemplateId();
|
||||
ContractCompanion<? extends Contract<?, ?>, ?, ?> companion =
|
||||
getContractCompanion(templateId)
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new IllegalArgumentException("No template found for identifier " + templateId));
|
||||
return companion.fromCreatedEvent(event);
|
||||
}
|
||||
|
||||
public Optional<? extends ContractCompanion<? extends Contract<?, ?>, ?, ? extends DamlRecord<?>>>
|
||||
getContractCompanion(Identifier templateId) {
|
||||
return Optional.ofNullable(companions.get(templateId));
|
||||
}
|
||||
|
||||
public Optional<Function<CreatedEvent, com.daml.ledger.javaapi.data.Contract>> getDecoder(
|
||||
Identifier templateId) {
|
||||
return getContractCompanion(templateId).map(companion -> companion::fromCreatedEvent);
|
||||
}
|
||||
|
||||
public Optional<ContractCompanion.FromJson<? extends DamlRecord<?>>> getJsonDecoder(
|
||||
Identifier templateId) {
|
||||
return getContractCompanion(templateId).map(companion -> companion::fromJson);
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.ExerciseCommand;
|
||||
import com.daml.ledger.javaapi.data.Value;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This class is used as a super class for all concrete ContractIds generated by the java codegen
|
||||
* with the following properties:
|
||||
*
|
||||
* <pre>
|
||||
* Foo.ContractId fooCid = new Foo.ContractId("test");
|
||||
* Bar.ContractId barCid = new Bar.ContractId("test");
|
||||
* ContractId<Foo> genericFooCid = new ContractId<>("test");
|
||||
* ContractId<Foo> genericBarCid = new ContractId<>("test");
|
||||
*
|
||||
* fooCid.equals(genericFooCid) == true;
|
||||
* genericFooCid.equals(fooCid) == true;
|
||||
*
|
||||
* fooCid.equals(barCid) == false;
|
||||
* barCid.equals(fooCid) == false;
|
||||
* </pre>
|
||||
*
|
||||
* Due to erase, we cannot distinguish ContractId<Foo> from ContractId<Bar>, thus:
|
||||
*
|
||||
* <pre>
|
||||
* fooCid.equals(genericBarCid) == true
|
||||
* genericBarCid.equals(fooCid) == true
|
||||
*
|
||||
* genericFooCid.equals(genericBarCid) == true
|
||||
* genericBarCid.equals(genericFooCid) == true
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> A template type
|
||||
*/
|
||||
public class ContractId<T> implements Exercises<ExerciseCommand> {
|
||||
public final String contractId;
|
||||
|
||||
public ContractId(String contractId) {
|
||||
this.contractId = contractId;
|
||||
}
|
||||
|
||||
public final Value toValue() {
|
||||
return new com.daml.ledger.javaapi.data.ContractId(contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, R> Update<Exercised<R>> makeExerciseCmd(
|
||||
Choice<?, ? super A, R> choice, A choiceArgument) {
|
||||
var command =
|
||||
new ExerciseCommand(
|
||||
getCompanion().TEMPLATE_ID,
|
||||
contractId,
|
||||
choice.name,
|
||||
choice.encodeArg.apply(choiceArgument));
|
||||
return new Update.ExerciseUpdate<>(command, x -> x, choice.returnTypeDecoder);
|
||||
}
|
||||
|
||||
// overridden by every code generator, but decoding abstractly can e.g.
|
||||
// produce a ContractId<Foo> that is not a Foo.ContractId
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by {@link ContractId} and <em>should not
|
||||
* be referenced directly</em>. Applications should refer to generated {@code exercise} methods
|
||||
* instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected ContractTypeCompanion<
|
||||
? extends Contract<? extends ContractId<T>, ?>, ? extends ContractId<T>, T, ?>
|
||||
getCompanion() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Cannot exercise on a contract ID type without code-generated exercise methods");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null
|
||||
|| !(getClass().isAssignableFrom(o.getClass())
|
||||
|| o.getClass().isAssignableFrom(getClass()))) return false;
|
||||
ContractId<?> that = (ContractId<?>) o;
|
||||
return contractId.equals(that.contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContractId(" + contractId + ')';
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.CreatedEvent;
|
||||
import com.daml.ledger.javaapi.data.Identifier;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The commonality between {@link ContractCompanion} and {@link InterfaceCompanion}.
|
||||
*
|
||||
* @param <Ct> The specific type of {@link Contract} representing contracts from the ledger. Always
|
||||
* a subtype of {@code Contract<Id, Data>}.
|
||||
* @param <Id> The code-generated class of {@link ContractId}s specific to this template or
|
||||
* interface. Always a subtype of {@code ContractId<ContractType>}.
|
||||
* @param <ContractType> The type argument to {@link ContractId}s of this contract type. This is the
|
||||
* same as {@code Data} for templates, but is a pure marker type for interfaces.
|
||||
* @param <Data> The "payload" data model for a contract. This is the template payload for
|
||||
* templates, and the view type for interfaces.
|
||||
*/
|
||||
public abstract class ContractTypeCompanion<Ct, Id, ContractType, Data> {
|
||||
/** The full template ID of the template or interface that defined this companion. */
|
||||
public final Identifier TEMPLATE_ID;
|
||||
|
||||
final String TEMPLATE_CLASS_NAME;
|
||||
|
||||
final Function<String, Id> newContractId;
|
||||
|
||||
/**
|
||||
* The provides a mapping of choice name to Choice.
|
||||
*
|
||||
* <pre>
|
||||
* // if you statically know the name of a choice
|
||||
* var c1 = Bar.COMPANION.choices.get("Transfer");
|
||||
* // it is better to retrieve it directly from the generated field
|
||||
* var c2 = Bar.CHOICE_Transfer;
|
||||
* </pre>
|
||||
*/
|
||||
public final Map<String, Choice<ContractType, ?, ?>> choices;
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by {@link ContractCompanion} and {@link
|
||||
* InterfaceCompanion}, and <em>should not be referenced directly</em>. Applications should refer
|
||||
* to code-generated {@code COMPANION} and {@code INTERFACE} fields specific to the template or
|
||||
* interface in question instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected ContractTypeCompanion(
|
||||
Identifier templateId,
|
||||
String templateClassName,
|
||||
Function<String, Id> newContractId,
|
||||
List<Choice<ContractType, ?, ?>> choices) {
|
||||
TEMPLATE_ID = templateId;
|
||||
TEMPLATE_CLASS_NAME = templateClassName;
|
||||
this.newContractId = newContractId;
|
||||
this.choices =
|
||||
choices.stream().collect(Collectors.toMap(choice -> choice.name, Function.identity()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to parse a contract from an event expected to create a {@code Ct} contract. This is
|
||||
* either the {@link CreatedEvent#getArguments} for {@link ContractCompanion}, or one of {@link
|
||||
* CreatedEvent#getInterfaceViews} for an {@link InterfaceCompanion}.
|
||||
*
|
||||
* @param event the event to try to parse a contract from
|
||||
* @throws IllegalArgumentException when the {@link CreatedEvent} payload cannot be parsed as
|
||||
* {@code Data}, or the {@link CreatedEvent#getContractKey} cannot be parsed as a contract
|
||||
* key.
|
||||
* @return The parsed contract, with payload and metadata, if present.
|
||||
*/
|
||||
public abstract Ct fromCreatedEvent(CreatedEvent event) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Convert from a generic {@link ContractId} to the specific contract ID subclass generated as
|
||||
* part of this companion's template or interface. Most applications should not need this
|
||||
* function, but if your Daml data types include types like {@code ContractId t} where {@code t}
|
||||
* is any type parameter, that is likely to result in code-generated types like {@code
|
||||
* ContractId<t>} that need to be passed to this function before e.g. {@code exercise*} methods
|
||||
* can be used.
|
||||
*/
|
||||
public final Id toContractId(ContractId<ContractType> parameterizedContractId) {
|
||||
return newContractId.apply(parameterizedContractId.contractId);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
final class ContractWithInterfaceView<Id, View> extends Contract<Id, View> {
|
||||
|
||||
private final InterfaceCompanion<?, Id, View> contractTypeCompanion;
|
||||
|
||||
ContractWithInterfaceView(
|
||||
InterfaceCompanion<?, Id, View> contractTypeCompanion,
|
||||
Id id,
|
||||
View interfaceView,
|
||||
Optional<String> agreementText,
|
||||
Set<String> signatories,
|
||||
Set<String> observers) {
|
||||
super(id, interfaceView, agreementText, signatories, observers);
|
||||
this.contractTypeCompanion = contractTypeCompanion;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InterfaceCompanion<?, Id, View> getCompanion() {
|
||||
return contractTypeCompanion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
return object instanceof ContractWithInterfaceView && super.equals(object);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A superclass for all codegen-generated Contracts whose templates have a {@code key} defined.
|
||||
*
|
||||
* @param <Id> The generated contract ID class alongside the generated Contract class.
|
||||
* @param <Data> The containing template's associated record type.
|
||||
* @param <Key> The template's key type.
|
||||
*/
|
||||
public abstract class ContractWithKey<Id, Data, Key> extends Contract<Id, Data> {
|
||||
/** The contract's key, if it was present in the event. */
|
||||
public final Optional<Key> key;
|
||||
|
||||
/**
|
||||
* <strong>INTERNAL API</strong>: this is meant for use by <a
|
||||
* href="https://docs.daml.com/app-dev/bindings-java/codegen.html">the Java code generator</a>,
|
||||
* and <em>should not be referenced directly</em>. Applications should refer to the constructors
|
||||
* of code-generated subclasses, or {@link ContractCompanion#fromCreatedEvent}, instead.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
protected ContractWithKey(
|
||||
Id id,
|
||||
Data data,
|
||||
Optional<String> agreementText,
|
||||
Optional<Key> key,
|
||||
Set<String> signatories,
|
||||
Set<String> observers) {
|
||||
super(id, data, agreementText, signatories, observers);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object object) {
|
||||
return object instanceof ContractWithKey
|
||||
&& super.equals(object)
|
||||
&& this.key.equals(((ContractWithKey<?, ?, ?>) object).key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return Objects.hash(
|
||||
this.id, this.data, this.agreementText, this.key, this.signatories, this.observers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return String.format(
|
||||
"%s.Contract(%s, %s, %s, %s, %s, %s)",
|
||||
getCompanion().TEMPLATE_CLASS_NAME,
|
||||
this.id,
|
||||
this.data,
|
||||
this.agreementText,
|
||||
this.key,
|
||||
this.signatories,
|
||||
this.observers);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.CreateAndExerciseCommand;
|
||||
import com.daml.ledger.javaapi.data.Template;
|
||||
|
||||
/** Parent of all generated {@code CreateAnd} classes within templates and interfaces. */
|
||||
public abstract class CreateAnd implements Exercises<CreateAndExerciseCommand> {
|
||||
protected final Template createArguments;
|
||||
|
||||
protected CreateAnd(Template createArguments) {
|
||||
this.createArguments = createArguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, R> Update<Exercised<R>> makeExerciseCmd(
|
||||
Choice<?, ? super A, R> choice, A choiceArgument) {
|
||||
var command =
|
||||
new CreateAndExerciseCommand(
|
||||
getCompanion().TEMPLATE_ID,
|
||||
createArguments.toValue(),
|
||||
choice.name,
|
||||
choice.encodeArg.apply(choiceArgument));
|
||||
return new Update.ExerciseUpdate<>(command, x -> x, choice.returnTypeDecoder);
|
||||
}
|
||||
|
||||
/** The origin of the choice, not the createArguments. */
|
||||
protected abstract ContractTypeCompanion<?, ?, ?, ?> getCompanion();
|
||||
|
||||
/**
|
||||
* Parent of all generated {@code CreateAnd} classes within interfaces. These need to pass both
|
||||
* the template and interface ID.
|
||||
*/
|
||||
public abstract static class ToInterface extends CreateAnd {
|
||||
private final ContractCompanion<?, ?, ?> createSource;
|
||||
|
||||
protected ToInterface(ContractCompanion<?, ?, ?> createSource, Template createArguments) {
|
||||
super(createArguments);
|
||||
this.createSource = createSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <A, R> Update<Exercised<R>> makeExerciseCmd(
|
||||
Choice<?, ? super A, R> choice, A choiceArgument) {
|
||||
// TODO i15638 use getCompanion().TEMPLATE_ID as the interface ID
|
||||
var command =
|
||||
new CreateAndExerciseCommand(
|
||||
createSource.TEMPLATE_ID,
|
||||
createArguments.toValue(),
|
||||
choice.name,
|
||||
choice.encodeArg.apply(choiceArgument));
|
||||
return new Update.ExerciseUpdate<>(command, x -> x, choice.returnTypeDecoder);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
// Proprietary code. All rights reserved.
|
||||
|
||||
package com.daml.ledger.javaapi.data.codegen;
|
||||
|
||||
import com.daml.ledger.javaapi.data.CreatedEvent;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* This class contains information related to a result after a contract is created.
|
||||
*
|
||||
* <p>Application code <em>should not</em> instantiate or subclass;
|
||||
*
|
||||
* @param <CtId> The type of the template {@code ContractId}.
|
||||
*/
|
||||
public final class Created<CtId> {
|
||||
public final CtId contractId;
|
||||
|
||||
private Created(CtId contractId) {
|
||||
this.contractId = contractId;
|
||||
}
|
||||
|
||||
/** @hidden */
|
||||
public static <CtId> Created<CtId> fromEvent(
|
||||
Function<String, CtId> createdContractId, CreatedEvent createdEvent) {
|
||||
return new Created<>(createdContractId.apply(createdEvent.getContractId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Created{" + "contractId=" + contractId + '}';
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user