Exemplo n.º 1
0
 public PingPongProcessor(string party, string ledgerId, Channel channel, Identifier pingIdentifier, Identifier pongIdentifier)
 {
     _party              = party;
     _ledgerId           = ledgerId;
     _transactionService = new TransactionService.TransactionServiceClient(channel);
     _submissionService  = new CommandSubmissionService.CommandSubmissionServiceClient(channel);
     _pingIdentifier     = pingIdentifier;
     _pongIdentifier     = pongIdentifier;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates numContracts number of Ping contracts.The sender is used as the submitting party.
        /// </summary>
        /// <param name="channel">the gRPC channel to use for services</param>
        /// <param name="ledgerId">the previously fetched ledger id</param>
        /// <param name="sender">the party that sends the initial Ping contract</param>
        /// <param name="receiver">the party that receives the initial Ping contract</param>
        /// <param name="pingIdentifier">the PingPong.Ping template identifier</param>
        /// <param name="numContracts">the number of initial contracts to create</param>
        private static void CreateInitialContracts(Channel channel, string ledgerId, string sender, string receiver, Identifier pingIdentifier, int numContracts)
        {
            var submissionService = new CommandSubmissionService.CommandSubmissionServiceClient(channel);

            var record = new Record {
                RecordId = pingIdentifier
            };                                                                                      // the identifier for a template's record is the same as the identifier for the template

            record.Fields.Add(new[] { new RecordField {
                                          Label = "sender", Value = new Value {
                                              Party = sender
                                          }
                                      },
                                      new RecordField {
                                          Label = "receiver", Value = new Value {
                                              Party = receiver
                                          }
                                      },
                                      new RecordField {
                                          Label = "count", Value = new Value {
                                              Int64 = 0
                                          }
                                      } });

            var createCommand = new Command {
                Create = new CreateCommand {
                    TemplateId = pingIdentifier, CreateArguments = record
                }
            };

            for (int i = 0; i < numContracts; i++)
            {
                var submitRequest = new SubmitRequest
                {
                    Commands = new Commands
                    {
                        LedgerId = ledgerId,
                        // set current time to ledger effective time (LET)
                        LedgerEffectiveTime = new Google.Protobuf.WellKnownTypes.Timestamp {
                            Seconds = 0
                        },
                        // set maximum record time (MRT) to now + 5s
                        MaximumRecordTime = new Google.Protobuf.WellKnownTypes.Timestamp {
                            Seconds = 5
                        },
                        CommandId     = Guid.NewGuid().ToString(),
                        WorkflowId    = $"Ping-{sender}-{i}",
                        Party         = sender,
                        ApplicationId = APP_ID
                    }
                };
                submitRequest.Commands.Commands_.Add(createCommand);

                // asynchronously send the commands
                submissionService.SubmitAsync(submitRequest);
            }
        }