Exemple #1
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            //Console.WriteLine(PoolNodesBLL.GetPoolNodeCount());
            long    x = 10123;
            decimal y = 23.00m;

            Console.WriteLine(x / y);
            Console.WriteLine(LBTCNodesBLL.GetAllNodes().Count);
            Console.WriteLine(PoolNodesBLL.GetPoolNodesByGroupID(0).Count);
            Console.ReadKey();
        }
        private IndexViewModel GetModel(string useraddress)
        {
            var     list     = LBTCNodesBLL.Get101Nodes(-1);
            decimal votessum = NodeVotesBLL.GetPoolNodeVotesSum();

            votessum = votessum / Strings.CoinToCong;
            votessum = Math.Round(votessum, 2);
            return(new IndexViewModel
            {
                HisSumCoins = Math.Round(UserInComesHisBLL.GetInComesSum(useraddress, null, null), 2),
                NowSumCoins = Math.Round(UserInComesOnlineBLL.GetOnlineInComesSum(useraddress, null), 6),
                NodeAllCount = PoolNodesBLL.GetPoolNodeCount(),
                NodeCount = list.Count,
                VotesSum = votessum,
                UsersSum = UserAddressesBLL.GetAllUserCount()
            });
        }
        /// <summary>
        /// 查询矿池票数
        /// </summary>
        public JsonResult GetGroupVotes()
        {
            var list     = PoolNodesBLL.GetPoolNodesByGroupID(0);
            var allnodes = LBTCNodesBLL.GetAllNodes();
            var rlist    = new List <IndexGroupVotes>();

            foreach (var node in list)
            {
                var NodeOrderIndex = 0;
                var GetRate        = 0.00m;
                var NodeVotes      = 0.00m;
                foreach (var nn in allnodes)
                {
                    NodeOrderIndex++;
                    if (nn.NodeAddress == node.NodeAddress)
                    {
                        GetRate   = nn.GetRate;
                        NodeVotes = Math.Round(nn.NodeVotes / Strings.CoinToCong, 2);
                        break;
                    }
                }
                //var IsForging = NodeOrderIndex < 101 ? 1 : 0;
                rlist.Add(new IndexGroupVotes
                {
                    NodeName       = node.NodeName,
                    NodeAddress    = node.NodeAddress,
                    NodeVotes      = NodeVotes,
                    MakeShareCoins = node.MakeShareCoins,
                    GetRate        = GetRate,
                    NodeOrderIndex = NodeOrderIndex
                });
            }
            var in101s  = rlist.FindAll(x => x.NodeOrderIndex < 101).OrderByDescending(x => x.NodeOrderIndex);
            var out101s = rlist.FindAll(x => x.NodeOrderIndex >= 101).OrderBy(x => x.NodeOrderIndex);
            var returns = in101s.Concat(out101s).ToList();

            return(Json(returns));
        }
