Exemple #1
0
        private async Task AddOrUpdateMinerInfo(Miningcore.Persistence.Model.MinerInfo minerInfo)
        {
            if (minerInfo.MinimumPayment == 0)
            {
                await deleteMinerInfo(minerInfo);

                return;
            }

            Miningcore.Persistence.Model.MinerInfo retrieved = await cf.RunTx(async (con, tx) =>
            {
                return(await minerInfoRepository.GetMinerInfo(con, tx, minerInfo.PoolId, minerInfo.Miner));
            });

            if (minerInfo != null)
            {
                await cf.RunTx(async (con, tx) =>
                {
                    await minerInfoRepository.DeleteMinerInfo(con, tx, minerInfo.PoolId, minerInfo.Miner);
                });
            }

            await cf.RunTx(async (con, tx) =>
            {
                await minerInfoRepository.AddMinerInfo(con, tx, minerInfo.PoolId, minerInfo.Miner, minerInfo.MinimumPayment);
            });
        }
        public async Task PayoutAsync(Balance[] balances)
        {
            // ensure we have peers
            var infoResponse = await daemon.ExecuteCmdSingleAsync <object>(logger, AionCommands.GetPeerCount);

            //TODO @AP-137 fix the validation
#if !DEBUG
            if (infoResponse.Error != null ||
                (Convert.ToInt32(infoResponse.Response)) < extraConfig.MinimumPeerCount)
            {
                logger.Warn(() => $"[{LogCategory}] Payout aborted. Not enough peers (" +
                            extraConfig.MinimumPeerCount + " required)");
                return;
            }
#endif

            var txHashes = new List <string>();

            foreach (var balance in balances)
            {
                Miningcore.Persistence.Model.MinerInfo miner = await cf.RunTx(async (con, tx) =>
                {
                    return(await minerInfoRepository.GetMinerInfo(con, tx, poolConfig.Id, balance.Address));
                });

                if (miner != null && miner.MinimumPayment > balance.Amount && extraConfig.EnableMinerMinimumPayment == true)
                {
                    continue;
                }

                try
                {
                    var txHash = await PayoutAsync(balance);

                    txHashes.Add(txHash);
                }

                catch (Exception ex)
                {
                    logger.Error(ex);

                    NotifyPayoutFailure(poolConfig.Id, new[] { balance }, ex.Message, null);
                }
            }

            if (txHashes.Any())
            {
                NotifyPayoutSuccess(poolConfig.Id, balances, txHashes.ToArray(), null);
            }
        }