public IActionResult CreateNewAccount([FromBody] GetUnusedAccountModel request)
        {
            Guard.NotNull(request, nameof(request));

            // checks the request is valid
            if (!this.ModelState.IsValid)
            {
                return(BuildErrorResponse(this.ModelState));
            }

            try
            {
                HdAccount result = this.walletManager.GetUnusedAccount(request.WalletName, request.Password);
                return(this.Json(result.Name));
            }
            catch (CannotAddAccountToXpubKeyWalletException e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, e.Message, string.Empty));
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
Ejemplo n.º 2
0
        private void attempting_to_add_an_account()
        {
            var request = new GetUnusedAccountModel()
            {
                WalletName = WalletName,
                Password   = WalletPassword
            };

            this.response = this.httpClient.PostAsJsonAsync($"{this.apiUri}{AccountUri}", request)
                            .GetAwaiter().GetResult();
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> CreateNewAccount([FromBody] GetUnusedAccountModel request,
                                                    CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await this.ExecuteAsAsync(request, cancellationToken, (req, token) =>
     {
         try
         {
             HdAccount result = this.walletManager.GetUnusedAccount(request.WalletName, request.Password);
             return this.Json(result.Name);
         }
         catch (CannotAddAccountToXpubKeyWalletException e)
         {
             this.Logger.LogError("Exception occurred: {0}", e.ToString());
             return ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, e.Message, string.Empty);
         }
     }));
 }
        public IActionResult CreateNewAccount([FromBody] GetUnusedAccountModel 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
            {
                var result = this.walletManager.GetUnusedAccount(request.WalletName, this.coinType, request.Password);
                return(this.Json(result.Name));
            }
            catch (Exception e)
            {
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new account for a wallet.
        /// </summary>
        /// <returns>An account name.</returns>
        public string CreateNewAccount(GetUnusedAccountModel request)
        {
            Guard.NotNull(request, nameof(request));

            // checks the request is valid
            //if (!this.ModelState.IsValid)
            //{
            //    return BuildErrorResponse(this.ModelState);
            //}

            try
            {
                var result = this.walletManager.GetUnusedAccount(request.WalletName, request.Password);
                return(result.Name);
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                //return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
                throw;
            }
        }