Пример #1
0
        private IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceCoreAsync(BalanceId balanceId, BalanceQuery query, CancellationToken cancel)
        {
            if (query == null)
            {
                query = new BalanceQuery();
            }


            var table      = Configuration.GetBalanceTable();
            var tableQuery = ExecuteBalanceQuery(table, query.CreateTableQuery(balanceId), query.PageSizes);


            var partitions =
                tableQuery
                .Select(c => new OrderedBalanceChange(c))
                .Select(c => new LoadingTransactionTask
            {
                Loaded = NeedLoading(c) ? EnsurePreviousLoadedAsync(c) : Task.FromResult(true),
                Change = c
            })
                .Partition(BalancePartitionSize);

            if (!query.RawOrdering)
            {
                return(GetOrderedBalanceCoreAsyncOrdered(partitions, cancel));
            }
            return(GetOrderedBalanceCoreAsyncRaw(partitions, cancel));
        }
Пример #2
0
        private bool MergeIntoWalletCore(string walletId, BalanceId balanceId, WalletRule rule, CancellationToken cancel)
        {
            var indexer = Configuration.CreateIndexer();

            var query = new BalanceQuery()
            {
                From        = new UnconfirmedBalanceLocator().Floor(),
                RawOrdering = true
            };
            var sourcesByKey = GetOrderedBalanceCore(balanceId, query, cancel)
                               .ToDictionary(i => GetKey(i));

            if (sourcesByKey.Count == 0)
            {
                return(false);
            }
            var destByKey =
                GetOrderedBalance(walletId, query, cancel)
                .ToDictionary(i => GetKey(i));

            List <OrderedBalanceChange> entities = new List <OrderedBalanceChange>();

            foreach (var kv in sourcesByKey)
            {
                var source   = kv.Value;
                var existing = destByKey.TryGet(kv.Key);
                if (existing == null)
                {
                    existing = new OrderedBalanceChange(walletId, source);
                }
                existing.Merge(kv.Value, rule);
                entities.Add(existing);
                if (entities.Count == 100)
                {
                    indexer.Index(entities);
                }
            }
            if (entities.Count != 0)
            {
                indexer.Index(entities);
            }
            return(true);
        }
Пример #3
0
 private IEnumerable <OrderedBalanceChange> GetOrderedBalanceCore(BalanceId balanceId, BalanceQuery query, CancellationToken cancel)
 {
     foreach (var partition in GetOrderedBalanceCoreAsync(balanceId, query, cancel))
     {
         foreach (var change in partition.Result)
         {
             yield return(change);
         }
     }
 }
Пример #4
0
 public IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceAsync(Script scriptPubKey, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(new BalanceId(scriptPubKey), query, cancel));
 }
Пример #5
0
 public IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceAsync(IDestination destination, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceAsync(destination.ScriptPubKey, query, cancel));
 }
Пример #6
0
 public IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceAsync(string walletId,
                                                                                  BalanceQuery query       = null,
                                                                                  CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(new BalanceId(walletId), query, cancel));
 }
Пример #7
0
 public IEnumerable <OrderedBalanceChange> GetOrderedBalance(BalanceId balanceId,
                                                             BalanceQuery query       = null,
                                                             CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCore(balanceId, query, cancel));
 }