public void Save(MySqlConnection conn, JObject jObject) { Dictionary <string, string> selectWhere = new Dictionary <string, string>(); selectWhere.Add("addr", SpiderHelper.getString(jObject["address"].ToString())); DataTable dt = MysqlConn.ExecuteDataSet(DataTableName, selectWhere).Tables[0]; if (dt.Rows.Count != 0) { Dictionary <string, string> dirs = new Dictionary <string, string>(); dirs.Add("lasttxid", jObject["txid"].ToString()); dirs.Add("txcount", (int.Parse(dt.Rows[0]["txcount"].ToString()) + 1) + ""); Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("addr", dt.Rows[0]["addr"].ToString()); MysqlConn.Update(conn, DataTableName, dirs, where); } else { List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jObject["address"].ToString())); slist.Add(jObject["txid"].ToString()); slist.Add(jObject["txid"].ToString()); slist.Add("1"); MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } }
public void Save(MySqlConnection conn, string addr, string asset, string script) { Dictionary <string, string> selectWhere = new Dictionary <string, string>(); selectWhere.Add("addr", addr); selectWhere.Add("asset", asset); DataTable dt = MysqlConn.ExecuteDataSet(DataTableName, selectWhere).Tables[0]; if (dt.Rows.Count == 0) { string type = ""; if (script.EndsWith(SpiderHelper.ZoroNativeNep5Call)) { type = "NativeNep5"; } else { type = "Nep5"; } List <string> slist = new List <string>(); slist.Add(addr); slist.Add(asset); slist.Add(type); MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } }
public void Save(MySqlConnection conn, string script, uint blockHeight, string txid) { if (script == null) { return; } Dictionary <string, string> selectWhere = new Dictionary <string, string>(); selectWhere.Add("txid", txid); DataTable dt = MysqlConn.ExecuteDataSet(DataTableName, selectWhere).Tables[0]; if (dt.Rows.Count != 0) { Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("txid", txid); MysqlConn.Delete(conn, DataTableName, where); } scriptMethods.Clear(); cutString(script); for (int i = 0; i < scriptMethods.Count; i++) { List <string> slist = new List <string>(); slist.Add(txid); slist.Add(scriptMethods[i].calltype); slist.Add(scriptMethods[i].method); slist.Add(scriptMethods[i].contract); slist.Add(blockHeight.ToString()); MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } }
public void Save(MySqlConnection conn, JObject jObject, uint height) { List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jObject["hash"].ToString())); slist.Add(SpiderHelper.getString(jObject["size"].ToString())); slist.Add(SpiderHelper.getString(jObject["version"].ToString())); slist.Add(SpiderHelper.getString(jObject["time"].ToString())); slist.Add(SpiderHelper.getString(jObject["index"].ToString())); slist.Add(SpiderHelper.getString(jObject["script"].ToString())); slist.Add((jObject["tx"] as JArray).Count.ToString()); if (ChainSpider.checkHeight == int.Parse(SpiderHelper.getString(jObject["index"].ToString()))) { Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("indexx", SpiderHelper.getString(jObject["index"].ToString())); MysqlConn.Delete(conn, DataTableName, where); } MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); uint blockTime = uint.Parse(SpiderHelper.getString(jObject["time"].ToString())); int numTx = 0; foreach (var tx in (jObject["tx"] as JArray)) { trans.Save(conn, tx, height, blockTime); numTx++; } LogConfig.Log($"BlockSaved {ChainHash} height:{height} tx:{numTx}", LogConfig.LogLevel.Warning, ChainHash.ToString()); }
public void Save(MySqlConnection conn, JObject jToken) { List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jToken["blockindex"].ToString())); slist.Add(SpiderHelper.getString(jToken["txid"].ToString())); slist.Add(SpiderHelper.getString(jToken["n"].ToString())); slist.Add(SpiderHelper.getString(jToken["asset"].ToString())); slist.Add(SpiderHelper.getString(jToken["from"].ToString())); slist.Add(SpiderHelper.getString(jToken["to"].ToString())); slist.Add(SpiderHelper.getString(jToken["value"].ToString())); if (ChainSpider.checkHeight == int.Parse(jToken["blockindex"].ToString())) { Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("txid", SpiderHelper.getString(jToken["txid"].ToString())); where.Add("blockindex", SpiderHelper.getString(jToken["blockindex"].ToString())); MysqlConn.Delete(conn, DataTableName, where); } { MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } LogConfig.Log($"SaveNEP5Transfer {ChainHash} {jToken["blockindex"]} {jToken["txid"]}", LogConfig.LogLevel.Info, ChainHash.ToString()); }
public void getNativeNEP5Asset(MySqlConnection conn, UInt160 Contract) { try { ScriptBuilder sb = new ScriptBuilder(); sb.EmitSysCall("Zoro.NativeNEP5.Call", "TotalSupply", Contract); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Name", Contract); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Symbol", Contract); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", Contract); IO.Json.JObject jObject; Blockchain blockchain = ZoroChainSystem.Singleton.GetBlockchain(ChainHash);; ApplicationEngine engine = ApplicationEngine.Run(sb.ToArray(), blockchain, testMode: true); if (engine.State.HasFlag(VMState.FAULT)) { return; } JArray jStack = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson())); string totalSupply = jStack[0]["type"].AsString() == "ByteArray" ? new BigInteger(SpiderHelper.HexString2Bytes(jStack[0]["value"].AsString())).ToString() : jStack[0]["value"].AsString(); string name = jStack[1]["type"].AsString() == "ByteArray" ? Encoding.UTF8.GetString(SpiderHelper.HexString2Bytes(jStack[1]["value"].AsString())) : jStack[1]["value"].AsString(); string symbol = jStack[2]["type"].AsString() == "ByteArray" ? Encoding.UTF8.GetString(SpiderHelper.HexString2Bytes(jStack[2]["value"].AsString())) : jStack[2]["value"].AsString(); string decimals = jStack[3]["type"].AsString() == "ByteArray" ? BigInteger.Parse(jStack[3]["value"].AsString()).ToString() : jStack[3]["value"].AsString(); //BCT没有限制,可以随意增发 if (symbol == "BCT") { totalSupply = "0"; } List <string> slist = new List <string>(); slist.Add(Contract.ToString()); slist.Add(totalSupply); slist.Add(name); slist.Add(symbol); slist.Add(decimals); //这里有个bug,我们的bcp会因为转账而增长 { MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } LogConfig.Log($"SaveNEP5Asset {ChainHash} {Contract}", LogConfig.LogLevel.Info, ChainHash.ToString()); } catch (Exception e) { LogConfig.Log($"error occured when call invokescript, chainhash:{ChainHash}, nep5contract:{Contract.ToString()}, reason:{e.Message}", LogConfig.LogLevel.Error); throw e; } }
public void Save(MySqlConnection conn, JObject jObject, uint blockHeight) { if (null == jObject["vout"]) { return; } foreach (JObject vout in jObject["vout"] as JArray) { JObject result = new JObject(); result["addr"] = vout["address"]; result["txid"] = jObject["txid"]; result["n"] = vout["n"]; result["asset"] = vout["asset"]; result["value"] = vout["value"]; result["createHeight"] = blockHeight; result["used"] = 0; result["useHeight"] = 0; result["claimed"] = ""; List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(result["addr"].ToString())); slist.Add(SpiderHelper.getString(result["txid"].ToString())); slist.Add(SpiderHelper.getString(result["n"].ToString())); slist.Add(SpiderHelper.getString(result["asset"].ToString())); slist.Add(SpiderHelper.getString(result["value"].ToString())); slist.Add(SpiderHelper.getString(result["createHeight"].ToString())); slist.Add(SpiderHelper.getString(result["used"].ToString())); slist.Add(SpiderHelper.getString(result["useHeight"].ToString())); slist.Add(SpiderHelper.getString(result["claimed"].ToString())); //Dictionary<string, string> dictionary = new Dictionary<string, string>(); //dictionary.Add("txid", result["txid"].ToString()); //dictionary.Add("createHeight", blockHeight.ToString()); //bool exist = MysqlConn.CheckExist(DataTableName, dictionary); //if (!exist) if (ChainSpider.checkHeight == int.Parse(SpiderHelper.getString(result["createHeight"].ToString()))) { Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("addr", SpiderHelper.getString(result["addr"].ToString())); where.Add("createHeight", SpiderHelper.getString(result["createHeight"].ToString())); MysqlConn.Delete(conn, DataTableName, where); } { MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } //var utxoPath = "utxo" + Path.DirectorySeparatorChar + result["txid"] + "_" + result["n"] + "_" + result["addr"] + ".txt"; //File.Delete(utxoPath); //File.WriteAllText(utxoPath, result.ToString(), Encoding.UTF8); } foreach (JObject vin in jObject["vin"] as JArray) { ChangeUTXO(conn, SpiderHelper.getString(vin["txid"].ToString()), SpiderHelper.getString(vin["vout"].ToString()), blockHeight); } }
public void Save(MySqlConnection conn, JObject jToken) { string contract = SpiderHelper.getString(jToken["assetid"].ToString()); Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("assetid", contract); bool exist = MysqlConn.CheckExist(DataTableName, where); if (!exist) { Start(conn, contract); } }
public void getNEP5Asset(MySqlConnection conn, UInt160 Contract) { try { ScriptBuilder sb = new ScriptBuilder(); sb.EmitAppCall(Contract, "totalSupply"); sb.EmitAppCall(Contract, "name"); sb.EmitAppCall(Contract, "symbol"); sb.EmitAppCall(Contract, "decimals"); Blockchain blockchain = ZoroChainSystem.Singleton.GetBlockchain(ChainHash);; ApplicationEngine engine = ApplicationEngine.Run(sb.ToArray(), blockchain, testMode: true); if (engine.State.HasFlag(VMState.FAULT)) { return; } JArray jStack = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson())); string totalSupply = new BigInteger(SpiderHelper.HexString2Bytes(jStack[0]["value"].ToString())).ToString(); string name = Encoding.UTF8.GetString(SpiderHelper.HexString2Bytes(jStack[1]["value"].ToString())); string symbol = Encoding.UTF8.GetString(SpiderHelper.HexString2Bytes(jStack[2]["value"].ToString())); string decimals = BigInteger.Parse(jStack[3]["value"].ToString()).ToString(); List <string> slist = new List <string>(); slist.Add(Contract.ToString()); slist.Add(totalSupply); slist.Add(name); slist.Add(symbol); slist.Add(decimals); //Dictionary<string, string> dictionary = new Dictionary<string, string>(); //dictionary.Add("assetid", Contract.ToString()); //bool exist = MysqlConn.CheckExist(DataTableName, dictionary); //if (!exist) //这里有个bug,我们的bcp会因为转账而增长 { MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } LogConfig.Log($"SaveNEP5Asset {ChainHash} {Contract}", LogConfig.LogLevel.Info, ChainHash.ToString()); } catch (Exception e) { LogConfig.Log($"error occured when call invokescript, chainhash:{ChainHash}, nep5contract:{Contract.ToString()}, reason:{e.Message}", LogConfig.LogLevel.Error); throw e; } }
public void Save(MySqlConnection conn, JObject jObject) { List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jObject["address"].ToString())); slist.Add(SpiderHelper.getString(jObject["txid"].ToString())); Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("addr", SpiderHelper.getString(jObject["address"].ToString())); where.Add("txid", SpiderHelper.getString(jObject["txid"].ToString())); MysqlConn.Delete(conn, DataTableName, where); MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); }
public void ChangeUTXO(MySqlConnection conn, string txid, string voutNum, uint blockHeight) { Dictionary <string, string> dirs = new Dictionary <string, string>(); dirs.Add("used", "1"); dirs.Add("useHeight", blockHeight.ToString()); Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("txid", txid); where.Add("n", voutNum); MysqlConn.Update(conn, DataTableName, dirs, where); //JObject result = JObject.Parse(File.ReadAllText(path, Encoding.UTF8)); //result["used"] = 1; //result["useHeight"] = Helper.blockHeight; //File.WriteAllText(path, result.ToString(), Encoding.UTF8); }
public uint getHeight(string chainHash) { var dir = new Dictionary <string, string>(); dir.Add("chainhash", chainHash); DataTable dt = MysqlConn.ExecuteDataSet(DataTableName, dir).Tables[0]; if (dt.Rows.Count == 0) { return(0); } else { return(uint.Parse(dt.Rows[0]["chainheight"].ToString())); } }
public void Save(MySqlConnection conn, JObject jObject) { //JObject hashstateresult = new JObject(); //hashstateresult["result"] = jObject["result"]; List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jObject["version"].ToString())); slist.Add(SpiderHelper.getString(jObject["hash"].ToString())); slist.Add(SpiderHelper.getString(jObject["name"].ToString())); slist.Add(SpiderHelper.getString(jObject["owner"].ToString())); slist.Add(SpiderHelper.getString(jObject["timestamp"].ToString())); slist.Add(SpiderHelper.getString(jObject["seedlist"].ToString())); slist.Add(SpiderHelper.getString(jObject["validators"].ToString())); MysqlConn.SaveAndUpdataAppChainState(conn, DataTableName, slist); LogConfig.Log($"SaveAppChain {jObject["hash"]} {jObject["name"]}", LogConfig.LogLevel.Info); }
public void Save(MySqlConnection conn, string chainHash, string height) { var dir = new Dictionary <string, string>(); dir.Add("chainhash", chainHash); DataTable dt = MysqlConn.ExecuteDataSet(DataTableName, dir).Tables[0]; if (dt.Rows.Count == 0) { var list = new List <string>(); list.Add(chainHash); list.Add(height); MysqlConn.ExecuteDataInsert(conn, DataTableName, list); } else { var set = new Dictionary <string, string>(); set.Add("chainheight", height); MysqlConn.Update(conn, DataTableName, set, dir); } }
public void Save(MySqlConnection conn, JObject jObject, uint blockHeight, uint blockTime) { List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jObject["txid"].ToString())); slist.Add(SpiderHelper.getString(jObject["size"].ToString())); slist.Add(SpiderHelper.getString(jObject["type"].ToString())); slist.Add(SpiderHelper.getString(jObject["version"].ToString())); slist.Add(SpiderHelper.getString(jObject["attributes"].ToString())); slist.Add(SpiderHelper.getString(jObject["sys_fee"].ToString())); slist.Add(SpiderHelper.getString(jObject["blockindex"].ToString())); slist.Add(SpiderHelper.getString(jObject["gas_limit"] == null?"": jObject["gas_limit"].ToString())); slist.Add(SpiderHelper.getString(jObject["gas_price"] == null ? "" : jObject["gas_price"].ToString())); slist.Add(UInt160.Parse(StringRemoveZoro(SpiderHelper.getString(jObject["account"].ToString())).HexToBytes().Reverse().ToHexString()).ToAddress()); if (jObject["script"] != null) { txScriptMethod.Save(conn, SpiderHelper.getString(jObject["script"].ToString()), blockHeight, SpiderHelper.getString(jObject["txid"].ToString())); } if (ChainSpider.checkHeight == int.Parse(blockHeight.ToString())) { Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("txid", SpiderHelper.getString(jObject["txid"].ToString())); where.Add("blockindex", blockHeight.ToString()); MysqlConn.Delete(conn, DataTableName, where); } { MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } LogConfig.Log($"SaveTransaction {ChainHash} {blockHeight}", LogConfig.LogLevel.Info, ChainHash.ToString()); utxo.Save(conn, jObject, blockHeight); //if (SpiderHelper.getString(jObject["type"].ToString()) == "InvocationTransaction") //{ // notify.Save(conn, jObject, blockHeight, blockTime, SpiderHelper.getString(jObject["script"].ToString())); //} }
public void Save(MySqlConnection conn, JObject jObject, string path) { JObject result = new JObject(); result["version"] = jObject["version"]; result["id"] = jObject["txid"]; result["type"] = jObject["asset"]["type"]; result["name"] = jObject["asset"]["name"]; result["amount"] = jObject["asset"]["amount"]; result["available"] = 1; result["precision"] = jObject["asset"]["precision"]; result["owner"] = jObject["asset"]["owner"]; result["admin"] = jObject["asset"]["admin"]; result["issuer"] = 1; result["expiration"] = 0; result["frozen"] = 0; List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(result["version"].ToString())); slist.Add(SpiderHelper.getString(result["id"].ToString())); slist.Add(SpiderHelper.getString(result["type"].ToString())); slist.Add(SpiderHelper.getString(result["name"].ToString())); slist.Add(SpiderHelper.getString(result["amount"].ToString())); slist.Add(SpiderHelper.getString(result["available"].ToString())); slist.Add(SpiderHelper.getString(result["precision"].ToString())); slist.Add(SpiderHelper.getString(result["owner"].ToString())); slist.Add(SpiderHelper.getString(result["admin"].ToString())); slist.Add(SpiderHelper.getString(result["issuer"].ToString())); slist.Add(SpiderHelper.getString(result["expiration"].ToString())); slist.Add(SpiderHelper.getString(result["frozen"].ToString())); { MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); } LogConfig.Log($"SaveAsset {ChainHash} {result["name"]}", LogConfig.LogLevel.Info, ChainHash.ToString()); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Hash_List, name); return(true); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Chainlistheight, name); return(true); }
public bool IsTableExisted(string name) { return(MysqlConn.Exist(name)); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Address_tx, name); return(true); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Transaction, name); return(true); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Tx_Script_Method, name); return(true); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Appchainstate, name); return(true); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.NEP5Asset, name); return(true); }
public void Save(MySqlConnection conn, JObject jObject) { MysqlConn.SaveAndUpdataHashList(conn, DataTableName, SpiderHelper.getString(jObject["hashlist"].ToString())); }
public void Save(MySqlConnection conn, JObject jToken) { JObject executions = null; try { if (jToken != null) { executions = jToken["executions"]; } } catch (Exception e) { } //try //{ // if (!TryGetDB(ChainHash, out DB db)) return; // if (db.IsDisposed) return; // UInt256 hash = UInt256.Parse(SpiderHelper.getString(jToken["txid"].ToString())); // if (!db.TryGet(ReadOptions.Default, hash.ToArray(), out Slice value)) // throw new RpcException(-100, "Unknown transaction"); // result = JObject.Parse(value.ToString()); // if (result != null) // executions = result["executions"]; //} //catch (Exception e) //{ // LogConfig.Log($"error occured when call getapplicationlog, chain:{ChainHash} height:{blockHeight}, reason:{e.Message}", LogConfig.LogLevel.Error); // //throw e; //} if (jToken != null && executions != null) { foreach (var execution in executions as JArray) { List <string> slist = new List <string>(); slist.Add(SpiderHelper.getString(jToken["txid"].ToString())); slist.Add(SpiderHelper.getString(execution["vmstate"].ToString())); slist.Add(SpiderHelper.getString(execution["gas_consumed"].ToString())); slist.Add(SpiderHelper.getString(execution["stack"].ToString())); slist.Add(SpiderHelper.getString(execution["notifications"].ToString().Replace(@"[/n/r]", ""))); Dictionary <string, string> where = new Dictionary <string, string>(); where.Add("txid", SpiderHelper.getString(jToken["txid"].ToString())); MysqlConn.Delete(conn, DataTableName, where); MysqlConn.ExecuteDataInsert(conn, DataTableName, slist); LogConfig.Log($"SaveNotify {ChainHash} {jToken["txid"]}", LogConfig.LogLevel.Info, ChainHash.ToString()); if (execution["vmstate"].ToString().Contains("FAULT")) { return; } JObject notifications = execution["notifications"]; foreach (JObject notify in notifications as JArray) { JArray values = notify["state"]["value"] as JArray; if (values[0]["type"].ToString() == "ByteArray") { string transfer = Encoding.UTF8.GetString(SpiderHelper.HexString2Bytes(SpiderHelper.getString(values[0]["value"].ToString()))); string contract = SpiderHelper.getString(notify["contract"].ToString()); if (transfer == "transfer") { JObject nep5 = new JObject(); nep5["assetid"] = contract; nep5Asset.Save(conn, nep5); //存储Nep5Transfer内容 JObject tx = new JObject(); tx["txid"] = SpiderHelper.getString(jToken["txid"].ToString()); tx["n"] = 0; tx["asset"] = contract; if (SpiderHelper.getString(values[1]["value"].ToString()) == "") { tx["from"] = ""; } else { tx["from"] = UInt160.Parse(SpiderHelper.getString(values[1]["value"].ToString())).ToAddress(); } tx["to"] = UInt160.Parse(SpiderHelper.getString(values[2]["value"].ToString())).ToAddress(); if (SpiderHelper.getString(values[3]["type"].ToString()) == "ByteArray") { tx["value"] = new BigInteger(SpiderHelper.HexString2Bytes(SpiderHelper.getString(values[3]["value"].ToString()))).ToString(); } else { tx["value"] = BigInteger.Parse(SpiderHelper.getString(values[3]["value"].ToString()), NumberStyles.AllowHexSpecifier).ToString(); } JObject j = new JObject(); j["address"] = SpiderHelper.getString(tx["to"].ToString()); j["txid"] = SpiderHelper.getString(tx["txid"].ToString()); address.Save(conn, j); addressAsset.Save(conn, SpiderHelper.getString(tx["to"].ToString()), contract, ""); address_tx.Save(conn, j); nep5Transfer.Save(conn, tx); } } } } } }