private void Form1_Load(object sender, EventArgs e) { if (!Directory.Exists(Node.NetParams.DataDirectory)) { Directory.CreateDirectory(Node.NetParams.DataDirectory); } string password = ""; if (File.Exists(Node.NetParams.KeysFileName)) { var fs = File.Open(Node.NetParams.KeysFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using (var br = new BinaryReader(fs)) { if (fs.Length > 0) { var magic = ByteString.ReadFromStream(br); var version = br.ReadUInt32(); var count = br.ReadUInt32(); for (var i = 0; i < count; i++) { var keyPair = new ECKeyPair(); keyPair.LoadFromStream(fs, false, true, true); Keys.Add(keyPair); if (version < 110) { while (true) { try { keyPair.DecriptKey(password); break; } catch (Exception exception) { if (password == "") { password = Prompt.ShowDialog("Add meg a tárca jelszavát", "Jelszó szükséges"); } } } } } } } } if (Keys.Count == 0) { var fs = File.Open(Node.NetParams.KeysFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); var keyPair = ECKeyPair.CreateNew(false, DateTime.Now.ToString()); Keys.Add(keyPair); using (BinaryWriter bw = new BinaryWriter(fs, Encoding.ASCII, true)) { ByteString magic = "WalletKeys"; magic.SaveToStream(bw); bw.Write((uint)110); bw.Write((uint)Keys.Count); foreach (var key in Keys) { key.SaveToStream(fs, false, true, true); } } fs.Dispose(); } Node.Instance.NodeKey = Keys.First(); Node.Instance.NodeServers.NodesChanged += (ob, ev) => { Invoke((Action)(() => { var i = 0; connectionCount.Caption = Node.Instance.NodeServers.Count.ToString(); connectionCount.SuperTip.Items.Clear(); foreach (var nodeServer in Node.Instance.NodeServers) { connectionCount.SuperTip.Items.Add(nodeServer.Value.EndPoint.ToString()).Image = Resources.network_connect; i++; } if (i > Node.Instance.NodeServers.Count) { i = 0; } })); }; Node.Instance.BlockDownloadProgress += (o, ev) => { Invoke((Action)(() => { progressBar.Caption = "Blokklánc"; progressPanel.Description = "Blokklánc letöltése"; repositoryItemProgressBar1.Maximum = ev.BlocksToDownload; progressBar.EditValue = ev.DownloadedBlocks; })); }; CheckPoints.CheckPointBuilding += (oo, ee) => { Invoke((Action)(() => { progressBar.Caption = "Checkpointok"; progressPanel.Description = "Checkpointok számítása"; repositoryItemProgressBar1.Maximum = ee.BlocksNeeded; progressBar.EditValue = ee.BlocksDone; })); }; ribbon.Enabled = false; transaction.Enabled = false; Task.Run(async() => { var node = await Node.Instance.StartNode(Keys); if (node == null) { return; } Invoke((Action)(() => { ribbon.Enabled = true; transaction.Enabled = true; progressPanel.Visible = false; })); Action action = () => { //repositoryItemMarqueeProgressBar1.Paused = true; accountBindingSource.DataSource = Node.Instance.Accounts.Where(p => Keys.Contains(p.AccountInfo.AccountKey)); var myAccounts = Node.Instance.Accounts.Where(p => Keys.Contains(p.AccountInfo.AccountKey)); accountCount.Text = myAccounts.Count().ToString("N0") + " db"; currentBalance.Text = myAccounts.Sum(p => p.VisibleBalance).ToString("N") + " " + Node.NetParams.CoinTicker; var timer = new Timer { Interval = 5000 }; timer.Tick += (o, ev) => { var lastBlock = Node.Instance.BlockChain.GetLastBlock(); lastBlockTime.Caption = "Utolsó blokk " + Math.Round(DateTime.Now.Subtract(lastBlock.Timestamp).TotalMinutes).ToString() + " perce"; minerCount.Caption = $"{Node.Instance.MinerServer.Clients.Count} bányászó kliens"; difficulty.Caption = Node.Instance.BlockChain.GetNewTarget().Item2.ToString("X"); }; timer.Enabled = true; }; Invoke(action); }); }