private static void ConnectCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket client = (Socket)ar.AsyncState; // Complete the connection. client.EndConnect(ar); var blockchain = NetworkFileProvider <Blockchain.Blockchain> .GetModel(Constants.BlockchainStoragePath); if (!blockchain.Nodes.Any(n => n.Address == client.RemoteEndPoint.ToString())) { blockchain.RegisterNode(client.RemoteEndPoint.ToString()); } NetworkFileProvider <Blockchain.Blockchain> .SetModel(Constants.BlockchainStoragePath, blockchain); // Signal that the connection has been made. connectDone.Set(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public static void Initialize() { wallet = NetworkFileProvider <Wallet> .GetModel(Constants.WalletStoragePrivateKey); BigInteger privateKey; if (wallet.Address == null || wallet.Address == string.Empty) { Logger.LogLine("set password (must be 16 symbols):", ConsoleColor.Gray); var password = Console.ReadLine(); var hex = CryptographyHelper.GetRandomHexNumber(62); privateKey = Hex.HexToBigInteger(hex); Logger.LogLine($"your private key is {privateKey}"); var encryptedPrivateKey = CryptographyHelper.Encrypt(privateKey.ToString(), password); ECPoint publicKey = Secp256k1.Secp256k1.G.Multiply(privateKey); string bitcoinAddressUncompressed = publicKey.GetBitcoinAddress(false); string bitcoinAddressCompressed = publicKey.GetBitcoinAddress(compressed: true); wallet.PublicKey = publicKey; wallet.Address = bitcoinAddressCompressed; wallet.EncryptedPrivateKey = encryptedPrivateKey; NetworkFileProvider <Wallet> .SetModel(Constants.WalletStoragePrivateKey, wallet); } else { Logger.LogLine("your password:"******"your private key is {GetPrivateKey(password)}"); } Logger.LogLine($"your address is {wallet.Address}"); }