/// <summary>
        /// Creates the Wallet.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> CreateWallet(CreateWalletRequest request)
        {
            try
            {
                var client = httpClientFactory.CreateClient(WalletServiceOperation.serviceName);

                var         param       = JsonConvert.SerializeObject(request);
                HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(servicesConfig.Wallet + WalletServiceOperation.CreateWallet(), contentPost);

                if (response.IsSuccessStatusCode)
                {
                    var wallet = JsonConvert.DeserializeObject <WalletResponse>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse(wallet, HttpStatusCode.Created));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateWallet()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
        public void PostCreateWalletClientId(string _userId)
        {
            CreateWalletRequest createWalletRequest = new CreateWalletRequest().GetTestModel(_userId);
            var postWalletPesp = lykkeApi.ClientAccount.Wallets.PostCreateWallet(createWalletRequest);

            Assert.That(postWalletPesp.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public void PostWalletWithoutTypeTest()
        {
            var walletId = "";

            Step("Make POST /api/wallets and validate response ", () =>
            {
                var model = new CreateWalletRequest
                {
                    Description = "Wallet created during test",
                    Name        = "Autotest wallet.Remove me"
                };
                var response = apiV2.wallets.PostWallets(model, token);

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

                walletId = response.GetResponseObject().Id;
            });

            if (walletId != "")
            {
                Step($"Make DELETE /api/wallets/{walletId} and remove wallet", () =>
                {
                    var response = apiV2.wallets.DeleteWallet(walletId, token);
                });
            }
        }
        public void DeleteWalletIdInvalidTokenTest()
        {
            var walletId = "";

            Step("Make POST /api/wallets and validate response ", () =>
            {
                var model = new CreateWalletRequest
                {
                    Description = "Wallet created during test",
                    Name        = "Autotest wallet.Remove me",
                    Type        = WalletType.Trading
                };
                var response = apiV2.wallets.PostWallets(model, token);

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

                walletId = response.GetResponseObject().Id;
            });

            Step($"Make DELETE /api/wallets/{walletId} with invalid token and validate", () =>
            {
                var response = apiV2.wallets.DeleteWallet(walletId, Guid.NewGuid().ToString());
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            });

            Step($"Make DELETE /api/wallets/{walletId} and remove wallet", () =>
            {
                var response = apiV2.wallets.DeleteWallet(walletId, token);
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            });
        }
        public async Task <Response> MobileCheckIn(string organisationId, MobileUpdateCountRequest payload)
        {
            var walletRequest = new CreateWalletRequest
            {
                MobileNumber = payload.MobileNumber
            };

            var wallet = await _walletService.CreateWallet(walletRequest, true);

            var session = await _sessionService.CreateSession(payload.MobileNumber, wallet);

            var organisation = await _organisationRepository.GetAsync(Guid.Parse(organisationId));

            if (organisation == default)
            {
                throw new NotFoundException(Messages.Org_NotExists);
            }

            await _smsService.SendWelcomeSms(payload.MobileNumber, organisation.Name, session.ExpireAt.Value, session.Id);

            var updateCounterRequest = new UpdateCountRequest
            {
                Latitude  = payload.Latitude,
                Longitude = payload.Longitude,
                WalletId  = wallet.Id.ToString()
            };

            var counterResponse = await UpdateCountAsync(organisationId, updateCounterRequest, ScanType.CheckIn, true);

            return(counterResponse);
        }
        }     //end of public async Task<string> CreateMnemonic(MnemomicLanguage language, MnemonicWordCount wordCount)

        /// <summary>
        /// Creates A Wallet
        /// </summary>
        /// <param name="mnemonic">Nemonic To Use</param>
        /// <param name="password">Wallet Password</param>
        /// <param name="passphrase">Wallet Passphrase</param>
        /// <param name="name"></param>
        /// <returns>MNemonic Used To Create The Wallet</returns>
        public async Task <string> CreateWallet(string mnemonic, string password, string name, string passphrase = "")
        {
            try
            {
                if (string.IsNullOrWhiteSpace(passphrase))
                {
                    passphrase = password;
                }

                Guard.Null(mnemonic, nameof(mnemonic), "mnemonic Cannot Be NULL/Empty!");
                Guard.Null(password, nameof(password), "Wallet Password Cannot Be NULL/Empty!");
                Guard.Null(name, nameof(name), "Wallet Name Cannot Be NULL/Empty!");

                CreateWalletRequest request = new CreateWalletRequest
                {
                    name       = name,
                    passphrase = passphrase,
                    password   = password,
                    mnemonic   = mnemonic
                };

                string response = await base.SendPostJSON <string>("api/Wallet/create", request);

                Guard.Null(response, nameof(response), "'api/Wallet/create' API Response Was Null!");

                return(response);
            }
            catch (Exception ex)
            {
                Logger.Fatal($"An Error '{ex.Message}' Occured When Creating Wallet '{name}'", ex);
                throw;
            } //end of try-catch
        }     //end of public async Task<string> CreateWallet(string mnemonic, string password, string passphrase, string name)
        public async Task <TokenResponse> CreateWalletAndOtp(CreateWalletRequest walletRequest, string sessionId)
        {
            Wallet wallet;

            if (sessionId == null)
            {
                wallet = await CreateWallet(walletRequest);
            }
            else
            {
                wallet = await GetWallet(sessionId);

                _cryptoService.DecryptAsServer(wallet);

                wallet.MobileNumberReference = walletRequest.MobileNumberReference;
                wallet.MobileNumber          = wallet.MobileNumber;

                await UpdateWallet(wallet);
            }

            var otpId = await _otpService.GenerateAndSendOtpAsync(walletRequest.MobileNumber);

            return(new TokenResponse
            {
                Token = _tokenService.GenerateToken(wallet.Id.ToString(), otpId)
            });
        }
        public async Task <IActionResult> CreateWallet([FromBody] CreateWalletRequest request)
        {
            var createWalletCommand = new CreateWalletCommand(request);
            var result = await mediator.Send(createWalletCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
Exemple #9
0
        public async Task <WalletApiResponse> CreateWallet(int userId, [FromBody] CreateWalletRequest createWalletRequest)
        {
            try
            {
                if (_currencyService.HasCurrencyRate(createWalletRequest.Currency))
                {
                    var newWallet = new Wallet()
                    {
                        Currency = createWalletRequest.Currency,
                        UserId   = userId
                    };
                    _context.Wallets.Add(newWallet);
                    await _context.SaveChangesAsync();

                    return(new CreateWalletResponse(newWallet));
                }
                else
                {
                    return(new WalletApiErrorResponse($"Нельзя создать кошелек с валютой {createWalletRequest.Currency}"));
                }
            }
            catch (Exception ex)
            {
                return(new WalletApiErrorResponse(ex));
            }
        }
        public HttpStatusCode PostCreateWalletName(string _walletName)
        {
            CreateWalletRequest createWalletRequest = new CreateWalletRequest().GetTestModel(userId);

            createWalletRequest.Name = _walletName;
            var postWalletPesp = lykkeApi.ClientAccount.Wallets.PostCreateWallet(createWalletRequest);

            return(postWalletPesp.StatusCode);
        }
Exemple #11
0
 public static CreateWalletRequest GetTestModel(this CreateWalletRequest wallet, string clientId, WalletType walletType = WalletType.Trusted)
 {
     return(new CreateWalletRequest()
     {
         ClientId = clientId,
         Name = TestData.GenerateString(10),
         Type = walletType,
         Description = TestData.GenerateString(15)
     });
 }
Exemple #12
0
 public async Task CreateWallet(string pubPassphrase, string privPassphrase, byte[] seed)
 {
     var client  = WalletLoaderService.NewClient(_channel);
     var request = new CreateWalletRequest
     {
         PublicPassphrase  = ByteString.CopyFromUtf8(pubPassphrase),
         PrivatePassphrase = ByteString.CopyFromUtf8(privPassphrase),
         Seed = ByteString.CopyFrom(seed),
     };
     await client.CreateWalletAsync(request, cancellationToken : _tokenSource.Token);
 }
        public void PostCreateWallet()
        {
            CreateWalletRequest createWalletRequest = new CreateWalletRequest().GetTestModel(userId);
            var postWalletPesp = lykkeApi.ClientAccount.Wallets.PostCreateWallet(createWalletRequest);
            var wallet         = postWalletPesp.GetResponseObject();

            Assert.That(wallet.Id, Is.Not.Null);
            Assert.That(wallet.Type, Is.EqualTo(createWalletRequest.Type.ToSerializedValue()));
            Assert.That(wallet.Name, Is.EqualTo(createWalletRequest.Name));
            Assert.That(wallet.Description, Is.EqualTo(createWalletRequest.Description));
        }
        public void PostWalletEmptyBodyTest()
        {
            Step("Make POST /api/wallets and validate response ", () =>
            {
                var model = new CreateWalletRequest
                {
                };
                var response = apiV2.wallets.PostWallets(model, token);

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            });
        }
        public void DeleteWallet()
        {
            var walletToCreate = new CreateWalletRequest().GetTestModel(userId);
            var createdWalet   = lykkeApi.ClientAccount.Wallets.PostCreateWallet(walletToCreate).GetResponseObject();

            var deleteWalletById = lykkeApi.ClientAccount.Wallets.DeleteWalletById(createdWalet.Id);

            Assert.That(deleteWalletById.StatusCode, Is.EqualTo(HttpStatusCode.OK));

            var getWalletById = lykkeApi.ClientAccount.Wallets.GetWalletById(createdWalet.Id);

            Assert.That(getWalletById.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public void PostWalletInvalidTokenTest()
        {
            Step("Make POST /api/wallets and validate response ", () =>
            {
                var model = new CreateWalletRequest
                {
                    Description = "Wallet created during test",
                    Name        = "Autotest wallet.Remove me",
                    Type        = WalletType.Trading
                };
                var response = apiV2.wallets.PostWallets(model, Guid.NewGuid().ToString());

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            });
        }
Exemple #17
0
        public async Task <bool> CreateWallet(string walletName, string password, string accountName)
        {
            //api/Wallet/create
            var    baseUrl        = ConfigurationManager.AppSettings["StratisBlockChainBaseUrl"];
            string mnemonicResult = await CreateMnemonic();

            mnemonicResult = mnemonicResult.Trim('"');
            var crateWalletRequest = new CreateWalletRequest {
                name = walletName, password = password, mnemonic = mnemonicResult, passphrase = password
            };
            var createWalletUrl = baseUrl + ConfigurationManager.AppSettings["CreateWalletUrl"];
            var result          = await GetSetHttpClient.PostAsJsonAsync <CreateWalletRequest>(createWalletUrl, crateWalletRequest);

            return(result.StatusCode == System.Net.HttpStatusCode.OK);
        }
        public void GetWallet()
        {
            var walletToCreate = new CreateWalletRequest().GetTestModel(userId);
            var createdWalet   = lykkeApi.ClientAccount.Wallets.PostCreateWallet(walletToCreate).GetResponseObject();

            var getWalletById = lykkeApi.ClientAccount.Wallets.GetWalletById(createdWalet.Id);

            Assert.That(getWalletById.StatusCode, Is.EqualTo(HttpStatusCode.OK));

            var recievedWallet = getWalletById.GetResponseObject();

            Assert.That(recievedWallet.Id, Is.EqualTo(createdWalet.Id));
            Assert.That(recievedWallet.Name, Is.EqualTo(createdWalet.Name));
            Assert.That(recievedWallet.Type, Is.EqualTo(createdWalet.Type));
            Assert.That(recievedWallet.Description, Is.EqualTo(createdWalet.Description));
        }
Exemple #19
0
        public async Task <Wallet> CreateWallet(CreateWalletRequest walletRequest, bool mobile = false)
        {
            var wallet = new Wallet
            {
                CreatedAt             = DateTime.UtcNow,
                MobileNumber          = walletRequest.MobileNumber,
                MobileNumberReference = walletRequest?.MobileNumberReference
            };

            _cryptoService.EncryptAsServer(wallet, mobile);

            await _walletRepository.AddAsync(wallet);

            await _walletRepository.SaveAsync();

            return(wallet);
        }
        public void PutWallet()
        {
            var walletToCreate = new CreateWalletRequest().GetTestModel(userId);
            var createdWalet   = lykkeApi.ClientAccount.Wallets.PostCreateWallet(walletToCreate).GetResponseObject();

            var newWallet = new ModifyWalletRequest().GetTestModel();

            var putWalletById = lykkeApi.ClientAccount.Wallets.PutWalletById(createdWalet.Id, newWallet);

            Assert.That(putWalletById.StatusCode, Is.EqualTo(HttpStatusCode.OK));

            var changedWallet = lykkeApi.ClientAccount.Wallets.GetWalletById(createdWalet.Id).GetResponseObject();

            //Have not to change
            Assert.That(changedWallet.Id, Is.EqualTo(createdWalet.Id));
            Assert.That(changedWallet.Type, Is.EqualTo(createdWalet.Type));
            //Have to be changed
            Assert.That(changedWallet.Name, Is.EqualTo(newWallet.Name));
            Assert.That(changedWallet.Description, Is.EqualTo(newWallet.Description));
        }
        public void GetWalletsOfTypeForClientTest()
        {
            //create new client
            var client           = new AccountRegistrationModel().GetTestModel();
            var registeredclient = lykkeApi.Registration.PostRegistration(client);
            var clientId         = registeredclient.Account.Id;

            lykkeApi.ClientAccount.ClientAccountInformation.PostSetPIN(clientId, "1111");

            //Create 3 wallets
            var tradingWallet1 = new CreateWalletRequest().GetTestModel(clientId);

            tradingWallet1.Type = WalletType.Trading;
            var trustedWallet2 = new CreateWalletRequest().GetTestModel(clientId);

            trustedWallet2.Type = WalletType.Trusted;
            var trustedWallet3 = new CreateWalletRequest().GetTestModel(clientId);

            trustedWallet3.Type = WalletType.Trusted;

            var createdTradingWallet1 = lykkeApi.ClientAccount.Wallets
                                        .PostCreateWallet(tradingWallet1).GetResponseObject();
            var createdTrustedWalet2 = lykkeApi.ClientAccount.Wallets
                                       .PostCreateWallet(trustedWallet2).GetResponseObject();
            var createdTrustedWalet3 = lykkeApi.ClientAccount.Wallets
                                       .PostCreateWallet(trustedWallet3).GetResponseObject();

            var tradingWallets = lykkeApi.ClientAccount.Wallets
                                 .GetWalletsForClientByType(clientId, WalletType.Trading).GetResponseObject();

            var trustedWallets = lykkeApi.ClientAccount.Wallets
                                 .GetWalletsForClientByType(clientId, WalletType.Trusted).GetResponseObject();

            Assert.That(tradingWallets.Select(w => w.Id),
                        Does.Contain(createdTradingWallet1.Id));

            Assert.That(trustedWallets.Select(w => w.Id),
                        Does.Contain(createdTrustedWalet2.Id).And.Contain(createdTrustedWalet3.Id));
        }
Exemple #22
0
        /// <summary>
        /// Creates a new Blockchain.info wallet if the user's API code has the 'generate wallet' permission.
        /// It can be created containing a pre-generated private key or will otherwise generate a new private key.
        /// </summary>
        /// <param name="password">Password for the new wallet. At least 10 characters.</param>
        /// <param name="privateKey">Private key to add to the wallet</param>
        /// <param name="label">Label for the first address in the wallet</param>
        /// <param name="email">Email to associate with the new wallet</param>
        /// <returns>An instance of the CreateWalletResponse class</returns>
        /// <exception cref="ServerApiException">If the server returns an error</exception>
        public async Task <CreateWalletResponse> CreateAsync(string password, string privateKey = null, string label = null, string email = null, bool hd = false)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password));
            }
            if (string.IsNullOrWhiteSpace(httpClient.ApiCode))
            {
                throw new ArgumentNullException("Api code must be specified", innerException: null);
            }

            var request = new CreateWalletRequest {
                Password   = password,
                ApiCode    = httpClient.ApiCode,
                PrivateKey = privateKey,
                Label      = label,
                Email      = email,
                HD         = hd
            };

            return(await httpClient.PostAsync <CreateWalletRequest, CreateWalletResponse>("api/v2/create/", request, contentType : "application/json"));
        }
Exemple #23
0
        public async Task <IActionResult> CreateWallet([FromBody] CreateWalletRequest walletParameters)
        {
            var response = await _walletService.CreateWalletAndOtp(walletParameters, null);

            return(Ok(new Response(response, HttpStatusCode.OK)));
        }
Exemple #24
0
 public async Task CreateWallet(string pubPassphrase, string privPassphrase, byte[] seed)
 {
     var client = new WalletLoaderService.WalletLoaderServiceClient(_channel);
     var request = new CreateWalletRequest
     {
         PublicPassphrase = ByteString.CopyFromUtf8(pubPassphrase),
         PrivatePassphrase = ByteString.CopyFromUtf8(privPassphrase),
         Seed = ByteString.CopyFrom(seed),
     };
     await client.CreateWalletAsync(request, cancellationToken: _tokenSource.Token);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateWalletCommand"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 public CreateWalletCommand(CreateWalletRequest request)
 {
     Request = request;
 }
Exemple #26
0
        //[Authorize(Roles = "Admin, Vendor")]
        public async Task <IActionResult> CreateWallet([FromBody] CreateWalletRequest request)
        {
            var result = await walletService.CreateWallet(request);

            return(StatusCode((int)result.Code, result.Value));
        }
 public Task <CreateWalletResponse> CreateWalletAsync(CreateWalletRequest request)
 {
     return(_grpcService.CreateWalletAsync(request));
 }
 public IResponse <WalletModel> PostWallets(CreateWalletRequest request, string authorization) =>
 Request.Post("/wallets").AddJsonBody(request).WithBearerToken(authorization).Build().Execute <WalletModel>();
Exemple #29
0
        public async Task <JsonResult> Create([FromBody] CreateWalletRequest request)
        {
            var result = await WalletServiceWrapper.CreateWallet(InjectAuthorization(request));

            return(new JsonResult(result));
        }
Exemple #30
0
 public IResponse <WalletDto> PostCreateWallet(CreateWalletRequest wallet)
 {
     return(Request.Post("api/Wallets").AddJsonBody(wallet).Build().Execute <WalletDto>());
 }
Exemple #31
0
        public async Task <CreateWalletResponse> CreateWalletAsync(CreateWalletRequest request)
        {
            using var _ = MyTelemetry.StartActivity($"Create a new wallet");
            request.Name.AddToActivityAsTag("wallet-name");
            request.ClientId.ClientId.AddToActivityAsTag("clientId");
            request.ClientId.BrokerId.AddToActivityAsTag("brokerId");

            _logger.LogInformation("Request to create wallet. Request: {requestText}", JsonSerializer.Serialize(request));

            if (string.IsNullOrEmpty(request.ClientId?.ClientId) ||
                string.IsNullOrEmpty(request.ClientId?.BrokerId) ||
                string.IsNullOrEmpty(request.Name) ||
                string.IsNullOrWhiteSpace(request.BaseAsset))
            {
                _logger.LogError("Cannot create wallet. BadRequest.");
                return(new CreateWalletResponse()
                {
                    Success = false,
                    ErrorMessage = "Bad request"
                });
            }

            var index = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            var wallet = new ClientWallet()
            {
                IsDefault         = false,
                IsInternal        = false,
                EnableEarnProgram = true,
                Name             = request.Name,
                WalletId         = $"{Program.Settings.WalletPrefix}{request.ClientId.ClientId}-{index}",
                CreatedAt        = DateTime.UtcNow,
                BaseAsset        = request.BaseAsset,
                EnableUseTestNet = Program.Settings.EnableUseTestNetByDefault
            };

            wallet.WalletId.AddToActivityAsTag("walletId");

            var entity = new ClientWalletEntity(request.ClientId.BrokerId, request.ClientId.ClientId, wallet);

            await using var ctx = new DatabaseContext(_dbContextOptionsBuilder.Options);
            await ctx.ClientWallet.AddAsync(entity);

            await ctx.SaveChangesAsync();

            var list = await ctx.ClientWallet
                       .Where(e => e.ClientId == request.ClientId.ClientId && e.BrokerId == request.ClientId.BrokerId)
                       .ToListAsync();

            await UpdateCache(request.ClientId.ClientId, request.ClientId.BrokerId, list);

            _logger.LogInformation("Wallet created. Wallet: {walletJson}", JsonSerializer.Serialize(entity));

            return(new CreateWalletResponse()
            {
                Success = true,
                Name = request.Name,
                WalletId = wallet.WalletId,
                CreatedAt = wallet.CreatedAt
            });
        }