private void RefreshBlockChain(object sender, EventArgs e) { if (!_viewModel.IsConnected) { return; } _nodeLauncher.RefreshBlockChain(); }
private static void ExecuteP2PNetworkRunningMenu(int number) { if (number < 0 || number > 4) { MenuHelper.DisplayError("Enter a number between [1-4]"); ExecuteFullNodeMenu(); return; } switch (number) { case 1: Console.WriteLine($"Number of active nodes {_nodeLauncher.GetActivePeers().Count}"); break; case 2: var peers = _nodeLauncher.GetActivePeers(); var ips = peers.Select(p => (new IPAddress(p.GetCurrentIpAddress().Ipv6)).MapToIPv4().ToString()); foreach (var ip in ips) { Console.WriteLine(ip); } break; case 3: _nodeLauncher.RefreshMemPool(); _nodeLauncher.RefreshBlockChain(); break; case 4: break; case 5: _nodeLauncher.GetP2PNode().Stop(); _nodeLauncher.GetP2PNetwork().Stop(); break; } ExecuteFullNodeMenu(); }
private static void ExecuteConnectedWallet(int number) { if (number < 0 && number > 6) { MenuHelper.DisplayError("Please enter an option between [1-6]"); } switch (number) { case 1: // BROADCAST A UTXO TRANSACTION. Console.WriteLine("Please enter the address"); var receivedHash = Console.ReadLine(); var deserializedAdr = BlockChainAddress.Deserialize(receivedHash); Console.WriteLine("How much do-you want to send ?"); var value = MenuHelper.EnterNumber(); var blockChain = BlockChainStore.Instance().GetBlockChain(); var builder = new TransactionBuilder(); var transaction = builder.NewNoneCoinbaseTransaction() // .Spend(0, ) .AddOutput(value, Script.CreateP2PKHScript(deserializedAdr.PublicKeyHash)) .Build(); var serializedTransaction = transaction.Serialize(); // SEND UTXO. _nodeLauncher.Broadcast(transaction); ExecuteMenu(); return; case 2: // GENERATE A NEW BITCOIN ADDRESS. var key = Key.Genererate(); var h = new BigInteger(key.GetPublicKeyHashed()); var blockChainAddress = new BlockChainAddress(ScriptTypes.P2PKH, _nodeLauncher.GetNetwork(), key); var hash = blockChainAddress.GetSerializedHash(); Console.WriteLine($"Give the bitcoin address to the person {hash}"); Console.WriteLine("Please enter a password to protect your wallet"); var password = Console.ReadLine(); _keyRepository.Load(password); _keyRepository.Keys.Add(key); _keyRepository.Save(password); break; case 3: DisplayWalletInformation(); ExecuteMenu(); return; case 4: _nodeLauncher.RefreshBlockChain(); ExecuteMenu(); break; case 5: _nodeLauncher.RefreshConnectedPeers(); ExecuteMenu(); break; case 6: Console.WriteLine("Bye bye"); Console.ReadLine(); return; } ExecuteMenu(); }