Exemple #4
0
        public static void ShareCoins(object source, ElapsedEventArgs e)
        {
            //Console.WriteLine("Share Begin!");
            log.Info("循环执行时间:" + DateTime.Now.ToString() + "");
            string listnodess = RunScript("listdelegates");

            listhasnodes = LBTCNodesBLL.GetAllNodes();
            var newlisthasnodes = new List <LBTCNodes>();
            var addlist         = new List <LBTCNodes>();
            var alllist         = new List <LBTCNodes>();
            var onenode         = new LBTCNodes();

            poolnodes = PoolNodesBLL.GetPoolNodesByGroupID(0);
            var datarunInt = -1;

            #region 30秒更新一次节点投票信息
            if (Strings.ScriptTrue(listnodess))
            {
                try
                {
                    try
                    {
                        var    listnodes  = JsonConvert.DeserializeObject <List <NodeInfo> >(listnodess);
                        string nodevotess = "";
                        long   nodevotes  = 0;//节点投票数
                        foreach (var node in listnodes)
                        {
                            var thisname = node.name.Replace(Environment.NewLine, "");
                            //thisname = thisname.Trim();
                            if (!string.IsNullOrWhiteSpace(thisname))
                            {
                                nodevotess = RunScript("getdelegatevotes \"" + thisname + "\"");
                                if (Strings.ScriptTrue(nodevotess))
                                {
                                    nodevotes = long.Parse(nodevotess);
                                }
                                var GroupID = GetGorupID(node.address);
                                alllist.Add(new LBTCNodes
                                {
                                    NodeID      = node.id,
                                    NodeAddress = node.address,
                                    NodeName    = thisname,
                                    NodeVotes   = nodevotes,
                                    GroupID     = GroupID,
                                    GetRate     = 0.0000m
                                });
                                if (IsInHasList(node.address))
                                {
                                    newlisthasnodes.Add(new LBTCNodes
                                    {
                                        NodeID      = node.id,
                                        NodeAddress = node.address,
                                        NodeName    = thisname,
                                        NodeVotes   = nodevotes,
                                        GroupID     = GroupID
                                    });
                                }
                                else
                                {
                                    addlist.Add(new LBTCNodes
                                    {
                                        NodeID      = node.id,
                                        NodeAddress = node.address,
                                        NodeName    = thisname,
                                        NodeVotes   = nodevotes,
                                        GroupID     = GroupID,
                                        GetRate     = 0.0000m
                                    });
                                }
                            }
                        }
                        if (newlisthasnodes.Count > 0)
                        {
                            datarunInt = LBTCNodesBLL.UpdateNodesWithOutRate(newlisthasnodes);
                        }
                        if (addlist.Count > 0)
                        {
                            datarunInt = LBTCNodesBLL.InsertNodes(addlist);
                        }
                    }
                    catch (Exception er)
                    {
                        log.Error(er.ToString());
                    }
                }
                catch (Exception ee)
                {
                    log.Error(ee.ToString());
                }
            }
            #endregion

            #region 每周五9点按时发放分红
            var  publictime = DateTime.Now;
            bool isintime   = Strings.WeekDayToInt(publictime.DayOfWeek) == conf.ShareCoinsWeekDay && publictime.Hour == conf.ShareCoinsHour && publictime.Minute <= conf.GetNodesTimerSpan / 60 && publictime.Second < conf.GetNodesTimerSpan % 60;
            //isintime = publictime.Hour == 13 && publictime.Minute == 43 && publictime.Second < 30;
            if (isintime)
            {
                //统计节点分红率
                var allpoolnodes = PoolNodesBLL.GetPoolNodesByGroupID(0);
                var publicnodes  = new List <LBTCNodes>();
                foreach (var node in allpoolnodes)
                {
                    var getcoinsAll = UserInComesOnlineBLL.GetOnlineInComesSum(null, node.NodeAddress);
                    var thisnode    = alllist.Find(x => x.NodeAddress == node.NodeAddress);
                    if (thisnode != null)
                    {
                        if (thisnode.NodeVotes > 0)
                        {
                            thisnode.GetRate = Math.Round(getcoinsAll * Strings.CoinToCong * 10000.00m / thisnode.NodeVotes, 4);
                        }
                        else
                        {
                            thisnode.GetRate = 0.0000m;
                        }
                    }
                    publicnodes.Add(thisnode);
                }
                datarunInt = LBTCNodesBLL.UpdateNodesWithAll(publicnodes);
                //发放分红
                var listusers = UserAddressesBLL.GetAllUserAddress();
                //poolgroups = PoolGroupBLL.GetAllPoolGroup();
                var hislist = new List <UserInComesHis>();
                foreach (var user in listusers)
                {
                    var getcoinsAll = UserInComesOnlineBLL.GetOnlineInComesSum(user.UserAddress, null);
                    if (getcoinsAll >= conf.ShareMin)
                    {
                        //7044 5ad6 5891 8824 85d2 1c6c 2014 35cc 921b 9e17 1e30 3cb1 30f5 1539 0649 3a2e
                        //执行转账脚本
                        string txhash = RunScript("sendtoaddress " + user.UserAddress + " " + getcoinsAll.ToString());
                        //string txhash = RunScript("sendtoaddress 12CacXV2WvdUNBu9K3Z1CUBvfEizPq9r4D 0.005");
                        log.Info("分红:sendtoaddress " + user.UserAddress + " " + getcoinsAll.ToString() + "------txid:" + txhash);
                        if (Strings.ScriptTrue(txhash) && txhash.Length == 64)
                        {
                            string listhis = "";
                            foreach (var poolnode in poolnodes)
                            {
                                var getcoinsone = UserInComesOnlineBLL.GetOnlineInComesSum(user.UserAddress, poolnode.NodeAddress);
                                listhis += "|" + poolnode.NodeAddress + "-" + getcoinsone.ToString();
                            }
                            listhis = listhis.Trim('|');
                            hislist.Add(new UserInComesHis {
                                InComeID        = Guid.NewGuid().ToString(),
                                NodeAddresses   = listhis,
                                UserAddress     = user.UserAddress,
                                SetTime         = publictime,
                                GetCoins        = getcoinsAll,
                                TransactionHash = txhash
                            });
                            datarunInt = UserInComesOnlineBLL.DelOnlineInComesByUserAddress(user.UserAddress);
                        }
                    }
                }
                if (hislist.Count > 0)
                {
                    datarunInt = UserInComesHisBLL.InsertInComesHis(hislist);
                }
                datarunInt = PoolNodesBLL.CleanOnlineCoins();//还原所有矿池节点周期统计
            }
            #endregion

            log.Info("循环结束时间:" + DateTime.Now.ToString() + "");
        }
        /// <summary>
        /// 获取分红统计
        /// </summary>
        public JsonResult GetView(string useraddress)
        {
            var list = LBTCNodesBLL.Get101Nodes(0);

            return(Json(GetModel(useraddress)));
        }
 /// <summary>
 /// 查询101节点情况
 /// </summary>
 public JsonResult Get101Votes()
 {
     return(Json(LBTCNodesBLL.Get101Nodes(0)));
 }