Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="configuration"></param>
 /// <returns></returns>
 public static ContainerBuilder AddPosMinting(this ContainerBuilder builder, IConfiguration configuration)
 {
     builder.Register(c =>
     {
         var stakingConfigurationOptions = new StakingConfigurationOptions();
         configuration.Bind("Staking", stakingConfigurationOptions);
         var posMintingProvider = new PosMinting(c.Resolve <IGraph>(), c.Resolve <IMemoryPool>(),
                                                 c.Resolve <ISerfClient>(), c.Resolve <IUnitOfWork>(), c.Resolve <ISigning>(), c.Resolve <IValidator>(),
                                                 c.Resolve <ISync>(), stakingConfigurationOptions, c.Resolve <Serilog.ILogger>(), c.Resolve <IHostApplicationLifetime>());
         return(posMintingProvider);
     }).As <IStartable>().SingleInstance();
     return(builder);
 }
Exemplo n.º 2
0
        public PosMinting(IGraph graph, IMemoryPool memoryPool, ISerfClient serfClient, IUnitOfWork unitOfWork,
                          ISigning signing, IValidator validator, ISync sync, StakingConfigurationOptions stakingConfigurationOptions,
                          ILogger logger, IHostApplicationLifetime applicationLifetime)
        {
            _graph      = graph;
            _memoryPool = memoryPool;
            _serfClient = serfClient;
            _unitOfWork = unitOfWork;
            _signing    = signing;
            _validator  = validator;
            _sync       = sync;
            _stakingConfigurationOptions = stakingConfigurationOptions;
            _logger  = logger.ForContext("SourceContext", nameof(PosMinting));
            _keyPair = _signing.GetOrUpsertKeyName(_signing.DefaultSigningKeyName).GetAwaiter().GetResult();

            _stakingTimer      = new Timer(async _ => await Staking(), null, TimeSpan.FromSeconds(35), TimeSpan.FromSeconds(10));
            _decideWinnerTimer = new Timer(async _ => await DecideWinner(), null, TimeSpan.FromSeconds(40), TimeSpan.FromSeconds(20));

            applicationLifetime.ApplicationStopping.Register(OnApplicationStopping);
        }