public async Task <IActionResult> SyncFromDate([FromBody] WalletSyncRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(await this.ExecuteAsAsync(request, cancellationToken, (req, token) => { if (!request.All) { this.walletSyncManager.SyncFromDate(request.Date, request.WalletName); } else { this.walletSyncManager.SyncFromHeight(0, request.WalletName); } return this.Ok(); })); }
private async Task <bool> RestoreWalletAsync(int apiPort, string chainName, string walletName) { Console.WriteLine($"You have chosen to restore your {chainName} wallet."); string mnemonic; string passphrase; string password; do { Console.WriteLine($"Please enter your 12-Words used to recover your wallet:"); mnemonic = Console.ReadLine(); Console.WriteLine("Please enter your wallet passphrase:"); passphrase = Console.ReadLine(); Console.WriteLine("Please enter the wallet password used to encrypt the wallet:"); password = Console.ReadLine(); if (!string.IsNullOrEmpty(mnemonic) && !string.IsNullOrEmpty(passphrase) && !string.IsNullOrEmpty(password)) { break; } Console.WriteLine("ERROR: Please ensure that you enter all the wallet details."); } while (true); var walletRecoveryRequest = new WalletRecoveryRequest() { CreationDate = new DateTime(2020, 11, 1), Mnemonic = mnemonic, Name = walletName, Passphrase = passphrase, Password = password }; try { await $"http://localhost:{apiPort}/api".AppendPathSegment("wallet/recover").PostJsonAsync(walletRecoveryRequest); } catch (Exception ex) { Console.WriteLine($"ERROR: An exception occurred trying to recover your {chainName} wallet: {ex}"); return(false); } WalletInfoModel walletInfoModel = await $"http://localhost:{apiPort}/api".AppendPathSegment("Wallet/list-wallets").GetJsonAsync <WalletInfoModel>(); if (walletInfoModel.WalletNames.Contains(walletName)) { Console.WriteLine($"SUCCESS: {chainName} wallet has been restored."); } else { Console.WriteLine($"ERROR: {chainName} wallet failed to be restored, exiting the registration process."); return(false); } try { Console.WriteLine($"Your {chainName} wallet will now be resynced, please be patient..."); var walletSyncRequest = new WalletSyncRequest() { All = true, WalletName = walletName }; await $"http://localhost:{apiPort}/api".AppendPathSegment("wallet/sync-from-date").PostJsonAsync(walletSyncRequest); } catch (Exception ex) { Console.WriteLine($"ERROR: An exception occurred trying to resync your {chainName} wallet: {ex}"); return(false); } return(true); }