Exemple #1
0
        public static async Task Run([PerperStreamTrigger(RunOnStartup = true)] PerperStreamContext context,
                                     CancellationToken cancellationToken)
        {
            var keys         = new List <(ECParameters, ValidatorKey)>();
            var validatorSet = new ValidatorSet();

            for (var i = 0; i < 1; i++)
            {
                using var dsa = ECDsa.Create(ECCurve.NamedCurves.nistP521);
                var privateKey = dsa.ExportParameters(true);
                var publicKey  = new ValidatorKey {
                    Key = dsa.ExportParameters(false)
                };
                keys.Add((privateKey, publicKey));
                validatorSet.Weights.Add(publicKey, 10);
            }

            var ipfsGateway = "http://127.0.0.1:5001";

            await using var _validatorSetsStream = await context.StreamFunctionAsync("TestDataGenerator", new
            {
                delay = TimeSpan.FromSeconds(20),
                data  = validatorSet
            });

            await using var validatorSetsStream = await context.StreamFunctionAsync(nameof (IpfsSaver), new
            {
                ipfsGateway,
                dataStream = _validatorSetsStream
            });

            await using var validatorLauncherStreams = new AsyncDisposableList();
            foreach (var(privateKey, self) in keys)
            {
                validatorLauncherStreams.Add(
                    await context.StreamActionAsync(nameof(ValidatorLauncher), new
                {
                    agentId  = "0",
                    services = new [] { "Sample", "IpfsInput" },
                    validatorSetsStream,
                    ipfsGateway,
                    privateKey,
                    self
                }));
            }

            await context.BindOutput(cancellationToken);
        }
        public static async Task Run([PerperStreamTrigger] PerperStreamContext context,
                                     [Perper("agentId")] string agentId,
                                     [Perper("services")] string[] services,
                                     [Perper("commandsStream")] object[] commandsStream,
                                     [Perper("genesisMessage")] object genesisMessage,
                                     [Perper("ipfsGateway")] string ipfsGateway,
                                     CancellationToken cancellationToken)
        {
            await using var genesisMessageStream = await context.StreamFunctionAsync(nameof (TestDataGenerator), new
            {
                delay = TimeSpan.FromSeconds(10),
                data  = genesisMessage
            });

            /* await using var agentZeroStream = await context.StreamFunctionAsync(nameof(IpfsInput), new
             * {
             *  ipfsGateway,
             *  topic = 0 //"apocryph-agent-0"
             * });
             *
             * await using var _inputVerifierStream = await context.StreamFunctionAsync(nameof(StepSignatureVerifier), new
             * {
             *  validatorSetsStream, // TODO: Should give agent 0's validator set instead !!
             *  stepsStream = agentZeroStream,
             * });
             *
             * await using var inputVerifierStream = await context.StreamFunctionAsync(nameof(IpfsLoader), new
             * {
             *  ipfsGateway,
             *  hashStream = _inputVerifierStream
             * });
             *
             * await using var validatorSetsStream = await context.StreamFunctionAsync(nameof(ValidatorSets), new
             * {
             *  inputVerifierStream
             * });
             *
             * await using var subscriptionCommandExecutorStream = await context.StreamFunctionAsync(nameof(SubscriptionCommandExecutor), new
             * {
             *  ipfsGateway,
             *  commandsStream,
             *  validatorSetsStream
             * }); */

            await using var reminderCommandExecutorStream = await context.StreamFunctionAsync(nameof (ReminderCommandExecutor), new
            {
                commandsStream
            });

            await using var serviceFilterStreams = new AsyncDisposableList();
            await using var serviceStreams       = new AsyncDisposableList();
            foreach (var serviceName in services)
            {
                var functionName           = "Service" + serviceName;
                var filteredCommandsStream = await context.StreamFunctionAsync(nameof(ServiceCommandFilter), new
                {
                    commandsStream,
                    serviceName
                });

                serviceFilterStreams.Add(filteredCommandsStream);
                var serviceStream = await context.StreamFunctionAsync(functionName, new
                {
                    commandsStream = filteredCommandsStream,
                    agentId,
                    ipfsGateway
                });

                serviceStreams.Add(serviceStream);
            }

            var outputStream = new []
            {
                reminderCommandExecutorStream,
                genesisMessageStream,
                // subscriptionCommandExecutorStream
            }.Concat(serviceStreams).ToArray();


            await context.BindOutput(outputStream, cancellationToken);
        }