private void handleOnAuctionDiscontinued(List <JToken> rr, long blockindex) { rr.ForEach(p => { string findStr = new JObject() { { "orderid", p["auctionid"] } }.ToString(); mh.DeleteData(localConn.connStr, localConn.connDB, dexDomainSellStateCol, findStr); }); }
private void process() { // updateState(); // 获取远程已同步高度 long remoteHeight = getRemoteHeight(); // 获取本地已处理高度 long localHeight = getLocalHeight(); // if (remoteHeight <= localHeight) { log(localHeight, remoteHeight); return; } for (long index = localHeight; index <= remoteHeight; index += batchSize) { long nextIndex = index + batchSize; long endIndex = nextIndex < remoteHeight ? nextIndex : remoteHeight; // 待处理数据 //string findstr = new JObject() { {"addr", cgasAddress },{ "createHeight", new JObject() { { "$gt", index }, { "$lte", endIndex } } } }.ToString(); //string fieldstr = new JObject() { { "state", 0 } }.ToString(); string findstr = new JObject() { { "blockindex", new JObject() { { "$gt", index }, { "$lte", endIndex } } }, { "type", new JObject() { { "$ne", "MinerTransaction" } } } }.ToString(); string fieldstr = new JObject() { { "vin", 1 }, { "vout", 1 }, { "blockindex", 1 }, { "txid", 1 } }.ToString(); JArray queryRes = mh.GetDataWithField(remoteConn.connStr, remoteConn.connDB, utxoCol, fieldstr, findstr); if (queryRes == null || queryRes.Count == 0) { updateRecord(endIndex); log(endIndex, remoteHeight); continue; } //long[] blockindexArr = queryRes.Select(p => long.Parse(p["createHeight"].ToString())).Distinct().ToArray(); long[] blockindexArr = queryRes.Select(p => long.Parse(p["blockindex"].ToString())).Distinct().OrderBy(p => p).ToArray(); foreach (long blockindex in blockindexArr) { //JToken[] jtArr = queryRes.Where(p => long.Parse(p["createHeight"].ToString()) == blockindex).ToArray(); JToken[] jtArr = queryRes.Where(p => long.Parse(p["blockindex"].ToString()) == blockindex).ToArray(); foreach (JToken jt in jtArr) { if (jt["vin"] != null) { foreach (JToken jvin in (JArray)jt["vin"]) { string prevTxid = jvin["txid"].ToString(); long prevIndex = long.Parse(jvin["vout"].ToString()); findstr = new JObject() { { "txid", prevTxid }, { "n", prevIndex } }.ToString(); if (mh.GetDataCount(localConn.connStr, localConn.connDB, cgasUtxoCol, findstr) > 0) { mh.DeleteData(localConn.connStr, localConn.connDB, cgasUtxoCol, findstr); } } } if (jt["vout"] != null) { foreach (JToken jvout in (JArray)jt["vout"]) { if (jvout["address"].ToString() != cgasAddress) { continue; } string newData = new JObject() { { "addr", jvout["address"] }, { "txid", jt["txid"] }, { "n", jvout["n"] }, { "asset", jvout["asset"] }, { "value", jvout["value"] }, { "createHeight", blockindex }, { "markAddress", "0" }, { "markTime", 0 }, { "lockAddress", "0" }, { "lockHeight", 0 }, }.ToString(); findstr = new JObject() { { "txid", jt["txid"] }, { "n", jvout["n"] } }.ToString(); if (mh.GetDataCount(localConn.connStr, localConn.connDB, cgasUtxoCol, findstr) <= 0) { mh.PutData(localConn.connStr, localConn.connDB, cgasUtxoCol, newData); } } } } // updateRecord(blockindex); log(blockindex, remoteHeight); } } // 添加索引 if (hasCreateIndex) { return; } mh.setIndex(localConn.connStr, localConn.connDB, cgasUtxoCol, "{'txid':1,'n':1}", "i_txid_n"); mh.setIndex(localConn.connStr, localConn.connDB, cgasUtxoCol, "{'markAddress':1}", "i_markAddress"); mh.setIndex(localConn.connStr, localConn.connDB, cgasUtxoCol, "{'markAddress':1, 'lockAddress':1}", "i_markAddress_lockAddress"); hasCreateIndex = true; }
private void run() { if (!initSuccFlag) { return; } string dataSortStr = new JObject() { { "lastTime.blockindex", 1 } }.ToString(); while (true) { try { ping(); int sumCount = 0; long cnt = mh.GetDataCount(remoteDbConnInfo.connStr, remoteDbConnInfo.connDB, auctionStateChangeCol, "{}"); for (int startIndex = 0; startIndex < cnt; startIndex += batchSize) { // 分页获取变更数据 JArray res = mh.GetData(remoteDbConnInfo.connStr, remoteDbConnInfo.connDB, auctionStateChangeCol, "{}", dataSortStr, startIndex, batchSize); if (res == null || res.Count == 0) { continue; } foreach (var item in res) { string fulldomain = item["fulldomain"].ToString(); string maxBuyer = item["maxBuyer"].ToString(); string maxPrice = item["maxPrice"].ToString(); string findStr = new JObject() { { "domain", fulldomain } }.ToString(); long subcnt = mh.GetDataCount(remoteDbConnInfo.connStr, remoteDbConnInfo.connDB, notifySubsColl, findStr); for (int ist = 0; ist < subcnt; ist += batchSize) { // 分页获取订阅邮箱 JArray ires = mh.GetData(remoteDbConnInfo.connStr, remoteDbConnInfo.connDB, notifySubsColl, findStr, "{}", ist, batchSize); if (ires == null || ires.Count == 0) { continue; } var mailArr = ires.Select(p => p["mail"].ToString()).Distinct().ToList(); mailArr.ForEach(p => { // 加入发送队列 sendQueue.Add(new SendMsg { mail = p, mailData = new List <MailData> { new MailData { fulldomain = fulldomain, maxBuyer = maxBuyer, maxPrice = DecimalHelper.formatDecimal(maxPrice) } } }); }); } } // 删除 res.ToList().ForEach(p => { string findStr = new JObject() { { "fulldomain", p["fulldomain"].ToString() } }.ToString(); mh.DeleteData(remoteDbConnInfo.connStr, remoteDbConnInfo.connDB, auctionStateChangeCol, findStr); } ); sumCount += res.Count; } LogHelper.printLog(name() + " has processed:" + sumCount); } catch (Exception ex) { LogHelper.printEx(ex); } } }