コード例 #1
0
ファイル: Pool.cs プロジェクト: Gabbe-x/smartx-dotnet
        public MinerView GetMinerView(string address, long transferIndex, long transferColumn, long minerIndex, long minerColumn)
        {
            transferColumn = Math.Min(transferColumn, 100);
            minerColumn    = Math.Min(minerColumn, 100);

            var minerView = new MinerView();

            minerView.address = address;

            var transfers_cur = MinerReward_PPLNS(false)?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
            }

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                int TopIndex = snapshot.Queue.GetTopIndex($"Pool_MT_{address}");
                for (int ii = 1; ii <= (int)transferColumn; ii++)
                {
                    var value = snapshot.Queue.Get($"Pool_MT_{address}", TopIndex - (int)transferIndex - ii);
                    if (!string.IsNullOrEmpty(value))
                    {
                        var transfer = JsonHelper.FromJson <BlockSub>(value);
                        if (transfer != null)
                        {
                            minerView.transfers.Add(transfer);
                        }
                    }
                }

                foreach (var transfer in minerView.transfers)
                {
                    // 节点使用自己的地址挖矿
                    if (transfer.addressIn == transfer.addressOut)
                    {
                        transfer.hash = transfer.addressIn;
                    }
                    else
                    {
                        transfer.hash = transferProcess.GetMinerTansfer(snapshot, transfer.data);
                    }
                }
            }

            var miners    = httpPool.GetMinerReward(out long miningHeight);
            var minerList = miners?.Values.Where((x) => x.address == address).ToList();

            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                for (var ii = 0; ii < minerColumn; ii++)
                {
                    if ((minerIndex + ii) >= minerList.Count)
                    {
                        break;
                    }
                    var miner = minerList[(int)minerIndex + ii];

                    if (string.IsNullOrEmpty(miner.power_cur))
                    {
                        miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                    }

                    var minerdata = new MinerViewData();
                    minerdata.number    = miner.number;
                    minerdata.lasttime  = miner.time;
                    minerdata.power_cur = miner.power_cur;

                    double.TryParse(miner.power_average, out double power_average);
                    minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                    minerView.miners.Add(minerdata);

                    totalPower += power_average;
                }
                minerView.totalMiners = minerList.Count;
            }

            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            return(minerView);
        }
コード例 #2
0
ファイル: Pool.cs プロジェクト: mangodager/smartx-dotnet
        public MinerView GetMinerView(string address, long transferIndex, long transferColumn, long minerIndex, long minerColumn)
        {
            if (getMinerViewTimePass.IsPassSet())
            {
                getMinerViewCache.Clear();
            }
            if (getMinerViewCache.TryGetValue($"{address}_{transferIndex}_{transferColumn}_{minerIndex}_{minerColumn}", out MinerView minerViewLast))
            {
                return(minerViewLast);
            }

            transferColumn = Math.Min(transferColumn, 100);
            minerColumn    = Math.Min(minerColumn, 100);

            var minerView = new MinerView();

            minerView.address = address;

            Dictionary <string, BlockSub> minerTransferCache = null;

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                var str = snapshot.Get($"Pool_Cache_MinerReward");
                if (!string.IsNullOrEmpty(str))
                {
                    minerTransferCache = JsonHelper.FromJson <Dictionary <string, BlockSub> >(str);
                }
            }

            var transfers_cur = minerTransferCache?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
                minerView.share      = transfers_cur.type;
            }

            // 交易确认
            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                int TopIndex = snapshot.Queue.GetTopIndex($"Pool_MT_{address}");
                for (int ii = 1; ii <= (int)transferColumn; ii++)
                {
                    var value = snapshot.Queue.Get($"Pool_MT_{address}", TopIndex - (int)transferIndex - ii);
                    if (!string.IsNullOrEmpty(value))
                    {
                        var transfer = JsonHelper.FromJson <BlockSub>(value);
                        if (transfer != null)
                        {
                            minerView.transfers.Add(transfer);
                        }
                    }
                }

                foreach (var transfer in minerView.transfers)
                {
                    // 节点使用自己的地址挖矿
                    if (transfer.addressIn == transfer.addressOut)
                    {
                        transfer.hash = transfer.addressIn;
                    }
                    else
                    {
                        transfer.hash = TransferProcess.GetMinerTansfer(snapshot, transfer.data);
                    }
                }
            }

            var    miners     = httpPool.GetMinerRewardMin(out long miningHeight);
            var    minerList  = miners?.Values.Where((x) => x.address == address).ToList();
            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                // 当前页矿机算力
                for (var ii = 0; ii < minerColumn; ii++)
                {
                    if ((minerIndex + ii) >= minerList.Count)
                    {
                        break;
                    }
                    var miner = minerList[(int)minerIndex + ii];

                    if (string.IsNullOrEmpty(miner.power_cur))
                    {
                        miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                    }

                    var minerdata = new MinerViewData();
                    minerdata.number    = miner.number;
                    minerdata.lasttime  = miner.time;
                    minerdata.power_cur = miner.power_cur;

                    double.TryParse(miner.power_average, out double power_average);
                    minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                    minerView.miners.Add(minerdata);
                }

                // 当前总算力
                for (var ii = 0; ii < minerList.Count; ii++)
                {
                    var miner = minerList[ii];
                    if (double.TryParse(miner.power_average, out double power_average))
                    {
                        totalPower += power_average;
                    }
                }
                minerView.totalMiners = minerList.Count;
            }

            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            getMinerViewCache.Add($"{address}_{transferIndex}_{transferColumn}_{minerIndex}_{minerColumn}", minerView);
            return(minerView);
        }
