示例#1
0
        // 移动端调用:获取注册器竞拍账户余额
        public JArray getRegisterAddressBalance(string address, string registerhash)
        {
            registerhash = registerhash.StartsWith("0x") ? registerhash: "0x" + registerhash;
            string findstr = new JObject()
            {
                { "address", address }, { "register", registerhash }
            }.ToString();
            string fieldstr = new JObject()
            {
                { "balance", 1 }
            }.ToString();
            JArray res = mh.GetDataWithField(mongodbConnStr, mongodbDatabase, cgasBalanceStateCol, fieldstr, findstr);

            if (res == null || res.Count() == 0)
            {
                return(new JArray());
            }
            JObject jo    = (JObject)res[0];
            string  value = jo["balance"].ToString();

            value = NumberDecimalHelper.formatDecimal(value);
            jo.Remove("balance");
            jo.Add("balance", value);
            return(new JArray()
            {
                jo
            });
        }
        public JArray getNNCfromSellingHash(string address)
        {
            string findStr = new JObject()
            {
                { "address", address }, { "register", NNSfixedSellingColl }
            }.ToString();
            string fieldStr = new JObject()
            {
                { "address", 1 }, { "balance", 1 }
            }.ToString();
            var query = mh.GetDataWithField(Notify_mongodbConnStr, Notify_mongodbDatabase, "nnsFixedSellingBalanceState", fieldStr, findStr);

            if (query == null || query.Count == 0)
            {
                return new JArray {
                }
            }
            ;


            return(new JArray {
                new JObject()
                {
                    { "address", query[0]["address"] },
                    { "balance", NumberDecimalHelper.formatDecimal(query[0]["balance"].ToString()) }
                }
            });
        }
示例#3
0
        public JArray getAuctionInfo(string auctionId)
        {
            // 域名信息:
            // 域名 + 哈希 + 开始时间 + 结束时间 + maxBuyer + maxPrice + auctionState + 开标块
            string findStr = new JObject()
            {
                { "auctionId", auctionId }
            }.ToString();
            string fieldStr = MongoFieldHelper.toReturn(new string[] { "fulldomain", "auctionId", "startTime.blocktime", "endTime.blocktime", "lastTime.blocktime", "maxBuyer", "maxPrice", "auctionState", "startTime.blockindex", "ttl" }).ToString();
            JArray res      = mh.GetDataWithField(Notify_mongodbConnStr, Notify_mongodbDatabase, auctionStateColl, fieldStr, findStr);

            res = new JArray()
            {
                res.Select(p =>
                {
                    JObject jo   = (JObject)p;
                    string value = jo["maxPrice"].ToString();
                    value        = NumberDecimalHelper.formatDecimal(value);
                    jo.Remove("maxPrice");
                    jo.Add("maxPrice", value);
                    return(jo);
                }).ToArray()
            };
            return(format(res));
        }
示例#4
0
        //获取当前分红的信息
        public JArray getCurrentBonus(string address)
        {
            //获取最新的分红数据表
            var    cur     = (JObject)mh.GetData(Bonus_mongodbConnStr, Bonus_mongodbDatabase, CurrentBonusCol, "{}")[0];
            string curColl = cur["currentColl"].ToString();
            //获取此次分红的信息
            JObject queryFilter = new JObject()
            {
                { "addr", address }
            };
            JArray jAData = mh.GetData(Bonus_mongodbConnStr, Bonus_mongodbDatabase, curColl, queryFilter.ToString());

            if (jAData == null || jAData.Count() == 0)
            {
                JObject _jo = new JObject();

                _jo["addr"]        = address;
                _jo["assetid"]     = cur["assetid"].ToString();
                _jo["balance"]     = "0";
                _jo["send"]        = "0";
                _jo["totalSend"]   = NumberDecimalHelper.formatDecimal(cur["totalValue"].ToString());
                _jo["txid"]        = "";
                _jo["sendAssetid"] = cur["sendAssetid"].ToString();
                _jo["applied"]     = false;
                UInt32 _height = UInt32.Parse(cur["height"].ToString());
                _jo["height"] = _height;
                string _blocktimeFindstr = new JObject()
                {
                    { "index", _height }
                }.ToString();
                JObject _joBlock = (JObject)mh.GetData(Block_mongodbConnStr, Block_mongodbDatabase, "block", _blocktimeFindstr)[0];
                _jo["blocktime"] = _joBlock["time"].ToString();
                return(new JArray()
                {
                    _jo
                });
            }
            JObject jObject = (JObject)jAData[0];
            //获取高度对应的时间
            UInt32 height           = UInt32.Parse(jObject["height"].ToString());
            string blocktimeFindstr = new JObject()
            {
                { "index", height }
            }.ToString();
            JObject joBlock = (JObject)mh.GetData(Block_mongodbConnStr, Block_mongodbDatabase, "block", blocktimeFindstr)[0];

            jObject["blocktime"] = joBlock["time"].ToString();
            jObject["balance"]   = NumberDecimalHelper.formatDecimal(jObject["balance"].ToString());
            jObject["totalSend"] = NumberDecimalHelper.formatDecimal(jObject["totalSend"].ToString());
            jObject["send"]      = NumberDecimalHelper.formatDecimal(jObject["send"].ToString());
            return(new JArray()
            {
                jObject
            });
        }
示例#5
0
        public JArray getAuctionInfoRank(string auctionId, int pageNum = 1, int pageSize = 10)
        {
            // 竞价排行:
            // 排名 + 价格 + 竞标人
            string findStr = new JObject()
            {
                { "auctionId", auctionId }
            }.ToString();
            string fieldStr = MongoFieldHelper.toReturn(new string[] { "addwholist.address", "addwholist.totalValue" }).ToString();
            JArray res      = mh.GetDataWithField(Notify_mongodbConnStr, Notify_mongodbDatabase, auctionStateColl, fieldStr, findStr);

            if (res == null || res.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            JToken[] jt = res.SelectMany(p =>
            {
                JObject ja = (JObject)p;
                return((JArray)ja["addwholist"]);
            }).ToArray();

            //JToken[] arr = jt.Where(p => p["address"].ToString() != bonusAddress).OrderByDescending(p => decimal.Parse(p["totalValue"].ToString(), NumberStyles.Float)).ToArray();
            JToken[] arr = jt.Select(p =>
            {
                JObject jo   = (JObject)p;
                string value = jo["totalValue"].ToString();
                value        = NumberDecimalHelper.formatDecimal(value);
                jo.Remove("totalValue");
                jo.Add("totalValue", value);
                return(jo);
            }).Where(p => p["address"].ToString() != bonusAddress).OrderByDescending(p => decimal.Parse(p["totalValue"].ToString(), NumberStyles.Float)).ToArray();
            long   count = arr.Count();
            int    num   = (pageNum - 1) * pageSize;
            JArray js    = new JArray();

            foreach (JObject obj in arr.Skip(num).Take(pageSize))
            {
                obj.Add("range", ++num);
                js.Add(obj);
            }
            //res = new JArray() { arr };
            return(new JArray()
            {
                { new JObject()
                  {
                      { "list", js }, { "count", count }
                  } }
            });
        }
示例#6
0
        public JArray getAuctingDomainList(int pageNum = 1, int pageSize = 10, bool sortByMaxPrice = false)
        {
            string findStr = MongoFieldHelper.toFilter(new string[] { AuctionState.STATE_CONFIRM, AuctionState.STATE_RANDOM }, "auctionState").ToString();
            string sortStr = null;

            if (sortByMaxPrice)
            {
                sortStr = new JObject()
                {
                    { "maxPrice", -1 }
                }.ToString();
            }
            else
            {
                sortStr = new JObject()
                {
                    { "startTime.blockindex", -1 }
                }.ToString();
            }
            string fieldStr = MongoFieldHelper.toReturn(new string[] { "fulldomain", "lastTime.txid", "maxBuyer", "maxPrice", "auctionState" }).ToString();
            JArray res      = mh.GetDataPagesWithField(notify_mongodbConnStr, notify_mongodbDatabase, auctionStateColl, fieldStr, pageSize, pageNum, sortStr, findStr);

            if (res == null || res.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            res = new JArray()
            {
                res.Select(p =>
                {
                    JObject jo   = (JObject)p;
                    string value = jo["maxPrice"].ToString();
                    value        = NumberDecimalHelper.formatDecimal(value);
                    jo.Remove("maxPrice");
                    jo.Add("maxPrice", value);
                    return(jo);
                }).ToArray()
            };
            long count = mh.GetDataCount(notify_mongodbConnStr, notify_mongodbDatabase, auctionStateColl, findStr);

            return(new JArray()
            {
                { new JObject()
                  {
                      { "list", res }, { "count", count }
                  } }
            });
        }
示例#7
0
        private decimal getProfit()
        {
            string filter = new JObject()
            {
                { "assetid", id_sgas }
            }.ToString();
            JArray rr = mh.GetData(bonusSgas_mongodbConnStr, bonusSgas_mongodbDatabase, bonusSgasCol, filter);

            if (rr != null && rr.Count > 0)
            {
                return(rr.Select(p => decimal.Parse(NumberDecimalHelper.formatDecimal(p["totalValue"].ToString()), NumberStyles.Float)).Sum());
            }
            return(0);
        }
示例#8
0
        public JArray getdomainAuctionInfo(string domain)
        {
            domain = domain.ToLower();
            string findstr = new JObject()
            {
                { "fulldomain", domain }
            }.ToString();
            string sortstr = new JObject()
            {
                { "startTime.blockindex", -1 }
            }.ToString();
            //string fieldstr = new JObject() { { "auctionState",1} }.ToString();
            //JArray res = mh.GetDataPagesWithField(mongodbConnStr, mongodbDatabase, auctionStateCol, fieldstr, 1, 1, sortstr, findstr);
            JArray res = mh.GetDataPages(mongodbConnStr, mongodbDatabase, auctionStateCol, sortstr, 1, 1, findstr);

            if (res == null || res.Count() == 0)
            {
                return(new JArray());
            }

            var jo = (JObject)res[0];

            if (jo["auctionState"].ToString() == "0401")
            {
                string owner = "";
                if (NNSfixedSellingService.hasNNfixedSelling(domain, long.Parse(res[0]["startTime"]["blockindex"].ToString()), out owner, out string price))
                {
                    jo.Remove("auctionState");
                    jo.Add("auctionState", "0901");
                }
                jo.Add("owner", owner);
            }
            string maxPrice = NumberDecimalHelper.formatDecimal(jo["maxPrice"].ToString());

            jo.Remove("maxPrice");
            jo.Add("maxPrice", maxPrice);

            return(new JArray()
            {
                jo
            });
        }
示例#9
0
        private JArray formatRes(JArray res)
        {
            return(new JArray()
            {
                res.Select(p => {
                    JObject jo = (JObject)p;
                    string joStr = jo.ToString();
                    if (joStr.Contains("maxPrice"))
                    {
                        string value = jo["maxPrice"].ToString();
                        value = NumberDecimalHelper.formatDecimal(value);
                        jo.Remove("maxPrice");
                        jo.Add("maxPrice", value);
                    }
                    if (joStr.Contains("addwholist") && joStr.Contains("totalValue"))
                    {
                        JArray ja = JArray.Parse(jo["addwholist"].ToString());
                        ja = new JArray()
                        {
                            ja.Select(pb => {
                                JObject job = (JObject)pb;
                                string vb = job["totalValue"].ToString();
                                vb = NumberDecimalHelper.formatDecimal(vb);
                                job.Remove("totalValue");
                                job.Add("totalValue", vb);

                                vb = job["curTotalValue"].ToString();
                                vb = NumberDecimalHelper.formatDecimal(vb);
                                job.Remove("curTotalValue");
                                job.Add("curTotalValue", vb);
                                return job;
                            }).ToArray()
                        };
                        jo.Remove("addwholist");
                        jo.Add("addwholist", ja);
                    }
                    return jo;
                }).ToArray()
            });
        }
示例#10
0
        public JArray getUsedDomainList(int pageNum = 1, int pageSize = 10)
        {
            string findStr = MongoFieldHelper.toFilter(new string[] { AuctionState.STATE_END }, "auctionState").ToString();
            string sortStr = new JObject()
            {
                { "maxPrice", -1 }
            }.ToString();
            string fieldStr = MongoFieldHelper.toReturn(new string[] { "fulldomain", "lastTime.txid", "maxBuyer", "maxPrice", "startTime.blocktime", "ttl" }).ToString();
            JArray res      = mh.GetDataPagesWithField(notify_mongodbConnStr, notify_mongodbDatabase, auctionStateColl, fieldStr, pageSize, pageNum, sortStr, findStr);

            if (res == null || res.Count() == 0)
            {
                return(new JArray()
                {
                });
            }
            JArray ja  = new JArray();
            int    num = (pageNum - 1) * pageSize;

            foreach (JObject obj in res)
            {
                obj.Add("range", ++num);
                string value = obj["maxPrice"].ToString();
                value = NumberDecimalHelper.formatDecimal(value);
                obj.Remove("maxPrice");
                obj.Add("maxPrice", value);
                ja.Add(obj);
            }
            long count = mh.GetDataCount(notify_mongodbConnStr, notify_mongodbDatabase, auctionStateColl, findStr);

            return(new JArray()
            {
                { new JObject()
                  {
                      { "list", format(ja) }, { "count", count }
                  } }
            });
        }
示例#11
0
        public JArray getTransByAddress_new(string address, int pageSize, int pageNum)
        {
            JObject filter = new JObject()
            {
                { "addr", address }
            };
            JObject sort = new JObject()
            {
                { "blockindex", -1 }, { "txid", -1 }
            };
            JArray result = mh.GetDataPages(mongodbConnStr_new, mongodbDatabase_new, "address_tx", sort.ToString(), pageSize, pageNum, filter.ToString());

            for (var i = 0; i < result.Count; i++)
            {
                result[i]["detail"]["value"] = NumberDecimalHelper.formatDecimal(result[i]["detail"]["value"].ToString());
            }
            if (result == null || result.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            return(result);
        }
示例#12
0
        private JArray format(JArray res)
        {
            if (res == null || res.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            return(new JArray()
            {
                res.Select(p => {
                    JObject jo = (JObject)p;


                    string fulldoamin = p["fulldomain"].ToString();
                    TimeSetter timeSetter = TimeConst.getTimeSetter(fulldoamin.Substring(fulldoamin.LastIndexOf(".")));

                    if (fulldoamin.EndsWith(".test"))
                    {
                        long starttime = long.Parse(jo["startTime"]["blocktime"].ToString());
                        jo.Remove("ttl");
                        jo.Add("ttl", starttime + timeSetter.ONE_YEAR_SECONDS);
                    }


                    long st = long.Parse(jo["startTime"]["blocktime"].ToString());
                    long ed = long.Parse(jo["endTime"]["blocktime"].ToString());
                    if (ed > 0)
                    {
                        jo.Remove("lastTime");
                        return jo;
                    }
                    string auctionState = p["auctionState"].ToString();
                    long expireSeconds = 0;
                    if (auctionState == "0201")
                    {
                        expireSeconds = st + timeSetter.THREE_DAY_SECONDS;
                    }
                    else if (auctionState == "0301")
                    {
                        expireSeconds = st + timeSetter.FIVE_DAY_SECONDS;
                    }
                    else if (auctionState == "0401")
                    {
                        long lt = long.Parse(jo["lastTime"]["blocktime"].ToString());
                        if (st + timeSetter.TWO_DAY_SECONDS >= lt)
                        {
                            expireSeconds = st + timeSetter.THREE_DAY_SECONDS;
                        }
                        else
                        {
                            expireSeconds = st + timeSetter.FIVE_DAY_SECONDS;
                        }
                    }
                    if (expireSeconds > 0)
                    {
                        // 预计结束时间
                        JObject ep = (JObject)jo["endTime"];
                        long blocktime = long.Parse(ep["blocktime"].ToString());
                        long endBlockTime = blocktime + expireSeconds;
                        ep.Remove("blocktime");
                        jo.Remove("endTime");
                        ep.Add("blocktime", endBlockTime);
                        jo.Add("endTime", ep);
                        //
                        jo.Remove("lastTime");
                    }
                    string value = jo["maxPrice"].ToString();
                    value = NumberDecimalHelper.formatDecimal(value);
                    jo.Remove("maxPrice");
                    jo.Add("maxPrice", value);
                    return jo;
                })
            });
        }
示例#13
0
        public JArray getBonusHistByAddress(string address, int pageNum = 1, int pageSize = 10)
        {
            List <String> list = mh.listCollection(Bonus_mongodbConnStr, Bonus_mongodbDatabase);

            if (list == null && list.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            string findstr = new JObject()
            {
                { "addr", address }
            }.ToString();

            JToken[] res = list.Where(p => p.StartsWith("Snapshot_NNC_") && !p.Contains("_test")).Select(p =>
            {
                string coll      = p;
                JArray addrbonus = mh.GetData(Bonus_mongodbConnStr, Bonus_mongodbDatabase, coll, findstr);
                if (addrbonus == null || addrbonus.Count == 0)
                {
                    return(null);
                }
                JObject bonus = (JObject)addrbonus[0];
                //if(bonus["txid"] == null || bonus["txid"].ToString() == "")
                //{
                //    return null;
                //}
                return(new JObject()
                {
                    { "address", bonus["addr"] },
                    { "balance", NumberDecimalHelper.formatDecimal(bonus["balance"].ToString()) },
                    { "addrBonus", NumberDecimalHelper.formatDecimal(bonus["send"].ToString()) },
                    { "height", bonus["height"] },
                });
            }).Where(p => p != null).ToArray();
            if (res == null || res.Count() == 0)
            {
                return(new JArray()
                {
                });
            }


            // 分红总量快照
            long[] heightArr         = res.Select(p => long.Parse(p["height"].ToString())).Distinct().ToArray();
            string totalBonusFindstr = MongoFieldHelper.toFilter(heightArr, "height").ToString();
            JArray totalBonusRes     = mh.GetData(Bonus_mongodbConnStr, Bonus_mongodbDatabase, "TotalSnapShot", totalBonusFindstr);
            Dictionary <long, string> totalBonusDict = null;

            if (totalBonusRes != null && totalBonusRes.Count > 0)
            {
                totalBonusDict = totalBonusRes.ToDictionary(k => long.Parse(k["height"].ToString()), v => NumberDecimalHelper.formatDecimal(v["totalValue"].ToString()));
            }

            // 区块时间
            string blocktimeFindstr  = MongoFieldHelper.toFilter(heightArr, "index").ToString();
            string blocktimeFieldstr = new JObject()
            {
                { "index", 1 }, { "time", 1 }
            }.ToString();
            JArray blocktimeRes = mh.GetDataWithField(Block_mongodbConnStr, Block_mongodbDatabase, "block", blocktimeFieldstr, blocktimeFindstr);
            Dictionary <long, long> blocktimeDict = null;

            if (blocktimeRes != null && blocktimeRes.Count > 0)
            {
                blocktimeDict = blocktimeRes.ToDictionary(k => long.Parse(k["index"].ToString()), v => long.Parse(v["time"].ToString()));
            }
            res = res.Select(p =>
            {
                long height = long.Parse(p["height"].ToString());
                if (totalBonusDict != null && totalBonusDict.ContainsKey(height))
                {
                    p["totalValue"] = totalBonusDict.GetValueOrDefault(height);
                }
                else
                {
                    p["totalValue"] = 0;
                }

                if (blocktimeDict != null && blocktimeDict.ContainsKey(height))
                {
                    p["blocktime"] = blocktimeDict.GetValueOrDefault(height);
                }
                else
                {
                    p["blocktime"] = 0;
                }
                JObject jo = (JObject)p;
                jo.Remove("height");
                return(jo);
            }).OrderByDescending(p => long.Parse(p["blocktime"].ToString())).ToArray();

            return(new JArray()
            {
                new JObject()
                {
                    { "count", res.Count() }, { "list", new JArray()
                                                {
                                                    res.Skip(pageSize * (pageNum - 1)).Take(pageSize)
                                                } }
                }
            });
        }
示例#14
0
        //获取某个地址的已得的分红记录
        public JArray getBonusByAddress(string address, int pageNum = 1, int pageSize = 10)
        {
            JObject queryFilter = new JObject()
            {
                { "addr", address }
            };
            JArray jArray = mh.GetDataPages(Bonus_mongodbConnStr, Bonus_mongodbDatabase, BonusCol, "{height:-1}", pageSize, pageNum, queryFilter.ToString());

            if (jArray == null || jArray.Count() == 0)
            {
                return(new JArray()
                {
                });
            }
            //获取总数
            var count = mh.GetDataCount(Bonus_mongodbConnStr, Bonus_mongodbDatabase, BonusCol, queryFilter.ToString());

            // 区块时间
            long[] heightArr         = jArray.Select(p => long.Parse(p["height"].ToString())).Distinct().ToArray();
            string blocktimeFindstr  = MongoFieldHelper.toFilter(heightArr, "index").ToString();
            string blocktimeFieldstr = new JObject()
            {
                { "index", 1 }, { "time", 1 }
            }.ToString();
            JArray blocktimeRes = mh.GetDataWithField(Block_mongodbConnStr, Block_mongodbDatabase, "block", blocktimeFieldstr, blocktimeFindstr);
            Dictionary <long, long> blocktimeDict = null;

            if (blocktimeRes != null && blocktimeRes.Count > 0)
            {
                blocktimeDict = blocktimeRes.ToDictionary(k => long.Parse(k["index"].ToString()), v => long.Parse(v["time"].ToString()));
            }
            return(new JArray()
            {
                new JObject()
                {
                    { "count", count }, { "list", new JArray()
                                          {
                                              jArray.Select(p =>
                            {
                                long height = long.Parse(p["height"].ToString());


                                if (blocktimeDict != null && blocktimeDict.ContainsKey(height))
                                {
                                    p["blocktime"] = blocktimeDict.GetValueOrDefault(height);
                                }
                                else
                                {
                                    p["blocktime"] = 0;
                                }
                                p["balance"] = NumberDecimalHelper.formatDecimal(p["balance"].ToString());
                                p["send"] = NumberDecimalHelper.formatDecimal(p["send"].ToString());
                                p["totalSend"] = NumberDecimalHelper.formatDecimal(p["totalSend"].ToString());
                                JObject jo = (JObject)p;
                                jo.Remove("height");
                                return jo;
                            }).OrderByDescending(p => long.Parse(p["blocktime"].ToString())).ToArray()
                                          } }
                }
            });
        }
示例#15
0
        public JArray getContractCallTx(string hash, int pageNum = 1, int pageSize = 10)
        {
            if (mh == null)
            {
                return new JArray {
                }
            }
            ;
            // txid + time + from + to + value(1neo,1gas) + fee

            var hashArr = getContractHashArr(hash);
            var findStr = MongoFieldHelper.toFilter(hashArr, "contractHash").ToString();
            //string findStr = new JObject { { "contractHash", hash } }.ToString();
            string sortStr = new JObject {
                { "time", -1 }
            }.ToString();
            var queryRes = mh.GetDataPages(Analysis_mongodbConnStr, Analysis_mongodbDatabase, contractCallInfoCol, sortStr, pageSize, pageNum, findStr);;

            if (queryRes == null || queryRes.Count == 0)
            {
                return new JArray {
                }
            }
            ;

            var res = queryRes.Select(p => {
                var neoAmount = NumberDecimalHelper.formatDecimal(p["neoAmount"].ToString());
                var gasAmount = NumberDecimalHelper.formatDecimal(p["gasAmount"].ToString());
                var value     = "";
                if (neoAmount != "0")
                {
                    value += neoAmount + " NEO";
                }
                if (gasAmount != "0")
                {
                    if (value != "")
                    {
                        value += ", ";
                    }
                    value += gasAmount + " GAS";
                }
                if (value == "")
                {
                    value = "0";
                }

                return(new JObject {
                    { "txid", p["txid"] },
                    { "time", p["time"] },
                    { "from", p["address"] },
                    { "to", "当前合约" },
                    { "value", value },
                    { "net_fee", NumberDecimalHelper.formatDecimal(p["net_fee"].ToString()) + " GAS" }
                });
            }).ToArray();

            var count = mh.GetDataCount(Analysis_mongodbConnStr, Analysis_mongodbDatabase, contractCallInfoCol, findStr);

            return(new JArray {
                new JObject {
                    { "count", count },
                    { "list", new JArray {
                          res
                      } }
                }
            });
        }
示例#16
0
        private JArray format(JArray res, bool isSearch = false)
        {
            if (res == null || res.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            long nowtime = TimeHelper.GetTimeStamp();

            return(new JArray()
            {
                res.Select(p => {
                    JObject jo = (JObject)p;

                    // 格式转换
                    string value = jo["maxPrice"].ToString();
                    value = NumberDecimalHelper.formatDecimal(value);
                    jo.Remove("maxPrice");
                    jo.Add("maxPrice", value);

                    // 获取ttl
                    string fulldoamin = p["fulldomain"].ToString();
                    long ttl = 0;
                    if (isSearch)
                    {
                        var rr = getDomainInfo(fulldoamin);
                        if (rr != null && rr.Count > 0)
                        {
                            if (p["auctionState"].ToString() == "0401" || p["auctionState"].ToString() == "0601")
                            {
                                JObject resJo = new JObject()
                                {
                                    { "auctionId", p["auctionId"] },
                                    { "fulldomain", p["fulldomain"] },
                                    { "owner", rr[0]["owner"] },
                                    { "ttl", rr[0]["TTL"] }
                                };
                                string price;
                                if (hasNNfixedSelling(p["fulldomain"].ToString(), long.Parse(p["startTime"]["blockindex"].ToString()), out price))
                                {
                                    resJo.Remove("auctionState");
                                    resJo.Add("auctionState", "0901");
                                    resJo.Add("price", price);
                                    return resJo;
                                }
                                resJo.Add("price", "0");
                                return resJo;

                                /*
                                 * return new JObject() {
                                 *  {"auctionId", p["auctionId"] },
                                 *  {"fulldomain", p["fulldomain"] },
                                 *  {"owner", rr[0]["owner"] },
                                 *  {"ttl", rr[0]["TTL"] }
                                 * };
                                 */
                            }
                            ttl = long.Parse(rr[0]["TTL"].ToString());
                            jo.Remove("ttl");
                            jo.Add("ttl", ttl);
                            if (ttl > nowtime)
                            {
                                // 过期域名续约后状态需更新为0401
                                jo.Remove("auctionState");
                                jo.Add("auctionState", "0401");
                            }
                        }
                    }


                    // 触发结束
                    long now = TimeHelper.GetTimeStamp();
                    long st = long.Parse(jo["startTime"]["blocktime"].ToString());
                    long ed = long.Parse(jo["endTime"]["blocktime"].ToString());
                    if (ed > 0)
                    {
                        jo.Remove("lastTime");
                        if (now >= ed && now <= ttl)
                        {
                            jo.Remove("auctionState");
                            jo.Add("auctionState", "0401");
                        }
                        return jo;
                    }

                    // 计算预计结束时间
                    TimeSetter timeSetter = TimeConst.getTimeSetter(fulldoamin.Substring(fulldoamin.LastIndexOf(".")));
                    string auctionState = p["auctionState"].ToString();
                    long expireSeconds = 0;
                    if (auctionState == "0201")
                    {
                        expireSeconds = st + timeSetter.THREE_DAY_SECONDS;
                    }
                    else if (auctionState == "0301")
                    {
                        expireSeconds = st + timeSetter.FIVE_DAY_SECONDS;
                    }
                    else if (auctionState == "0401")
                    {
                        long lt = long.Parse(jo["lastTime"]["blocktime"].ToString());
                        if (st + timeSetter.TWO_DAY_SECONDS >= lt)
                        {
                            expireSeconds = st + timeSetter.THREE_DAY_SECONDS;
                        }
                        else
                        {
                            expireSeconds = st + timeSetter.FIVE_DAY_SECONDS;
                        }
                    }
                    if (expireSeconds > 0)
                    {
                        JObject ep = (JObject)jo["endTime"];
                        long blocktime = long.Parse(ep["blocktime"].ToString());
                        long endBlockTime = blocktime + expireSeconds;
                        ep.Remove("blocktime");
                        jo.Remove("endTime");
                        ep.Add("blocktime", endBlockTime);
                        jo.Add("endTime", ep);
                        //
                        jo.Remove("lastTime");
                    }
                    if (now >= expireSeconds && now <= ttl && auctionState == "0601")
                    {
                        jo.Remove("auctionState");
                        jo.Add("auctionState", "0401");
                    }

                    return jo;
                })
            });
        }
示例#17
0
        public JArray getNNSFixedSellingList(string orderField = "price" /* price/time */, string orderType = "high" /* high/low */, int pageNum = 1, int pageSize = 10, string displayNameId = "nid1" /* all/NNSfixedSellingLaunched/NNSfixedSellingBuy/NNSfixedSellingDiscontinued */)
        {
            long nowtime = TimeHelper.GetTimeStamp();
            //string findStr = new JObject() { { "displayName", "NNSfixedSellingLaunched" }, { "ttl", new JObject() { { "$gte", nowtime } } } }.ToString();
            JObject findJo = new JObject()
            {
                { "ttl", new JObject()
                  {
                      { "$gte", nowtime }
                  } }
            };

            if (parseDisplayNameId(displayNameId, out string displayName))
            {
                findJo.Add("displayName", displayName);
            }
            string findStr = findJo.ToString();

            long count = mh.GetDataCount(notify_mongodbConnStr, notify_mongodbDatabase, "nnsFixedSellingState", findStr);

            if (count == 0)
            {
                return new JArray {
                }
            }
            ;


            // domain + price + launchtime + owner + ttl
            string fieldStr = MongoFieldHelper.toReturn(new string[] { "fullDomain", "price", "launchTime", "owner", "ttl" }).ToString();
            string sortStr  = new JObject()
            {
                { "blockindex", -1 }
            }.ToString();

            if (orderField == "time")
            {
                // default
            }
            else if (orderField == "price")
            {
                sortStr = new JObject()
                {
                    { "price", orderType == "high" ? -1 : 1 }
                }.ToString();
            }

            var query = mh.GetDataPagesWithField(notify_mongodbConnStr, notify_mongodbDatabase, "nnsFixedSellingState", fieldStr, pageSize, pageNum, sortStr, findStr);
            var res   = query.Select(p =>
            {
                JObject jo   = (JObject)p;
                string price = NumberDecimalHelper.formatDecimal(jo["price"].ToString());
                jo.Remove("price");
                jo.Add("price", price);
                return(jo);
            }).ToArray();

            return(new JArray()
            {
                { new JObject()
                  {
                      { "count", count },
                      { "list", new JArray {
                                              res
                                          } }
                  } }
            });
        }