private bool ViewBlock(int height) { DataTable dt; string ts; using (var sqlc = new MySqlClient(SiaClassicLib.Config.ConnectionString)) { dt = sqlc.FillTable($"SELECT id,siacoininputs,siacoinoutputs,filecontracts,filecontractrevisions,storageproofs," + "siafundinputs,siafundoutputs,minerfees,arbitrarydata,transactionsignatures FROM txs WHERE blockheight=" + height); ts = sqlc.ExecuteScalar($"SELECT timestamp FROM blocks WHERE height=" + height)?.ToString(); } if (dt.Rows.Count == 0) { return(false); } BlockViewPanel.Visible = true; BlockViewListView.DataSource = dt; BlockViewListView.DataBind(); BlockHeightLabel.Text = height.ToString(); BlockTimeLabel.Text = ClassLibrary.Extensions.TimeStampToString(ts); return(true); }
private bool ViewAddress(string addr) { DataTable dt; object nrecords; using (var sqlc = new MySqlClient(SiaClassicLib.Config.ConnectionString)) { dt = sqlc.FillTable($"SELECT timestamp,block_height,tx_id,value FROM siacoinoutputs JOIN blocks on height=block_height " + $"WHERE unlockhash ='{addr}' ORDER by height desc LIMIT 21"); nrecords = sqlc.ExecuteScalar($"SELECT count(*) from siacoinoutputs WHERE unlockhash ='{addr}'"); } if (dt.Rows.Count == 0) { return(false); } dt.AddTimeColumn("time", "timestamp"); string count = "20", last = "Showing last ", s = "s"; if (dt.Rows.Count <= 20) { count = dt.Rows.Count.ToString(); last = string.Empty; if (dt.Rows.Count == 1) { s = string.Empty; } } AddressViewPanel.Visible = true; AddressViewListView.DataSource = dt; AddressViewListView.DataBind(); AddressViewLabel.Text = addr; AddressViewTxCountLabel.Text = $"{last}{count} transaction{s} out of {nrecords}"; return(true); }
public static string GenerateOrderID() { mutex.WaitOne(); string orderId = default(string); Random ran = new Random(); orderId = "P" + DateTime.Now.ToString("yyyyMMdd") + ran.Next(1000, 9999).ToString(); string sql = "SELECT Count(OrderID) FROM OrderInfo Where OrderID='" + orderId + "'"; if (mySqlclient == null) { mySqlclient = MySqlClient.GetMySqlClient(); } int count = Convert.ToInt32(mySqlclient.ExecuteScalar(sql, null)); if (count > 0) { GenerateOrderID(); } mutex.ReleaseMutex(); return(orderId); }
public void UpdateTopOnly(int heightLimit, bool continuos) { do { try { int height; using (var sqlc = new MySqlClient(connStr)) { var s = sqlc.ExecuteScalar($"SELECT height FROM `blocks` ORDER BY height DESC LIMIT 1"); height = s != null ? (int)(uint)s + 1 : 0; } Console.WriteLine(DateTime.Now + " Db height=" + height); if (height < heightLimit) { height = heightLimit; } int consensus_height = -1; bool wasSleeping = false; while (true) { if (Console.KeyAvailable && Console.ReadKey().KeyChar == 27) { break; } dynamic consensus = wc.GetObject("consensus"); int new_consensus_height = (int)consensus.height; if (consensus_height == new_consensus_height) { if (continuos) { Thread.Sleep(10000); Console.Write("."); wasSleeping = true; continue; } else { break; } } if (wasSleeping) { Console.WriteLine(); wasSleeping = false; } Console.WriteLine(DateTime.Now + " Consensus is at height=" + new_consensus_height); consensus_height = new_consensus_height; using (var sqlc = new MySqlClient(connStr)) for (; height <= consensus_height; ++height) { if (Console.KeyAvailable && Console.ReadKey().KeyChar == 27) { break; } InsertAtHeight(sqlc, height); } } } catch (Exception x) { Console.WriteLine(x.Message); Console.WriteLine(x.StackTrace); } }while (continuos); }