public IActionResult EnableFederation([FromBody] EnableFederationRequest request) { Guard.NotNull(request, nameof(request)); try { if (!this.ModelState.IsValid) { IEnumerable <string> errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } // Enabling the federation wallet requires the federation wallet. for (int timeOutSeconds = request.TimeoutSeconds ?? 0; timeOutSeconds >= 0; timeOutSeconds--) { if (this.walletManager.GetWallet() != null) { this.walletManager.EnableFederationWallet(request.Password, request.Mnemonic, request.Passphrase); return(this.Ok()); } Thread.Sleep(1000); } return(this.NotFound("No federation wallet found.")); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult EnableFederation([FromBody] EnableFederationRequest request) { Guard.NotNull(request, nameof(request)); try { if (!this.ModelState.IsValid) { IEnumerable <string> errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } this.walletManager.EnableFederation(request.Password, request.Mnemonic, request.Passphrase); return(this.Ok()); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult EnableFederation([FromBody] EnableFederationRequest request) { Guard.NotNull(request, nameof(request)); try { if (!this.ModelState.IsValid) { IEnumerable <string> errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } FederationWallet wallet = this.walletManager.GetWallet(); // Check the password try { Key.Parse(wallet.EncryptedSeed, request.Password, wallet.Network); } catch (Exception ex) { throw new SecurityException(ex.Message); } this.walletManager.Secret = new WalletSecret() { WalletPassword = request.Password }; return(this.Ok()); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }