public async Task <ActionResult> UpdatePool(AdminUpdatePoolModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("UpdatePoolModal", model));
            }

            var result = await PoolWriter.AdminUpdatePool(model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("UpdatePoolModal", model));
            }

            return(CloseModalSuccess(result.Message));
        }
Exemplo n.º 2
0
        public async Task <IWriterResult> AdminUpdatePool(AdminUpdatePoolModel model)
        {
            try
            {
                using (var context = PoolDataContextFactory.CreateContext())
                {
                    var pool = await context.Pool
                               .Include(x => x.Statistics)
                               .Where(c => c.Id == model.Id)
                               .FirstOrDefaultNoLockAsync().ConfigureAwait(false);

                    if (pool == null)
                    {
                        return(new WriterResult(false, "Pool not found"));
                    }

                    var connection = await context.Connection.FirstOrDefaultNoLockAsync(x => x.AlgoType == pool.AlgoType);

                    if (connection == null)
                    {
                        return(new WriterResult(false, "Algorithm not found"));
                    }

                    if (pool.Status == Enums.PoolStatus.OK &&
                        (model.Status == Enums.PoolStatus.Maintenance || model.Status == Enums.PoolStatus.Offline))
                    {
                        var backupPool = await context.Pool
                                         .Where(x => x.AlgoType == pool.AlgoType && x.Status == Enums.PoolStatus.OK && x.Id != pool.Id)
                                         .OrderByDescending(x => x.Statistics.Profitability)
                                         .FirstOrDefaultNoLockAsync().ConfigureAwait(false);

                        var workers = await context.Worker
                                      .Where(x => x.AlgoType == pool.AlgoType && x.TargetPool == pool.Symbol)
                                      .ToListNoLockAsync().ConfigureAwait(false);

                        foreach (var worker in workers)
                        {
                            // If the default pool is not this pool set as target
                            if (connection.DefaultPool != pool.Symbol)
                            {
                                worker.TargetPool = connection.DefaultPool;
                                continue;
                            }

                            // If everything is down use fist working pool
                            if (backupPool != null)
                            {
                                worker.TargetPool = backupPool.Symbol;
                                continue;
                            }
                            // if we are here the whole mineshaft is obviously down so do nothing
                        }
                    }

                    pool.Status                 = model.Status;
                    pool.StatusMessage          = model.StatusMessage;
                    pool.BlockTime              = model.BlockTime;
                    pool.IsForkCheckDisabled    = model.IsForkCheckDisabled;
                    pool.SpecialInstructions    = model.SpecialInstructions;
                    pool.WalletFee              = model.WalletFee;
                    pool.Statistics.BlockReward = model.BlockReward;

                    await context.SaveChangesAsync().ConfigureAwait(false);

                    return(new WriterResult(true, "Successfully updated pool details."));
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }