Exemplo n.º 1
0
        private void replaceAuctionTx(AuctionTx at, string auctionId)
        {
            string findstr = new JObject()
            {
                { "auctionId", auctionId }
            }.ToString();

            mh.ReplaceData(localDbConnInfo.connStr, localDbConnInfo.connDB, auctionStateColl, at, findstr);
        }
Exemplo n.º 2
0
        private void updateR2(JToken[] rr, long blockindex, Dictionary <string, long> blockindexDict)
        {// changeAuctionState
            foreach (JToken jt in rr)
            {
                string auctionId  = jt["auctionId"].ToString();
                string domain     = jt["domain"].ToString();
                string parenthash = jt["parenthash"].ToString();
                //string domainTTL = jt["domainTTL"].ToString();
                long    startBlockSelling = long.Parse(jt["startBlockSelling"].ToString());
                long    endBlock          = long.Parse(jt["endBlock"].ToString());
                decimal maxPrice          = decimal.Parse(jt["maxPrice"].ToString());
                string  maxBuyer          = jt["maxBuyer"].ToString();
                long    lastBlock         = long.Parse(jt["lastBlock"].ToString());
                string  txid = jt["txid"].ToString();

                AuctionTx at = queryAuctionTx(auctionId);
                if (at == null)
                {
                    // 没有竞拍信息,报错停止处理
                    error(auctionId); return;
                }
                if (format(at.maxPrice) > maxPrice)
                {
                    continue;
                }
                at.domain     = domain;
                at.parenthash = parenthash;
                //at.domainTTL = domainTTL;
                if (endBlock != 0)
                {
                    at.endTime = new AuctionTime
                    {
                        blockindex = endBlock,
                        blocktime  = blockindexDict.GetValueOrDefault(endBlock + ""),
                        txid       = txid
                    };
                }
                if (at.startTime == null || at.startTime.blockindex == 0)
                {
                    at.startTime = new AuctionTime
                    {
                        blockindex = startBlockSelling,
                        blocktime  = blockindexDict.GetValueOrDefault(startBlockSelling + ""),
                        txid       = txid
                    };
                }
                if (at.ttl == 0)
                {
                    at.ttl = at.startTime.blocktime + TimeConst.getTimeSetter(at.fulldomain.Substring(at.fulldomain.IndexOf("."))).ONE_YEAR_SECONDS;
                }

                at.maxPrice = format(maxPrice);
                at.maxBuyer = maxBuyer;
                replaceAuctionTx(at, auctionId);
            }
        }
Exemplo n.º 3
0
 private void updateR5(JToken[] rr, long blockindex, long rblockindex, long rblocktime)
 {// collectDomain
     foreach (JToken jt in rr)
     {
         string    auctionId  = jt["auctionId"].ToString();
         string    domain     = jt["domain"].ToString();
         string    parenthash = jt["parenthash"].ToString();
         string    who        = jt["who"].ToString();
         string    txid       = jt["txid"].ToString();
         AuctionTx at         = queryAuctionTx(auctionId);
         if (at == null)
         {
             // 没有竞拍信息,报错停止处理
             error(auctionId); return;
         }
         if (at.addwholist == null || at.addwholist.Count == 0)
         {
             at.addwholist = new List <AuctionAddWho>();
         }
         AuctionAddWho   addwho    = null;
         AuctionAddWho[] addwhoArr = at.addwholist.Where(p => p.address == who).ToArray();
         if (addwhoArr != null && addwhoArr.Count() > 0)
         {
             addwho = addwhoArr[0];
             at.addwholist.Remove(addwho);
         }
         else
         {
             addwho         = new AuctionAddWho();
             addwho.address = who;
         }
         // 领取域名时间
         addwho.getdomainTime = new AuctionTime
         {
             blockindex = rblockindex,
             blocktime  = rblocktime,
             txid       = txid
         };
         at.addwholist.Add(addwho);
         replaceAuctionTx(at, auctionId);
     }
 }
Exemplo n.º 4
0
 private void updateR4(JToken[] rr, long blockindex, long rblockindex, long rblocktime)
 {//raiseEndsAuction
     foreach (JToken jt in rr)
     {
         string    auctionId = jt["auctionId"].ToString();
         string    who       = jt["who"].ToString();
         string    txid      = jt["txid"].ToString();
         AuctionTx at        = queryAuctionTx(auctionId);
         if (at == null)
         {
             // 没有竞拍信息,报错停止处理
             error(auctionId); return;
         }
         at.endAddress = who;
         at.endTime    = new AuctionTime
         {
             blockindex = rblockindex,
             blocktime  = rblocktime,
             txid       = txid
         };
         replaceAuctionTx(at, auctionId);
     }
 }
Exemplo n.º 5
0
        public JArray getAuctionInfoTx(string auctionId, int pageNum = 1, int pageSize = 10)
        {
            // 竞拍信息:
            // txid + 类型(开标+加价+结束+领取+取回+) + 地址 + 金额 + 时间
            string findStr = new JObject()
            {
                { "auctionId", auctionId }
            }.ToString();
            List <AuctionTx> txList = mh.GetData <AuctionTx>(Notify_mongodbConnStr, Notify_mongodbDatabase, auctionStateColl, findStr);

            if (txList == null || txList.Count == 0)
            {
                return(new JArray()
                {
                });
            }
            AuctionTx tx = txList[0];

            //txid + 类型(开标+加价+结束+领取+取回+) + 地址 + 金额 + 时间
            JArray  arr = new JArray();
            JObject jo  = new JObject()
            {
                { "txid", tx.startTime.txid },
                { "type", AuctionStatus.AuctionStatus_Start },
                { "address", tx.startAddress },
                { "amount", 0 },
                { "time", tx.startTime.blocktime }
            };

            arr.Add(jo);
            foreach (AuctionAddWho addwho in tx.addwholist)
            {
                if (bonusAddress == addwho.address)
                {
                    continue;
                }

                foreach (AuctionAddPrice addprice in addwho.addpricelist)
                {
                    if (addprice.value <= 0)
                    {
                        continue;
                    }
                    jo = new JObject();
                    jo.Add("txid", addprice.time.txid);
                    jo.Add("type", AuctionStatus.AuctionStatus_AddPrice);
                    jo.Add("address", addwho.address);
                    jo.Add("amount", addprice.value);
                    jo.Add("time", addprice.time.blocktime);
                    arr.Add(jo);
                }
                if (addwho.accountTime != null && addwho.accountTime.blockindex != 0)
                {
                    jo = new JObject();
                    jo.Add("txid", addwho.accountTime.txid);
                    jo.Add("type", AuctionStatus.AuctionStatus_Account);
                    jo.Add("address", addwho.address);
                    jo.Add("amount", getEndValue(addwho.addpricelist));
                    jo.Add("time", addwho.accountTime.blocktime);
                    arr.Add(jo);
                }
                if (addwho.getdomainTime != null && addwho.getdomainTime.blockindex != 0)
                {
                    jo = new JObject();
                    jo.Add("txid", addwho.getdomainTime.txid);
                    jo.Add("type", AuctionStatus.AuctionStatus_GetDomain);
                    jo.Add("address", addwho.address);
                    jo.Add("amount", getEndValue(addwho.addpricelist));
                    jo.Add("time", addwho.getdomainTime.blocktime);
                    arr.Add(jo);
                }
            }
            if (tx.endTime != null && tx.endTime.blockindex != 0)
            {
                jo = new JObject()
                {
                    { "txid", tx.endTime.txid },
                    { "type", AuctionStatus.AuctionStatus_End },
                    { "address", tx.endAddress },
                    { "amount", 0 },
                    { "time", tx.endTime.blocktime }
                };
                arr.Add(jo);
            }
            JToken[] jt    = arr.OrderByDescending(p => long.Parse(p["time"].ToString())).ToArray();
            int      count = jt.Count();
            JArray   res   = new JArray()
            {
                jt.Skip(pageSize * (pageNum - 1)).Take(pageSize).ToArray()
            };

            return(new JArray()
            {
                new JObject()
                {
                    { "count", count }, { "list", res }
                }
            });
        }
Exemplo n.º 6
0
 private void insertAuctionTx(AuctionTx at)
 {
     mh.PutData(localDbConnInfo.connStr, localDbConnInfo.connDB, auctionStateColl, at);
 }
Exemplo n.º 7
0
        private void updateR3_BidSettlement(JToken[] rr, long blockindex, long rblockindex, long rblocktime)
        {
            foreach (var jt in rr)
            {
                string    who       = jt["who"].ToString();
                decimal   value     = decimal.Parse(jt["value"].ToString());
                string    auctionId = jt["auctionId"].ToString();
                string    txid      = jt["txid"].ToString();
                AuctionTx at        = queryAuctionTx(auctionId);
                if (at == null)
                {
                    // 没有竞拍信息,报错停止处理
                    error(auctionId); return;
                }
                if (at.addwholist == null)
                {
                    at.addwholist = new List <AuctionAddWho>();
                }
                AuctionAddWho   addwho    = null;
                AuctionAddWho[] addwhoArr = at.addwholist.Where(p => p.address == who).ToArray();
                if (addwhoArr != null && addwhoArr.Count() > 0)
                {
                    addwho = addwhoArr[0];
                    at.addwholist.Remove(addwho);
                }
                else
                {
                    addwho               = new AuctionAddWho();
                    addwho.address       = who;
                    addwho.totalValue    = format(0);
                    addwho.curTotalValue = format(0);
                }

                //
                bool hasExist = addwho.addpricelist != null && addwho.addpricelist.Any(p => p != null && p.time.txid == txid && p.value == value);
                if (hasExist)
                {
                    continue;
                }

                // 结算时间(领取域名/取回CGas)
                addwho.accountTime = new AuctionTime
                {
                    blockindex = rblockindex,
                    blocktime  = rblocktime,
                    txid       = txid
                };
                // 最后操作时间(包括最后出价时间和领取域名/取回Gas时间)
                at.lastTime = new AuctionTime
                {
                    blockindex = rblockindex,
                    blocktime  = rblocktime,
                    txid       = txid
                };

                // 加价列表
                if (addwho.addpricelist == null)
                {
                    addwho.addpricelist = new List <AuctionAddPrice>();
                }
                addwho.addpricelist.Add(new AuctionAddPrice
                {
                    time = new AuctionTime
                    {
                        blockindex = rblockindex,
                        blocktime  = rblocktime,
                        txid       = txid
                    },
                    value = format(value * -1),
                    isEnd = "1" // 表示结算
                });
                at.addwholist.Add(addwho);
                replaceAuctionTx(at, auctionId);
            }
        }
Exemplo n.º 8
0
        private void updateR3(JToken[] rr, long blockindex, Dictionary <string, long> blockindexDict)
        {// assetManagement
            foreach (JToken jt in rr)
            {
                //string auctionId = jt["auctionId"].ToString();
                string from = jt["from"].ToString();
                string to   = jt["to"].ToString();

                decimal value = decimal.Parse(jt["value"].ToString());
                string  txid  = jt["txid"].ToString();
                if (txid == "0xc97606fd0db030369a9848ef7c19543f66aad752bb70984b94f165c69b6301ca")
                {
                    //throw new Exception("TTT");
                }

                bool   auctionidIsTo = true;
                string auctionId     = null;
                string address       = null;
                if (from.Length > to.Length)
                {
                    auctionidIsTo = false;
                    auctionId     = "0x" + from.hexstringReverse();
                    address       = to;
                }
                else
                {
                    auctionidIsTo = true;
                    auctionId     = "0x" + to.hexstringReverse();
                    address       = from;
                }
                // 如果to为分红地址
                if (!auctionidIsTo && to == bonusAddress)
                {
                    //string data = new JObject() { { "from", from }, { "to", to }, { "value", value } }.ToString();
                    //mh.PutData(localDbConnInfo.connStr, localDbConnInfo.connDB, bonusAddressColl, data);
                    //return;
                }
                AuctionTx at = queryAuctionTx(auctionId);
                if (at == null)
                {
                    // 没有竞拍信息,报错停止处理
                    error(auctionId); return;
                }
                if (at.addwholist == null)
                {
                    at.addwholist = new List <AuctionAddWho>();
                }
                AuctionAddWho   addwho    = null;
                AuctionAddWho[] addwhoArr = at.addwholist.Where(p => p.address == address).ToArray();
                if (addwhoArr != null && addwhoArr.Count() > 0)
                {
                    addwho = addwhoArr[0];
                    at.addwholist.Remove(addwho);
                    //addwho.totalValue = auctionidIsTo ? addwho.totalValue + value : addwho.totalValue - value;
                    if (addwho.addpricelist != null && addwho.addpricelist.Any(p => p != null && p.time.txid == txid && format(p.value) == value))
                    {
                        continue;
                    }
                }
                else
                {
                    addwho               = new AuctionAddWho();
                    addwho.address       = address;
                    addwho.totalValue    = format(0);
                    addwho.curTotalValue = format(0);
                    //addwho.totalValue = value;
                }
                bool isPositiveFlag = auctionidIsTo || (!auctionidIsTo && address == bonusAddress);
                if (isPositiveFlag)
                {
                    addwho.totalValue    = format(format(addwho.totalValue) + value);
                    addwho.curTotalValue = format(format(addwho.curTotalValue) + value);
                }
                if (auctionidIsTo)
                {
                    addwho.lastTime = new AuctionTime
                    {
                        blockindex = blockindex,
                        blocktime  = blockindexDict.GetValueOrDefault(blockindex + ""),
                        txid       = txid
                    };
                    // 最后操作时间(包括最后出价时间和领取域名/取回Gas时间)
                    at.lastTime = new AuctionTime
                    {
                        blockindex = blockindex,
                        blocktime  = blockindex == 0 ? 0 : blockindexDict.GetValueOrDefault(blockindex + ""),
                        txid       = blockindex == 0 ? "" : txid
                    };
                }
                else
                {
                    if (bonusAddress != address /*&& value > 0*/)
                    {
                        addwho.accountTime = new AuctionTime
                        {
                            blockindex = blockindex,
                            blocktime  = blockindexDict.GetValueOrDefault(blockindex + ""),
                            txid       = txid
                        };
                    }
                }

                // 正在处理高度累计加价:待讨论
                // totalValue = curTotalValue
                // 开始:totalValue -= curTotalValue, curTotalValue = 0
                // 加价:totalValue += value        , curTotalValue += value
                // 完成:curTotalValue = 0, 更新已处理高度

                // 加价列表
                if (addwho.addpricelist == null)
                {
                    addwho.addpricelist = new List <AuctionAddPrice>();
                }
                bool hasExist = addwho.addpricelist.Any(p => p != null && p.time.txid == txid && p.value == value);
                if (!hasExist)
                {
                    addwho.addpricelist.Add(new AuctionAddPrice
                    {
                        time = new AuctionTime
                        {
                            blockindex = blockindex,
                            blocktime  = blockindexDict.GetValueOrDefault(blockindex + ""),
                            txid       = txid
                        },
                        value = isPositiveFlag ? format(value) : format(value * -1),
                        isEnd = isPositiveFlag ? "0" : "1"
                    });
                }
                at.addwholist.Add(addwho);
                replaceAuctionTx(at, auctionId);
            }
        }
