Ejemplo n.º 1
0
        public override Task <WalletsResponse> GetWallets(Empty request, ServerCallContext context)
        {
            var resp = new WalletsResponse();

            resp.Result = new WalletsResponse.Types.GetWalletsPayload()
            {
                Lykke = new WalletsResponse.Types.LykkeWalletsPayload()
                {
                    Equity = "10000",
                    Assets =
                    {
                        new WalletsResponse.Types.WalletAsset()
                        {
                            Id           = "BTC",
                            AssetPairId  = "BTCUSD",
                            Symbol       = "BTC",
                            Balance      = "1",
                            Reserved     = "0",
                            Accuracy     = 4,
                            AmountInBase = "10000",
                            Name         = "Bitcoin",
                            CategoryId   = "Crypto",
                            HideIfZero   = false,
                            IssuerId     = "market"
                        }
                    }
                }
            };


            return(Task.FromResult(resp));
        }
Ejemplo n.º 2
0
        public override async Task <WalletsResponse> GetWallets(Empty request, ServerCallContext context)
        {
            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WalletsGetAsync(token);

            var result = new WalletsResponse();

            if (response.Result != null)
            {
                result.Body = new WalletsResponse.Types.Body
                {
                    Lykke = new WalletsResponse.Types.LykkeWalletsPayload {
                        Equity = response.Result.Lykke.Equity.ToString(CultureInfo.InvariantCulture)
                    },
                    MultiSig         = response.Result.MultiSig,
                    ColoredMultiSig  = response.Result.ColoredMultiSig,
                    SolarCoinAddress = response.Result.SolarCoinAddress
                };

                result.Body.Lykke.Assets.AddRange(_mapper.Map <List <WalletsResponse.Types.WalletAsset> >(response.Result.Lykke.Assets));
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetWallets([FromRoute] Guid clientId, [FromQuery] int take, [FromQuery] string continuationToken)
        {
            if (take <= 0)
            {
                return(BadRequest(BlockchainWalletsErrorResponse.Create($"{nameof(take)} must be integer greater than 0.")));
            }

            if (!ValidateRequest(out var badRequest,
                                 ParamsToValidate.EmptyClientId,
                                 clientId: clientId))
            {
                return(badRequest);
            }

            var(wallets, token) = await _walletService.GetClientWalletsAsync(clientId, take, continuationToken);

            var response = new WalletsResponse
            {
                Wallets = wallets.Select(x => new WalletResponse
                {
                    Address                 = x.Address,
                    AddressExtension        = x.AddressExtension,
                    BaseAddress             = x.BaseAddress,
                    BlockchainType          = x.BlockchainType,
                    ClientId                = x.ClientId,
                    IntegrationLayerId      = x.BlockchainType,
                    IntegrationLayerAssetId = x.AssetId,
                    CreatedBy               = x.CreatorType
                }),
                ContinuationToken = token
            };

            if (response.Wallets.Any())
            {
                return(Ok(response));
            }
            else
            {
                return(NoContent());
            }
        }
        public async Task GetClientWalletsAsync_Called__Wallets_Exists__Return_Many_ClientWalletResponse()
        {
            var clientId = Guid.Parse("25c47ff8-e31e-4913-8e02-8c2512f0111e");
            var counter  = 0;

            #region Responses

            var content1 = new WalletsResponse
            {
                ContinuationToken = "1",
                Wallets           = new[]
                {
                    new WalletResponse
                    {
                        Address                 = "0x00000000...",
                        ClientId                = clientId,
                        BlockchainType          = "EthereumClassic",
                        IntegrationLayerAssetId = "ETC"
                    }
                }
            };

            var content2 = new WalletsResponse
            {
                ContinuationToken = null,
                Wallets           = new[]
                {
                    new WalletResponse
                    {
                        Address                 = "0x00000001...",//Does not matter
                        ClientId                = clientId,
                        BlockchainType          = "LiteCoin",
                        IntegrationLayerAssetId = "LTC"
                    }
                }
            };

            #endregion

            var handlerStub = new DelegatingHandlerStub((request, cancellationToken) =>
            {
                var content = content1;
                if (counter > 0)
                {
                    content = content2;
                }

                var response = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(content))
                };

                counter++;

                return(Task.FromResult(response));
            });

            var client = CreateClient(handlerStub);

            var result = (await client.GetAllWalletsAsync(clientId, 1)).ToList();

            // ReSharper disable PossibleMultipleEnumeration
            Assert.True(result.Count() == 2);
            Assert.True(result.FirstOrDefault()?.ClientId == clientId);
            // ReSharper restore PossibleMultipleEnumeration
        }