Пример #1
0
        private void ConvertThroughProto(Commands source)
        {
            Com.Daml.Ledger.Api.V1.Commands protoValue = source.ToProto("ledgerId");
            Commands target = Commands.FromProto(protoValue);

            Assert.True(source == target);
        }
Пример #2
0
        public static Commands FromProto(Com.Daml.Ledger.Api.V1.Commands commands)
        {
            string commandId = commands.CommandId;
            string party     = commands.Party;

            var actAs = new List <string>();

            if (commands.ActAs != null)
            {
                actAs.AddRange(commands.ActAs);
            }

            if (!actAs.Contains(party))
            {
                actAs.Insert(0, party);
            }

            var readAs = new List <string>();

            if (commands.ReadAs != null)
            {
                readAs.AddRange(commands.ReadAs);
            }

            return(new Commands(commands.WorkflowId, commands.ApplicationId, commandId, actAs, readAs,
                                commands.MinLedgerTimeAbs != null ? Optional.Of(commands.MinLedgerTimeAbs.ToDateTimeOffset()) : None.Value,
                                commands.MinLedgerTimeRel != null ? Optional.Of(commands.MinLedgerTimeRel.ToTimeSpan()) : None.Value,
                                commands.DeduplicationTime != null ? Optional.Of(commands.DeduplicationTime.ToTimeSpan()) : None.Value,
                                from c in commands.Commands_ select Command.FromProtoCommand(c)));
        }
Пример #3
0
        public static Com.Daml.Ledger.Api.V1.Commands ToProto(string ledgerId, string workflowId, string applicationId, string commandId,
                                                              IEnumerable <string> actAs, IEnumerable <string> readAs,
                                                              Optional <DateTimeOffset> minLedgerTimeAbs,
                                                              Optional <TimeSpan> minLedgerTimeRel, Optional <TimeSpan> deduplicationTime,
                                                              IEnumerable <Command> commands)
        {
            var c = new Com.Daml.Ledger.Api.V1.Commands {
                LedgerId = ledgerId, WorkflowId = workflowId, ApplicationId = applicationId, CommandId = commandId
            };

            c.ActAs.AddRange(actAs);
            c.ReadAs.AddRange(readAs);
            c.Party = c.ActAs[0];
            minLedgerTimeAbs.IfPresent(t => c.MinLedgerTimeAbs   = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(t));
            minLedgerTimeRel.IfPresent(t => c.MinLedgerTimeRel   = Google.Protobuf.WellKnownTypes.Duration.FromTimeSpan(t));
            deduplicationTime.IfPresent(d => c.DeduplicationTime = Google.Protobuf.WellKnownTypes.Duration.FromTimeSpan(d));
            c.Commands_.AddRange(from command in commands select command.ToProtoCommand());

            return(c);
        }