public static async Task <IEnumerable <IWallet> > GetAsync(this IWalletsRepository walletsRepository, string clientId,
                                                                   IEnumerable <IAsset> assets)
        {
            var wallets = await walletsRepository.GetAsync(clientId);


            return(assets.Select(asset => wallets.FirstOrDefault(wallet => wallet.AssetId == asset.Id) ?? Wallet.Create(asset)));
        }
Esempio n. 2
0
        private async Task <IReadOnlyList <IWallet> > ReloadAllAsync(string walletId)
        {
            var result = (await _repository.GetAsync(walletId)).Select(CachedWalletModel.Create).ToArray();

            try
            {
                await _redisDatabase.HashSetAsync(
                    GetCacheKey(walletId),
                    result.Select(x => new HashEntry(x.AssetId, CacheSerializer.Serialize(x))).ToArray());

                await _redisDatabase.KeyExpireAsync(GetCacheKey(walletId), _cacheExpiration);
            }
            catch (RedisConnectionException ex)
            {
                _log.Warning("Redis cache is not available", ex);
            }

            return(result);
        }
        public static async Task <double> GetWalletBalanceAsync(this IWalletsRepository walletsRepository, string clientId, string assetId)
        {
            var entity = await walletsRepository.GetAsync(clientId, assetId);

            if (entity == null)
            {
                return(0);
            }

            return(entity.Balance);
        }