Beispiel #1
0
        private async Task <List <TxHistory> > GetBaseAddressHistory(TxDirectionType direction, string address, int take, string afterPagingToken)
        {
            var result  = new List <TxHistory>();
            var context = new TransactionContext
            {
                Cursor = afterPagingToken
            };

#pragma warning disable 1998
            async Task <bool> Process(TxDirectionType type, TxHistory history)
            {
                if (direction == type)
                {
                    result.Add(history);
                }

                return(result.Count >= take);
            }

#pragma warning restore 1998

            do
            {
                await QueryAndProcessTransactions(address, context, Process);
            }while (!string.IsNullOrEmpty(context.Cursor) && result.Count < take);

            return(result);
        }
Beispiel #2
0
        public async Task <List <TxHistory> > GetHistory(TxDirectionType direction, string address, int take, string afterHash)
        {
            var observation = await _observationRepository.GetAsync(address);

            if (observation == null)
            {
                return(new List <TxHistory>());
            }

            List <TxHistory> result;
            string           afterPagingToken = null;

            if (!string.IsNullOrEmpty(afterHash))
            {
                var tx = await _horizonService.GetTransactionDetails(afterHash);

                if (tx == null || !afterHash.Equals(tx.Hash, StringComparison.OrdinalIgnoreCase))
                {
                    throw new BusinessException($"No transaction found. hash={afterHash}");
                }
                afterPagingToken = tx.PagingToken;
            }

            if (_balanceService.IsDepositBaseAddress(address))
            {
                result = await GetDepositBaseHistory(direction, address, take, afterPagingToken);
            }
            else
            {
                result = await GetBaseAddressHistory(direction, address, take, afterPagingToken);
            }

            return(result);
        }
Beispiel #3
0
        public async Task InsertOrReplaceAsync(TxDirectionType direction, TxHistory history)
        {
            var table = GetTable(direction);

            // history entry
            var entity = history.ToEntity();
            await table.InsertOrReplaceAsync(entity);
        }
Beispiel #4
0
        public async Task <List <TxHistory> > GetHistory(TxDirectionType direction, string address, int take, string afterHash)
        {
            var observation = await _observationRepository.GetAsync(address);

            if (observation != null)
            {
                var result = await _txHistoryRepository.GetAllAfterHashAsync(observation.TableId, direction, take, afterHash);

                return(result);
            }

            return(new List <TxHistory>());
        }
Beispiel #5
0
        private async Task <List <TxHistory> > GetDepositBaseHistory(TxDirectionType direction, string address, int take, string afterPagingToken)
        {
            string afterKey = null;

            if (afterPagingToken != null)
            {
                afterKey = TxHistory.GetKey(afterPagingToken, 999);
            }

            var memo   = _balanceService.GetPublicAddressExtension(address);
            var result = await _txHistoryRepository.GetAllAfterHashAsync(direction, memo, take, afterKey);

            return(result);
        }
Beispiel #6
0
        public async Task <List <TxHistory> > GetAllAfterHashAsync(TxDirectionType direction, string memo, int take, string afterKey)
        {
            // memo on transaction is assigned to destination
            if (direction == TxDirectionType.Outgoing && !string.IsNullOrEmpty(memo))
            {
                return(new List <TxHistory>());
            }

            var table = GetTable(direction);

            // build filter
            string filter = null;

            if (!string.IsNullOrEmpty(afterKey))
            {
                filter = TableQuery.GenerateFilterCondition(nameof(ITableEntity.PartitionKey), QueryComparisons.GreaterThan, afterKey);
            }
            if (!string.IsNullOrEmpty(memo))
            {
                var rkFilter = TableQuery.GenerateFilterCondition(nameof(ITableEntity.RowKey), QueryComparisons.Equal, memo);
                filter = filter != null?TableQuery.CombineFilters(filter, TableOperators.And, rkFilter) : rkFilter;
            }

            var query = new TableQuery <TxHistoryEntity>();

            if (filter != null)
            {
                query = query.Where(filter);
            }
            query = query.Take(take);
            var data = await table.GetDataWithContinuationTokenAsync(query, null);

            var items = data.Entities.ToDomain();

            return(items);
        }
Beispiel #7
0
 private INoSQLTableStorage <TxHistoryEntity> GetTable(TxDirectionType direction)
 {
     return(direction == TxDirectionType.Incoming ? _tableIn : _tableOut);
 }
Beispiel #8
0
 private static string GetPartitionKey(TxDirectionType direction) => direction.ToString();
Beispiel #9
0
        private async Task <bool> SaveTransactionHistory(TxDirectionType direction, TxHistory history)
        {
            await _txHistoryRepository.InsertOrReplaceAsync(direction, history);

            return(false);
        }