Пример #1
0
        public async Task <List <MPowPoolDailyReward> > GetLstSum(string timeSpanMin, string timeSpanMax, string addrFrom = "", string addrTo = "")
        {
            List <MPowPoolDailyReward> tmpLst = new List <MPowPoolDailyReward>();
            var lst = await GetLst(timeSpanMin, timeSpanMax, addrFrom, addrTo);

            foreach (var v in lst)
            {
                var reLst = v.balanceLst.GroupBy(p => new { p.addrTo })
                            .Select(g => new
                {
                    addrTo = g.Key.addrTo,
                    reward = g.Sum(p => p.balance)
                }).ToList();
                foreach (var j in reLst)
                {
                    var mo = new MPowPoolDailyReward();
                    mo.addrFrom       = v.addrFrom;
                    mo.settlementDate = v.date.ToString("yyyy-MM-dd");
                    mo.id             = 0;

                    mo.addrTo = j.addrTo;
                    mo.reward = j.reward;
                    tmpLst.Add(mo);
                }
            }

            return(tmpLst);
        }
Пример #2
0
        /// <summary>
        /// insert one
        /// </summary>
        /// <param name="mo"></param>
        /// <returns></returns>
        public async Task <bool> InsertOne(MPowPoolDailyReward mo)
        {
            string addrFrom = mo.addrFrom;
            string addrTo   = mo.addrTo;
            bool   res      = false;

            if (SqlAttack.IsDangerous(ref addrFrom) || SqlAttack.IsDangerous(ref addrTo))
            {
                return(res);
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("INSERT INTO `PowPoolDailyReward` (`id`,`addrFrom`,`addrTo`,`reward`,`settlementDate`) VALUES (");
            sb.Append("@id, @addrFrom, @addrTo, @reward, @settlementDate");
            sb.Append(")");

            using (var conn = new MySqlConnection(connStr))
            {
                //If it has one,skip

                /*var g = await GetBySomething(mo.addrFrom, mo.addrTo, mo.settlementDate);
                 * if(g.Count > 0)
                 * {
                 *  return false;
                 * }*/
                var re = await conn.ExecuteAsync(sb.ToString(), new {
                    id             = 0,
                    addrFrom       = mo.addrFrom.Trim(),
                    addrTo         = mo.addrTo.Trim(),
                    reward         = mo.reward,
                    settlementDate = Convert.ToDateTime(mo.settlementDate).ToString("yyyy-MM-dd")
                });

                // var re = await conn.ExecuteAsync(sb.ToString(), mo);
                if (re > 0)
                {
                    res = true;
                }
                return(res);
            }
        }
Пример #3
0
        public async Task <string> Get(string addrFrom = "", string addrTo = "", string date = "", bool isNewWay = true)
        {
            //only addrFrom,date used
            Result <List <MPowPoolDailyReward> > res = new Result <List <MPowPoolDailyReward> >();
            var lst = new List <MPowPoolDailyReward>();

            try
            {
                //用于强制改变API调用对象,如果是1就使用矿池解锁的每个块的结果
                //如果是2就使用矿池每日统计后的提交结果
                //如果是其它的值,比如0,就由提交的参数决定

                var vv = AppConfigurtaionServices.Configuration.GetSection("isNewWay").Value;
                if (vv.Equals("1"))
                {
                    isNewWay = true;
                }
                else if (vv.Equals("2"))
                {
                    isNewWay = false;
                }

                if (isNewWay)
                {
                    BUnlockBlock b   = new BUnlockBlock(connStr);
                    BCommon      bll = new BCommon(connStr);
                    if (!string.IsNullOrEmpty(date))
                    {
                        DateTime dt = new DateTime();
                        if (DateTime.TryParse(date, out dt))
                        {
                            var dateEnd = dt.AddDays(1);
                            var dStart  = Convert.ToInt64(CommonHelper.GetTimeStamp(dt, zone)) / 1000;      //假定:时间start
                            var dEnd    = Convert.ToInt64(CommonHelper.GetTimeStamp(dateEnd, zone)) / 1000; //假定:时间end
                            lst = await b.GetLstSum(dStart.ToString(), dEnd.ToString(), addrFrom, addrTo);
                        }
                    }

                    //TODO:需要处理date为空的情况

                    var tmp = new List <MPowPoolDailyReward>();
                    if (lst.Count > 0)
                    {
                        var reLst = lst.GroupBy(p => new { p.addrTo, p.addrFrom })
                                    .Select(g => new
                        {
                            addrFrom = g.Key.addrFrom,
                            addrTo   = g.Key.addrTo,
                            reward   = g.Sum(p => p.reward)
                        }).ToList();
                        foreach (var item in reLst)
                        {
                            var mo = new MPowPoolDailyReward();
                            mo.addrFrom       = item.addrFrom;
                            mo.addrTo         = item.addrTo;
                            mo.id             = 0;
                            mo.reward         = item.reward;
                            mo.settlementDate = Convert.ToDateTime(date).ToString("MM/dd/yyy HH:mm:ss");
                            tmp.Add(mo);
                        }
                    }

                    if (2 > 3)
                    {
                        //logic: start, 如果奖励总量不够,就补足97%
                        var query = bll.GetBlockDailyReward(addrFrom, date, "primary-pow");
                        var lsts  = (await query).ToList();
                        var ress  = new Result <List <MBlockPa> >(ResultCode.Ok, null, lsts);

                        decimal block_reward = ress.Data[0].reward_money; // date 日期内addrFrom 的pow出块奖励总额 (吐槽:这个代码,垃圾)
                        decimal rewardSum    = tmp.Sum(p => p.reward);
                        double  bl           = Convert.ToDouble(rewardSum / block_reward);

                        if (bl < 0.975)
                        {
                            double cz = Convert.ToDouble(block_reward - rewardSum) * 0.97;
                            double bc = cz / tmp.Count;
                            foreach (var i in tmp)
                            {
                                i.reward = i.reward + Convert.ToDecimal(bc);
                            }
                        }
                        //logic: end, 如果奖励总量不够,就补足97%
                    }

                    res = new Result <List <MPowPoolDailyReward> >(ResultCode.Ok, null, tmp);
                    return(JsonConvert.SerializeObject(res));
                }
                else
                {
                    BPowPoolDailyReward bll = new BPowPoolDailyReward(connStr);
                    lst = await bll.GetBySomething(addrFrom, addrTo, date);

                    // 这里对相同地址的数据求和

                    var reLst = lst.GroupBy(p => new { p.addrFrom, p.addrTo, p.settlementDate })
                                .Select(g => new
                    {
                        id             = 0,
                        addrFrom       = g.Key.addrFrom,
                        addrTo         = g.Key.addrTo,
                        settlementDate = g.Key.settlementDate,
                        reward         = g.Sum(p => p.reward)
                    }).ToList();

                    var lst_tmp = new List <MPowPoolDailyReward>();
                    foreach (var item in reLst)
                    {
                        var mo = new MPowPoolDailyReward();
                        mo.addrFrom       = item.addrFrom;
                        mo.addrTo         = item.addrTo;
                        mo.id             = 0;
                        mo.reward         = item.reward;
                        mo.settlementDate = item.settlementDate;
                        lst_tmp.Add(mo);
                    }

                    res = new Result <List <MPowPoolDailyReward> >(ResultCode.Ok, null, lst_tmp);
                    return(JsonConvert.SerializeObject(res));
                }
            }
            catch (Exception ex)
            {
                res = new Result <List <MPowPoolDailyReward> >(ResultCode.Fail, ex.Message, null);
                return(JsonConvert.SerializeObject(res));
            }
        }
Пример #4
0
        public async Task <string> Statistics(string addrFrom = "", string addrTo = "", string date = "", bool isNewWay = true)
        {
            Result <List <MPowPoolDailyReward> > res = new Result <List <MPowPoolDailyReward> >();
            var lst = new List <MPowPoolDailyReward>();

            try
            {
                //用于强制改变API调用对象,如果是1就使用矿池解锁的每个块的结果
                //如果是2就使用矿池每日统计后的提交结果
                //如果是其它的值,比如0,就由提交的参数决定

                var vv = AppConfigurtaionServices.Configuration.GetSection("isNewWay").Value;
                if (vv.Equals("1"))
                {
                    isNewWay = true;
                }
                else if (vv.Equals("2"))
                {
                    isNewWay = false;
                }

                if (isNewWay)
                {
                    BUnlockBlock b   = new BUnlockBlock(connStr);
                    BCommon      bll = new BCommon(connStr);
                    DateTime     dateEnd;
                    long         dStart = 0;
                    long         dEnd   = 0;
                    if (!string.IsNullOrEmpty(date))
                    {
                        DateTime dt = new DateTime();
                        if (DateTime.TryParse(date, out dt))
                        {
                            dateEnd = dt.AddDays(1);
                            dStart  = Convert.ToInt64(CommonHelper.GetTimeStamp(dt, zone)) / 1000;
                            dEnd    = Convert.ToInt64(CommonHelper.GetTimeStamp(dateEnd, zone)) / 1000;
                            lst     = await b.GetLstSum(dStart.ToString(), dEnd.ToString(), addrFrom, addrTo);
                        }
                    }

                    //TODO:需要处理date为空的情况

                    var tmp = new List <MPowPoolDailyReward>();
                    if (lst.Count > 0)
                    {
                        var reLst = lst.GroupBy(p => new { p.addrTo, p.addrFrom })
                                    .Select(g => new
                        {
                            addrFrom = g.Key.addrFrom,
                            addrTo   = g.Key.addrTo,
                            reward   = g.Sum(p => p.reward)
                        }).ToList();
                        foreach (var item in reLst)
                        {
                            var mo = new MPowPoolDailyReward();
                            mo.addrFrom       = item.addrFrom;
                            mo.addrTo         = item.addrTo;
                            mo.id             = 0;
                            mo.reward         = item.reward;
                            mo.settlementDate = Convert.ToDateTime(date).ToString("MM/dd/yyy HH:mm:ss");
                            tmp.Add(mo);
                        }
                    }
                    var query = bll.GetBlockDailyReward(addrFrom, date, "primary-pow");
                    var lsts  = (await query).ToList();
                    var ress  = new Result <List <MBlockPa> >(ResultCode.Ok, null, lsts);

                    decimal block_reward = ress.Data[0].reward_money;
                    decimal ys           = tmp.Sum(p => p.reward);
                    decimal count        = tmp.Sum(p => p.reward);
                    double  bl           = Convert.ToDouble(count / block_reward);
                    double  cz           = 0;
                    double  bc           = 0;
                    if (bl < 0.975)
                    {
                        cz = Convert.ToDouble(block_reward - count) * 0.97;
                        bc = cz / tmp.Count;
                        foreach (var i in tmp)
                        {
                            i.reward = i.reward + Convert.ToDecimal(bc);
                        }
                    }
                    count = tmp.Sum(p => p.reward);
                    return(" 统计:" + count.ToString() + ",原始:" + ys.ToString() + ",差额:" + cz.ToString() + ",bc:" + bc.ToString() + ",数量:" + tmp.Count.ToString() + ",地址:" + addrFrom + "开始时间:" + DateTimeOffset.FromUnixTimeSeconds(dStart).ToLocalTime().ToString() + ",结束时间:" + DateTimeOffset.FromUnixTimeSeconds(dEnd).ToLocalTime().ToString());
                }
                else
                {
                    BPowPoolDailyReward bll = new BPowPoolDailyReward(connStr);
                    lst = await bll.GetBySomething(addrFrom, addrTo, date);

                    // 这里对相同地址的数据求和

                    var reLst = lst.GroupBy(p => new { p.addrFrom, p.addrTo, p.settlementDate })
                                .Select(g => new
                    {
                        id             = 0,
                        addrFrom       = g.Key.addrFrom,
                        addrTo         = g.Key.addrTo,
                        settlementDate = g.Key.settlementDate,
                        reward         = g.Sum(p => p.reward)
                    }).ToList();

                    var lst_tmp = new List <MPowPoolDailyReward>();
                    foreach (var item in reLst)
                    {
                        var mo = new MPowPoolDailyReward();
                        mo.addrFrom       = item.addrFrom;
                        mo.addrTo         = item.addrTo;
                        mo.id             = 0;
                        mo.reward         = item.reward;
                        mo.settlementDate = item.settlementDate;
                        lst_tmp.Add(mo);
                    }

                    decimal count = 0;
                    foreach (var i in lst_tmp)
                    {
                        count += i.reward;
                    }
                    return(" 统计:" + count.ToString() + ",地址:" + addrFrom + "开始时间:" + date);
                }
            }
            catch (Exception ex)
            {
                return("error");
            }
        }
        public async Task <string> Get(string addrFrom = "", string addrTo = "", string date = "", bool isNewWay = true)
        {
            Result <List <MPowPoolDailyReward> > res = new Result <List <MPowPoolDailyReward> >();
            var lst = new List <MPowPoolDailyReward>();

            try
            {
                //用于强制改变API调用对象,如果是1就使用矿池解锁的每个块的结果
                //如果是2就使用矿池每日统计后的提交结果
                //如果是其它的值,比如0,就由提交的参数决定

                var vv = AppConfigurtaionServices.Configuration.GetSection("isNewWay").Value;
                if (vv.Equals("1"))
                {
                    isNewWay = true;
                }
                else if (vv.Equals("2"))
                {
                    isNewWay = false;
                }

                if (isNewWay)
                {
                    BUnlockBlock b = new BUnlockBlock(connStr);
                    if (!string.IsNullOrEmpty(date))
                    {
                        DateTime dt = new DateTime();
                        if (DateTime.TryParse(date, out dt))
                        {
                            var dateEnd = dt.AddDays(1);
                            var dStart  = Convert.ToInt64(CommonHelper.GetTimeStamp(dt, zone)) / 1000;
                            var dEnd    = Convert.ToInt64(CommonHelper.GetTimeStamp(dateEnd, zone)) / 1000;
                            lst = await b.GetLstSum(dStart.ToString(), dEnd.ToString(), addrFrom, addrTo);
                        }
                    }

                    //TODO:需要处理date为空的情况

                    var tmp = new List <MPowPoolDailyReward>();
                    if (lst.Count > 0)
                    {
                        var reLst = lst.GroupBy(p => new { p.addrTo, p.addrFrom })
                                    .Select(g => new
                        {
                            addrFrom = g.Key.addrFrom,
                            addrTo   = g.Key.addrTo,
                            reward   = g.Sum(p => p.reward)
                        }).ToList();
                        foreach (var item in reLst)
                        {
                            var mo = new MPowPoolDailyReward();
                            mo.addrFrom       = item.addrFrom;
                            mo.addrTo         = item.addrTo;
                            mo.id             = 0;
                            mo.reward         = item.reward;
                            mo.settlementDate = Convert.ToDateTime(date).ToString("MM/dd/yyy HH:mm:ss");
                            tmp.Add(mo);
                        }
                    }
                    res = new Result <List <MPowPoolDailyReward> >(ResultCode.Ok, null, tmp);
                    return(JsonConvert.SerializeObject(res));
                }
                else
                {
                    BPowPoolDailyReward bll = new BPowPoolDailyReward(connStr);
                    lst = await bll.GetBySomething(addrFrom, addrTo, date);

                    // 这里对相同地址的数据求和

                    var reLst = lst.GroupBy(p => new { p.addrFrom, p.addrTo, p.settlementDate })
                                .Select(g => new
                    {
                        id             = 0,
                        addrFrom       = g.Key.addrFrom,
                        addrTo         = g.Key.addrTo,
                        settlementDate = g.Key.settlementDate,
                        reward         = g.Sum(p => p.reward)
                    }).ToList();

                    var lst_tmp = new List <MPowPoolDailyReward>();
                    foreach (var item in reLst)
                    {
                        var mo = new MPowPoolDailyReward();
                        mo.addrFrom       = item.addrFrom;
                        mo.addrTo         = item.addrTo;
                        mo.id             = 0;
                        mo.reward         = item.reward;
                        mo.settlementDate = item.settlementDate;
                        lst_tmp.Add(mo);
                    }

                    res = new Result <List <MPowPoolDailyReward> >(ResultCode.Ok, null, lst_tmp);
                    return(JsonConvert.SerializeObject(res));
                }
            }
            catch (Exception ex)
            {
                res = new Result <List <MPowPoolDailyReward> >(ResultCode.Fail, ex.Message, null);
                return(JsonConvert.SerializeObject(res));
            }
        }