public IActionResult Create([FromBody] WalletCreationRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } try { Mnemonic mnemonic = this.walletManager.CreateWallet(request.Password, request.Name, mnemonic: request.Mnemonic); // start syncing the wallet from the creation date this.walletSyncManager.SyncFromDate(this.dateTimeProvider.GetUtcNow()); return(this.Json(mnemonic.ToString())); } catch (WalletException e) { // indicates that this wallet already exists this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, e.Message, e.ToString())); } catch (NotSupportedException e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "There was a problem creating a wallet.", e.ToString())); } }
public IActionResult Create([FromBody] WalletCreationRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { Mnemonic mnemonic = this.walletManager.CreateWallet(request.Password, request.Name, mnemonic: request.Mnemonic); // start syncing the wallet from the creation date this.walletSyncManager.SyncFromDate(DateTime.Now); return(this.Json(mnemonic.ToString())); } catch (WalletException e) { // indicates that this wallet already exists this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, e.Message, e.ToString())); } catch (NotSupportedException e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "There was a problem creating a wallet.", e.ToString())); } }
public IActionResult Create([FromBody] WalletCreationRequest walletCreation) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { var mnemonic = this.walletWrapper.Create(walletCreation.Password, walletCreation.FolderPath, walletCreation.Name, walletCreation.Network); return(this.Json(mnemonic)); } catch (NotSupportedException e) { // indicates that this wallet already exists return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, "This wallet already exists.", e.ToString())); } }
public IActionResult Create([FromBody] WalletCreationRequest request) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { // get the wallet folder DirectoryInfo walletFolder = this.GetWalletFolder(); Mnemonic mnemonic = this.walletManager.CreateWallet(request.Password, request.Name); return(this.Json(mnemonic.ToString())); } catch (InvalidOperationException e) { // indicates that this wallet already exists return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, "This wallet already exists.", e.ToString())); } }
public static async Task CreateFederationWallet(int apiPortForSidechain, string walletName, string password) { var walletCreationRequest = new WalletCreationRequest() { Name = walletName, Password = password }; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var uri = new Uri( $"http://localhost:{apiPortForSidechain}/api/generalpurposewallet/create"); var request = new JsonContent(walletCreationRequest); var httpResponseMessage = await client.PostAsync(uri, request); string json = await httpResponseMessage.Content.ReadAsStringAsync(); return;// JsonConvert.DeserializeObject<string>(json); } }
public async Task <IActionResult> Create([FromBody] WalletCreationRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(await this.Execute(request, cancellationToken, async (req, token) => this.Json(await this.walletService.CreateWallet(req, token)))); }