Exemplo n.º 1
0
        public async Task <IActionResult> Get(
            [FromQuery] string continuation,
            [FromQuery] int take)
        {
            // until ASP.NET Core 2.1 data annotations on arguments do not work
            if (take <= 0)
            {
                ModelState.AddModelError(nameof(take), "Must be greater than zero");
            }

            // kinda specific knowledge but there is no
            // another way to ensure continuation token
            if (!string.IsNullOrEmpty(continuation))
            {
                try
                {
                    JsonConvert.DeserializeObject <TableContinuationToken>(Utils.HexToString(continuation));
                }
                catch
                {
                    ModelState.AddModelError(nameof(continuation), "Invalid continuation token");
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.ToBlockchainErrorResponse()));
            }

            var result = await _blockchainService.GetBalancesAsync(continuation, take);

            return(Ok(PaginationResponse.From(
                          result.continuation,
                          result.items.Select(b => b.ToWalletContract()).ToArray())));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetBalances([FromQuery] int take, [FromQuery] string continuation)
        {
            if (take < 1)
            {
                throw new ValidationApiException($"{nameof(take)} must be positive non zero integer");
            }

            if (!string.IsNullOrEmpty(continuation))
            {
                try
                {
                    JsonConvert.DeserializeObject <TableContinuationToken>(Utils.HexToString(continuation));
                }
                catch (JsonReaderException)
                {
                    throw new ValidationApiException($"{nameof(continuation)} must be valid continuation token");
                }
            }

            var padedResult = await _balanceService.GetBalancesAsync(take, continuation);

            return(Ok(PaginationResponse.From(padedResult.Continuation, padedResult.Items.Select(p =>
                                                                                                 new WalletBalanceContract
            {
                Address = p.Address,
                Balance = p.Balance.ToString(CultureInfo.InvariantCulture),
                AssetId = p.AssetId,
                Block = p.UpdatedAtBlockHeight
            }).ToList().AsReadOnly())));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetBalances([FromQuery] int take, [FromQuery] string continuation)
        {
            if (take <= 0)
            {
                ModelState.AddModelError(nameof(take), "Must be greater than zero");
            }

            ModelState.IsValidContinuationToken(continuation);


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.ToErrorResponce()));
            }

            var padedResult = await _balanceService.GetBalances(take, continuation);

            return(Ok(PaginationResponse.From(padedResult.Continuation, padedResult.Items.Select(p => new WalletBalanceContract
            {
                Address = p.Address,
                Balance = MoneyConversionHelper.SatoshiToContract(p.BalanceSatoshi),
                AssetId = Constants.Assets.LiteCoin.AssetId,
                Block = p.UpdatedAtBlockHeight
            }).ToList().AsReadOnly())));
        }
        public IActionResult GetAssetList(
            [FromQuery] string continuation,
            [FromQuery] int take)
        {
            // until ASP.NET Core 2.1 data annotations on arguments do not work
            if (take <= 0)
            {
                ModelState.AddModelError(nameof(take), "Must be greater than zero");
            }

            // kinda specific knowledge but there is no
            // another way to ensure continuation token
            if (!string.IsNullOrEmpty(continuation))
            {
                try
                {
                    JsonConvert.DeserializeObject <TableContinuationToken>(CommonUtils.HexToString(continuation));
                }
                catch
                {
                    ModelState.AddModelError(nameof(continuation), "Invalid continuation token");
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.ToBlockchainErrorResponse()));
            }

            return(Ok(PaginationResponse.From(null,
                                              Constants.Assets.Values.Select(v => v.ToAssetContract()).ToArray())));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetBalances([FromQuery, Required] int take, [FromQuery] string continuation)
        {
            if (take < 1)
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("take", "Must be positive non zero integer")));
            }
            if (!string.IsNullOrEmpty(continuation))
            {
                try
                {
                    JsonConvert.DeserializeObject <TableContinuationToken>(Utils.HexToString(continuation));
                }
                catch (JsonReaderException)
                {
                    return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("continuation", "Must be valid continuation token")));
                }
            }

            var padedResult = await _balanceService.GetBalances(take, continuation);

            return(Ok(PaginationResponse.From(padedResult.Continuation, padedResult.Items.Select(p => new WalletBalanceContract
            {
                Address = p.Address,
                Balance = MoneyConversionHelper.SatoshiToContract(p.BalanceSatoshi),
                AssetId = Constants.Assets.BitcoinGold.AssetId,
                Block = p.UpdatedAtBlockHeight
            }).ToList().AsReadOnly())));
        }
        public async Task <PaginationResponse <WalletBalanceContract> > Get([Required, FromQuery] int take, [FromQuery] string continuation)
        {
            var result = await _balancePositiveRepository.GetAsync(take, continuation);

            return(PaginationResponse.From(
                       result.ContinuationToken,
                       result.Entities.Select(f => f.ToWalletBalanceContract()).ToArray()
                       ));
        }
        public IActionResult GetPaged([FromQuery] int take, [FromQuery] string continuation)
        {
            if (!ModelState.IsValid ||
                !ModelState.IsValidContinuationToken(continuation) ||
                !ModelState.IsValidTakeParameter(take))
            {
                return(BadRequest(ErrorResponseFactory.Create(ModelState)));
            }

            return(Ok(PaginationResponse.From(null, Storage.Take(take).ToList())));
        }
        public IActionResult Get([Required, FromQuery] int take, [FromQuery] string continuation)
        {
            if (take <= 0)
            {
                return(BadRequest());
            }

            var assets = new AssetResponse[] { Asset.Dynamic.ToAssetResponse() };

            return(Ok(PaginationResponse.From("", assets)));
        }
Exemplo n.º 9
0
        public async Task <PaginationResponse <AssetResponse> > GetPaged([FromQuery] int take, [FromQuery] string continuation)
        {
            var paginationResult = await _assetRepository.GetPaged(take, continuation);

            return(PaginationResponse.From(paginationResult.Continuation, paginationResult.Items.Select(p => new AssetResponse
            {
                Address = p.Address,
                AssetId = p.AssetId,
                Accuracy = p.Accuracy,
                Name = p.Name
            }).ToList().AsReadOnly()));
        }
        public PaginationResponse <AssetResponse> GetAssets([FromQuery] int?take, [FromQuery] string continuation)
        {
            if (take == null || take < 1)
            {
                throw new BusinessException(ErrorReason.BadRequest, "Invalid take parameter");
            }
            if (continuation != null)
            {
                throw new BusinessException(ErrorReason.BadRequest, "Continuation token not expected at this endpoint");
            }

            return(PaginationResponse.From(null, new [] { _assetResponse }));
        }
Exemplo n.º 11
0
        public IActionResult Get([Required, FromQuery] string take, [FromQuery] string continuation)
        {
            if (!int.TryParse(take, out var takeInt))
            {
                ModelState.AddModelError(nameof(take), "Should be integer.");

                return(BadRequest(ModelState));
            }

            var assets = new AssetResponse[] { Asset.Dash.ToAssetResponse() };

            return(Ok(PaginationResponse.From("", assets)));
        }
        public IActionResult Get([Required, FromQuery] int take, [FromQuery] string continuation)
        {
            if (take < 1)
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("take", "Must be positive non zero integer")));
            }
            if (!string.IsNullOrEmpty(continuation))
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("continuation", "Continuation token not supported")));
            }

            var assets = new [] { _blockchainAssetsService.GetNativeAsset().ToAssetResponse() };

            return(Ok(PaginationResponse.From("", assets)));
        }
Exemplo n.º 13
0
        public IActionResult Get([Required, FromQuery] int take, [FromQuery] string continuation)
        {
            if (take < 1)
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("take", "Must be positive non zero integer")));
            }
            if (!string.IsNullOrEmpty(continuation))
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("continuation", "Must be valid continuation token")));
            }

            var assets = new AssetResponse[] { Asset.Stellar.ToAssetResponse() };

            return(Ok(PaginationResponse.From("", assets)));
        }
Exemplo n.º 14
0
        public async Task <PaginationResponse <WalletBalanceContract> > GetBalances([FromQuery] int take, [FromQuery] string continuation)
        {
            if (take <= 0)
            {
                throw new BusinessException("Take must be greater than zero", ErrorCode.BadInputParameter);
            }
            var padedResult = await _balanceService.GetBalances(take, continuation);

            return(PaginationResponse.From(padedResult.Continuation, padedResult.Items.Select(p => new WalletBalanceContract
            {
                Address = p.Address,
                Balance = MoneyConversionHelper.SatoshiToContract(p.BalanceSatoshi),
                AssetId = Constants.Assets.Vertcoin.AssetId
            }).ToList().AsReadOnly()));
        }
        public async Task <IActionResult> Get([Required, FromQuery] string take, [FromQuery] string continuation)
        {
            if (!int.TryParse(take, out var takeInt))
            {
                ModelState.AddModelError(nameof(take), "Should be integer.");

                return(BadRequest(ModelState));
            }

            var result = await _balancePositiveRepository.GetAsync(takeInt, continuation);

            return(Ok(PaginationResponse.From(
                          result.ContinuationToken,
                          result.Entities.Select(f => f.ToWalletBalanceContract()).ToArray())));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> GetPaged([FromQuery] int take, [FromQuery] string continuation)
        {
            if (!ModelState.IsValid ||
                !ModelState.IsValidContinuationToken(continuation) ||
                !ModelState.IsValidTakeParameter(take))
            {
                return(BadRequest(ModelState.ToErrorResponce()));
            }

            var paginationResult = await _assetRepository.GetPaged(take, continuation);

            return(Ok(PaginationResponse.From(paginationResult.Continuation, paginationResult.Items.Select(p => new AssetResponse
            {
                Address = p.Address,
                AssetId = p.AssetId,
                Accuracy = p.Accuracy,
                Name = p.Name
            }).ToArray())));
        }
        public async Task <IActionResult> GetPaged([FromQuery, Required] int take, [FromQuery] string continuation)
        {
            var paginationResult = await _assetRepository.GetPaged(take, continuation);

            if (take < 1)
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("take", "Must be positive non zero integer")));
            }
            if (!string.IsNullOrEmpty(continuation))
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("continuation", "Must be valid continuation token")));
            }

            return(Ok(PaginationResponse.From(paginationResult.Continuation, paginationResult.Items.Select(p => new AssetResponse
            {
                Address = p.Address,
                AssetId = p.AssetId,
                Accuracy = p.Accuracy,
                Name = p.Name
            }).ToList().AsReadOnly())));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> GetPaged([FromQuery] int take, [FromQuery] string continuation)
        {
            if (take < 1)
            {
                throw new ValidationApiException($"{nameof(take)} must be positive non zero integer");
            }

            var skip = 0;

            if (!string.IsNullOrEmpty(continuation) && !int.TryParse(continuation, out skip))
            {
                throw new ValidationApiException($"{nameof(continuation)} must be valid continuation token");
            }

            var paginationResult = await _assetRepository.GetPagedAsync(take, skip);

            return(Ok(PaginationResponse.From(paginationResult.Continuation, paginationResult.Items.Select(p =>
                                                                                                           new AssetResponse
            {
                AssetId = p.AssetId,
                Accuracy = p.Accuracy,
                Name = p.Name
            }).ToList())));
        }
        public async Task <IActionResult> Get([Required, FromQuery] int take, [FromQuery] string continuation)
        {
            if (take < 1)
            {
                return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("take", "Must be positive non zero integer")));
            }
            if (!string.IsNullOrEmpty(continuation))
            {
                try
                {
                    JsonConvert.DeserializeObject <TableContinuationToken>(Utils.HexToString(continuation));
                }
                catch (JsonReaderException)
                {
                    return(BadRequest(ErrorResponse.Create("Invalid parameter").AddModelError("continuation", "Must be valid continuation token")));
                }
            }

            var balances = await _balanceService.GetBalancesAsync(take, continuation);

            var results = new List <WalletBalanceContract>();

            foreach (var b in balances.Wallets)
            {
                var result = new WalletBalanceContract
                {
                    Address = b.Address,
                    AssetId = b.AssetId,
                    Balance = b.Balance.ToString(),
                    Block   = b.Ledger
                };
                results.Add(result);
            }

            return(Ok(PaginationResponse.From(balances.ContinuationToken, results)));
        }
Exemplo n.º 20
0
        public PaginationResponse <AssetResponse> Get([Required, FromQuery] int take, [FromQuery] string continuation)
        {
            var assets = new AssetResponse[] { Asset.Dynamic.ToAssetResponse() };

            return(PaginationResponse.From("", assets));
        }
Exemplo n.º 21
0
        public async Task <ActionResult <PaginationResponse <WalletBalanceContract> > > Get(int take, string continuation)
        {
            if (take <= 0)
            {
                return(BadRequest(BlockchainErrorResponse.Create("'take' must be grater than zero")));
            }

            if (!Validators.ValidateAzureContinuation(continuation))
            {
                return(BadRequest(BlockchainErrorResponse.Create("'continuation' must be null or valid Azure continuation token")));
            }

            IEnumerable <DepositWalletBalanceEntity> balances;

            if (_api.CanGetBalances)
            {
                // to be able to enroll fake transfers properly
                // we keep block number increased by one order of magnitude
                var lastConfirmedBlock = await _api.GetLastConfirmedBlockNumberAsync() * 10;

                var depositWallets = await _depositWallets.GetWalletsAsync(take, continuation);

                var addresses = depositWallets.items.Select(w => w.Address).ToArray();

                continuation = depositWallets.continuation;
                balances     = (await _api.GetBalancesAsync(addresses, async assetId => await _assets.GetAsync(assetId)))
                               .Select(b => new DepositWalletBalanceEntity(b.Address, b.AssetId)
                {
                    Amount      = b.Amount,
                    BlockNumber = lastConfirmedBlock
                });
            }
            else
            {
                (balances, continuation) =
                    await _depositWallets.GetBalanceAsync(take, continuation);
            }

            var result = new List <WalletBalanceContract>();

            foreach (var balance in balances)
            {
                // blockchain may return unknown assets,
                // filter out such items

                var accuracy = (await _assets.GetAsync(balance.AssetId))?.Accuracy;
                if (accuracy == null)
                {
                    continue;
                }

                result.Add(new WalletBalanceContract
                {
                    Address = balance.Address,
                    AssetId = balance.AssetId,
                    Balance = Conversions.CoinsToContract(balance.Amount, accuracy.Value),
                    Block   = balance.BlockNumber
                });
            }

            return(PaginationResponse.From(continuation, result));
        }