コード例 #3
0
        public MinerView GetMinerView(string address, long transferIndex, long transferColumn, long minerIndex, long minerColumn)
        {
            var minerView = new MinerView();

            minerView.address = address;

            var transfers_cur = MinerReward_PPLNS(false)?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
            }

            long counted = 0;

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                string str_Counted = snapshot.Get("Pool_Counted");
                if (long.TryParse(str_Counted, out counted))
                {
                    counted = counted - transferIndex;
                    for (int i = 0; i < transferColumn; i++)
                    {
                        string str_MT = snapshot.Get($"Pool_MT_{counted-i}");
                        Dictionary <string, BlockSub> minerTransfer = null;
                        if (!string.IsNullOrEmpty(str_MT))
                        {
                            minerTransfer = JsonHelper.FromJson <Dictionary <string, BlockSub> >(str_MT);
                            if (minerTransfer != null)
                            {
                                var transfer = minerTransfer?.Values.FirstOrDefault(c => c.addressOut == address);
                                if (transfer != null)
                                {
                                    string        str_MR          = snapshot.Get($"Pool_MR_{counted - i}");
                                    MinerRewardDB minerRewardLast = null;
                                    if (!string.IsNullOrEmpty(str_MR))
                                    {
                                        minerRewardLast = JsonHelper.FromJson <MinerRewardDB>(str_MR);
                                    }

                                    long.TryParse(minerRewardLast.time, out long time);
                                    transfer.depend = new DateTime(time).ToString("yyyy-MM-dd HH:mm:ss");
                                    minerView.transfers.Add(transfer);
                                }
                            }
                        }
                    }
                }
            }

            // Is the query successful
            using (var dbSnapshot = PoolDBStore.GetSnapshot(0))
            {
                foreach (var transfer in minerView.transfers)
                {
                    transfer.hash = transferProcess.GetMinerTansfer(dbSnapshot, transfer.data);
                }
            }

            var miners    = httpPool.GetMinerReward(out long miningHeight);
            var minerList = miners?.Values.Where((x) => x.address == address).ToList();

            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                for (var ii = 0; ii < minerColumn; ii++)
                {
                    if ((minerIndex + ii) >= minerList.Count)
                    {
                        break;
                    }
                    var miner = minerList[(int)minerIndex + ii];

                    if (string.IsNullOrEmpty(miner.power_cur))
                    {
                        miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                    }

                    var minerdata = new MinerViewData();
                    minerdata.number    = miner.number;
                    minerdata.lasttime  = miner.time;
                    minerdata.power_cur = miner.power_cur;

                    double.TryParse(miner.power_average, out double power_average);
                    minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                    minerView.miners.Add(minerdata);

                    totalPower += power_average;
                }
                minerView.totalMiners = minerList.Count;
            }

            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            return(minerView);
        }