Exemplo n.º 9
0
        private void updateR1(JToken[] rr, long blockindex /*tx出块时间*/, long rblockindex /*业务判断时间*/, long rblocktime)
        {// startAuction
            // 哈希域名列表(父域名-父哈希)
            string[] phArr = rr.Select(item => item["parenthash"].ToString()).Distinct().Where(pItem => pItem != "").ToArray();
            Dictionary <string, string> phDict = getDomainByHash(phArr);

            foreach (JToken jt in rr)
            {
                string    auctionId  = jt["auctionId"].ToString();
                string    domain     = jt["domain"].ToString();
                string    parenthash = jt["parenthash"].ToString();
                string    who        = jt["who"].ToString();
                string    txid       = jt["txid"].ToString(); // 参数blockindex为该txid出块时间
                AuctionTx at         = queryAuctionTx(auctionId);
                if (at == null)
                {
                    at = new AuctionTx()
                    {
                        auctionId    = auctionId,
                        domain       = domain,
                        parenthash   = parenthash,
                        fulldomain   = domain + "." + phDict.GetValueOrDefault(parenthash),
                        startAddress = who,

                        /*
                         * startTime = new AuctionTime
                         * {
                         *  blockindex = rblockindex,
                         *  blocktime = rblocktime,
                         *  txid = txid
                         * },*/
                        endTime = new AuctionTime
                        {
                            blockindex = 0,
                            blocktime  = 0,
                            txid       = ""
                        },
                        auctionState = AuctionState.STATE_CONFIRM,
                        maxPrice     = format(0),
                        //ttl = time + TimeConst.getTimeSetter("." + phDict.GetValueOrDefault(parenthash)).ONE_DAY_SECONDS,
                        ttl = 0,

                        // 最后操作时间(包括最后出价时间和领取域名/取回Gas时间)
                        lastTime = new AuctionTime
                        {
                            blockindex = rblockindex,
                            blocktime  = rblocktime,
                            txid       = txid
                        }
                    };
                    insertAuctionTx(at);
                }
                else
                {
                    // 本无需处理,但为了后面数据重跑,新增如下更新
                    at.domain       = domain;
                    at.parenthash   = parenthash;
                    at.fulldomain   = domain + "." + phDict.GetValueOrDefault(parenthash);
                    at.startAddress = who;

                    /*
                     * at.startTime = new AuctionTime
                     * {
                     *  blockindex = rblockindex,
                     *  blocktime = rblocktime,
                     *  txid = txid
                     * };*/
                    at.endTime = new AuctionTime
                    {
                        blockindex = 0,
                        blocktime  = 0,
                        txid       = ""
                    };
                    at.auctionState = AuctionState.STATE_CONFIRM;
                    at.maxPrice     = format(0);
                    //at.ttl = time + TimeConst.getTimeSetter("." + phDict.GetValueOrDefault(parenthash)).ONE_YEAR_SECONDS;
                    at.ttl = 0;
                    replaceAuctionTx(at, auctionId);
                }
            }
        }