internal string GetTranSqlText(JToken jObject, uint blockHeight, uint blockTime) { string sql = ""; List <string> slist = new List <string>(); slist.Add(jObject["txid"].ToString()); slist.Add(jObject["size"].ToString()); slist.Add(jObject["type"].ToString()); slist.Add(jObject["version"].ToString()); slist.Add(jObject["attributes"].ToString()); slist.Add(jObject["sys_fee"].ToString()); slist.Add(jObject["net_fee"].ToString()); slist.Add(blockHeight.ToString()); sql += MysqlConn.InsertSqlBuilder(DataTableName, slist); sql += saveUtxo.GetUtxoSqlText(jObject, blockHeight); if ((string)jObject["type"] == "InvocationTransaction" && jObject["script"] != null) { sql += saveNotify.GetNotifySqlText(jObject, blockHeight, blockTime); } return(sql); }
public string GetBlockSqlText(WebClient wc, JToken jObject, uint height) { List <string> slist = new List <string>(); slist.Add(jObject["hash"].ToString()); slist.Add(jObject["size"].ToString()); slist.Add(jObject["version"].ToString()); slist.Add(jObject["previousblockhash"].ToString()); slist.Add(jObject["merkleroot"].ToString()); slist.Add(jObject["time"].ToString()); slist.Add(jObject["index"].ToString()); slist.Add(jObject["nonce"].ToString()); slist.Add(jObject["nextconsensus"].ToString()); slist.Add((jObject["tx"] as JArray).Count.ToString()); string sql = MysqlConn.InsertSqlBuilder(DataTableName, slist); uint blockTime = uint.Parse(jObject["time"].ToString()); int numTx = 0; foreach (var tx in jObject["tx"]) { sql += trans.GetTranSqlText(tx, height, blockTime); numTx++; } if (numTx > 1) { Program.Log($"GetBlockSqlText height:{height} tx:{numTx}", Program.LogLevel.Warning); } return(sql); }
public string GetNep5TransferSql(uint blockHeight, uint blockTime, string txid, JToken notifications) { string sql = ""; foreach (JObject notify in notifications) { string contract = notify["contract"].ToString(); //只监控 ZORO if (contract == Settings.Default.ZoroHash) { JToken values = notify["state"]["value"]; string method = Encoding.UTF8.GetString(ThinNeo.Helper.HexString2Bytes(values[0]["value"].ToString())); if (method == "transfer") { string from = values[1]["value"].ToString() == "" ? "" : ThinNeo.Helper_NEO.GetAddress_FromScriptHash(new ThinNeo.Hash160(values[1]["value"].ToString())); string to = ThinNeo.Helper_NEO.GetAddress_FromScriptHash(new ThinNeo.Hash160(values[2]["value"].ToString())); string value = values[3]["type"].ToString() == "ByteArray" ? new BigInteger(ThinNeo.Helper.HexString2Bytes(values[3]["value"].ToString())).ToString() : BigInteger.Parse(values[3]["value"].ToString(), NumberStyles.AllowHexSpecifier).ToString(); //构造保存Nep5Transfer的list List <string> slist = new List <string>(); slist.Add(blockHeight.ToString()); slist.Add(txid); slist.Add(contract); slist.Add(from); slist.Add(to); slist.Add(value.ToString()); sql += MysqlConn.InsertSqlBuilder(DataTableName, slist); //构造保存Address tx的list List <string> flist = new List <string>(); flist.Add(from); flist.Add(txid); flist.Add(TransType.Send); flist.Add(contract); flist.Add(value); flist.Add(blockHeight.ToString()); flist.Add(blockTime.ToString()); sql += address_tx.GetAddressTxSql(flist); //构造保存Address tx的list List <string> tlist = new List <string>(); tlist.Add(to); tlist.Add(txid); tlist.Add(TransType.Get); tlist.Add(contract); tlist.Add(value); tlist.Add(blockHeight.ToString()); tlist.Add(blockTime.ToString()); sql += address_tx.GetAddressTxSql(tlist); } } } return(sql); }
internal uint getHeight() { string sql = $"select height from {DataTableName}"; DataTable dt = MysqlConn.ExecuteDataSet(sql).Tables[0]; if (dt.Rows.Count == 0) { return(0); } else { return(uint.Parse(dt.Rows[0]["height"].ToString()) + 1); } }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.NEP5Transfer, name); return(true); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Notify, name); return(true); }
public bool IsTableExisted(string name) { return(MysqlConn.Exist(name)); }
public string GetAddressTxSql(List <string> slist) { return(MysqlConn.InsertSqlBuilder(DataTableName, slist)); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Address_tx, name); return(true); }
public string GetUtxoSqlText(JToken tx, uint blockHeight) { string sql = ""; string txid = (string)tx["txid"]; JArray vinJA = (JArray)tx["vin"]; JArray voutJA = (JArray)tx["vout"]; //Utxo产生,Insert if (voutJA.Count > 0) { foreach (JObject vo in voutJA) { List <string> slist = new List <string>(); slist.Add(vo["address"].ToString()); slist.Add(txid); slist.Add(vo["n"].ToString()); slist.Add(vo["asset"].ToString()); slist.Add(vo["value"].ToString()); slist.Add(blockHeight.ToString()); slist.Add(""); //used slist.Add("0"); //useHeight slist.Add(""); //claimed sql += MysqlConn.InsertSqlBuilder(DataTableName, slist); } } //Utxo使用,Update if (vinJA.Count > 0) { foreach (JObject vi in vinJA) { //Update 字段 Dictionary <string, string> uDic = new Dictionary <string, string>(); uDic.Add("used", txid); uDic.Add("useHeight", blockHeight.ToString()); //Where 条件字段 Dictionary <string, string> wDic = new Dictionary <string, string>(); wDic.Add("txid", vi["txid"].ToString()); wDic.Add("n", vi["vout"].ToString()); sql += MysqlConn.UpdateSqlBuilder(DataTableName, uDic, wDic); } } if (tx["claims"] != null) { //记录GAS领取 JArray claimJA = (JArray)tx["claims"]; if (claimJA.Count > 0) { foreach (JObject cl in claimJA) { //Update 字段 Dictionary <string, string> uDic = new Dictionary <string, string>(); uDic.Add("claimed", cl["txid"].ToString()); //Where 条件字段 Dictionary <string, string> wDic = new Dictionary <string, string>(); wDic.Add("txid", cl["txid"].ToString()); wDic.Add("n", cl["vout"].ToString()); sql += MysqlConn.UpdateSqlBuilder(DataTableName, uDic, wDic); } } } return(sql); }
public override bool CreateTable(string name) { MysqlConn.CreateTable(TableType.Transaction, name); return(true); }