private async void buttonRestoreYourWallet_ClickAsync(object sender, EventArgs e) { string walletPath = textBoxPathWallet.Text; string walletPassword = textBoxPassword.Text; string walletKey = textBoxPrivateKey.Text; walletKey = Regex.Replace(walletKey, @"\s+", string.Empty); textBoxPassword.Text = string.Empty; textBoxPathWallet.Text = string.Empty; textBoxPrivateKey.Text = string.Empty; if (await ClassWalletObject.InitializationWalletConnection(string.Empty, walletPassword, string.Empty, ClassWalletPhase.Create)) { ClassWalletObject.ListenSeedNodeNetworkForWallet(); ClassWalletObject.WalletDataCreationPath = walletPath; new Thread(async delegate() { Stopwatch packetSpeedCalculator = new Stopwatch(); packetSpeedCalculator.Start(); if (await ClassWalletObject.WalletConnect.SendPacketWallet(ClassWalletObject.Certificate, string.Empty, false)) { packetSpeedCalculator.Stop(); if (packetSpeedCalculator.ElapsedMilliseconds > 0) { Thread.Sleep(1000); } string requestRestoreQrCodeEncrypted = null; using (ClassWalletRestoreFunctions walletRestoreFunctions = new ClassWalletRestoreFunctions()) { requestRestoreQrCodeEncrypted = walletRestoreFunctions.GenerateQRCodeKeyEncryptedRepresentation(walletKey, walletPassword); if (requestRestoreQrCodeEncrypted != null) { ClassWalletObject.WalletNewPassword = walletPassword; ClassWalletObject.WalletPrivateKeyEncryptedQRCode = walletKey; if (!await ClassWalletObject.SeedNodeConnectorWallet.SendPacketToSeedNodeAsync(ClassWalletCommand.ClassWalletSendEnumeration.AskPhase + "|" + requestRestoreQrCodeEncrypted, ClassWalletObject.Certificate, false, true)) { #if WINDOWS ClassFormPhase.MessageBoxInterface(ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT")); ClassFormPhase.WalletXiropht.BeginInvoke(invoke); #endif } } else { #if WINDOWS ClassFormPhase.MessageBoxInterface("Invalid private key inserted.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht, "Invalid private key inserted."); ClassFormPhase.WalletXiropht.BeginInvoke(invoke); #endif } } } else { #if WINDOWS ClassFormPhase.MessageBoxInterface( ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT")); ClassFormPhase.WalletXiropht.BeginInvoke(invoke); #endif } }).Start(); } }
private async void buttonRestoreYourWallet_ClickAsync(object sender, EventArgs e) { if (CheckPasswordValidity()) { ClassParallelForm.ShowWaitingFormAsync(); var walletPath = textBoxPathWallet.Text; var walletPassword = textBoxPassword.Text; var walletKey = textBoxPrivateKey.Text; walletKey = Regex.Replace(walletKey, @"\s+", string.Empty); textBoxPassword.Text = string.Empty; textBoxPathWallet.Text = string.Empty; textBoxPrivateKey.Text = string.Empty; CheckPasswordValidity(); await Task.Factory.StartNew(async() => { var walletRestoreFunctions = new ClassWalletRestoreFunctions(); var requestRestoreQrCodeEncrypted = walletRestoreFunctions.GenerateQrCodeKeyEncryptedRepresentation(walletKey, walletPassword); if (Program.WalletXiropht.ClassWalletObject != null) { await Program.WalletXiropht.InitializationWalletObject(); } if (await Program.WalletXiropht.ClassWalletObject.InitializationWalletConnection(string.Empty, walletPassword, string.Empty, ClassWalletPhase.Restore)) { Program.WalletXiropht.ClassWalletObject.ListenSeedNodeNetworkForWallet(); Program.WalletXiropht.ClassWalletObject.WalletDataCreationPath = walletPath; if (await Program.WalletXiropht.ClassWalletObject.WalletConnect.SendPacketWallet( Program.WalletXiropht.ClassWalletObject.Certificate, string.Empty, false)) { if (requestRestoreQrCodeEncrypted != null) { Program.WalletXiropht.ClassWalletObject.WalletNewPassword = walletPassword; Program.WalletXiropht.ClassWalletObject.WalletPrivateKeyEncryptedQRCode = walletKey; await Task.Delay(1000); if (!await Program.WalletXiropht.ClassWalletObject.SeedNodeConnectorWallet .SendPacketToSeedNodeAsync( ClassWalletCommand.ClassWalletSendEnumeration.AskPhase + ClassConnectorSetting.PacketContentSeperator + requestRestoreQrCodeEncrypted, Program.WalletXiropht.ClassWalletObject.Certificate, false, true)) { ClassParallelForm.HideWaitingFormAsync(); #if WINDOWS ClassFormPhase.MessageBoxInterface( ClassTranslation.GetLanguageTextFromOrder( ClassTranslationEnumeration.createwalleterrorcantconnectmessagecontenttext), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(Program.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder(ClassTranslationEnumeration.createwalleterrorcantconnectmessagecontenttext)); Program.WalletXiropht.BeginInvoke(invoke); #endif } } else { ClassParallelForm.HideWaitingFormAsync(); #if WINDOWS ClassFormPhase.MessageBoxInterface("Invalid private key inserted.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(Program.WalletXiropht, "Invalid private key inserted."); Program.WalletXiropht.BeginInvoke(invoke); #endif } } else { ClassParallelForm.HideWaitingFormAsync(); #if WINDOWS ClassFormPhase.MessageBoxInterface( ClassTranslation.GetLanguageTextFromOrder( ClassTranslationEnumeration.createwalleterrorcantconnectmessagecontenttext), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(Program.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder(ClassTranslationEnumeration.createwalleterrorcantconnectmessagecontenttext)); Program.WalletXiropht.BeginInvoke(invoke); #endif } } else { ClassParallelForm.HideWaitingFormAsync(); #if WINDOWS ClassFormPhase.MessageBoxInterface( ClassTranslation.GetLanguageTextFromOrder( ClassTranslationEnumeration.createwalleterrorcantconnectmessagecontenttext), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MethodInvoker invoke = () => MessageBox.Show(Program.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder(ClassTranslationEnumeration.createwalleterrorcantconnectmessagecontenttext)); Program.WalletXiropht.BeginInvoke(invoke); #endif } walletRestoreFunctions.Dispose(); }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current); } else { #if WINDOWS ClassFormPhase.MessageBoxInterface( ClassTranslation.GetLanguageTextFromOrder(ClassTranslationEnumeration.createwalletlabelpasswordrequirementtext), ClassTranslation.GetLanguageTextFromOrder( ClassTranslationEnumeration.walletnetworkobjectcreatewalletpassworderror2titletext), MessageBoxButtons.OK, MessageBoxIcon.Error); #else await Task.Factory.StartNew(() => { MethodInvoker invoke = () => MessageBox.Show(Program.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder(ClassTranslationEnumeration.createwalletlabelpasswordrequirementtext), ClassTranslation.GetLanguageTextFromOrder(ClassTranslationEnumeration.walletnetworkobjectcreatewalletpassworderror2titletext), MessageBoxButtons.OK, MessageBoxIcon.Error); Program.WalletXiropht.BeginInvoke(invoke); }).ConfigureAwait(false); #endif } }