示例#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, ConsensusFactory))
                .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);
        }
        private async Task <ICollection <OrderedBalanceChange> > GetOrderedBalanceCoreAsync(BalanceId balanceId, BalanceQuery query, CancellationToken cancel)
        {
            if (query == null)
            {
                query = new BalanceQuery();
            }

            var result = new List <OrderedBalanceChange>();

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


            var partitions =
                tableQuery
                .Select(c => new OrderedBalanceChange(c, ConsensusFactory))
                .Partition(BalancePartitionSize, cancel);

            var enumerator = await partitions.GetAsyncEnumeratorAsync(cancel);

            while (await enumerator.MoveNextAsync(cancel))
            {
                var partition = enumerator.Current;
                await Task.WhenAll(partition.Select(c => NeedLoading(c) ? EnsurePreviousLoadedAsync(c) : Task.FromResult <bool>(true)));

                foreach (var entity in partition)
                {
                    if (Prepare(entity))
                    {
                        result.Add(entity);
                    }
                }
            }
            if (query.RawOrdering)
            {
                return(result);
            }
            result = result.TopologicalSort();
            result.Reverse();
            return(result);
        }
 public IEnumerable<Task<List<OrderedBalanceChange>>> GetOrderedBalanceAsync(IDestination destination, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return GetOrderedBalanceAsync(destination.ScriptPubKey, query, cancel);
 }
 public IEnumerable<Task<List<OrderedBalanceChange>>> GetOrderedBalanceAsync(string walletId,
                                                           BalanceQuery query = null,
                                                           CancellationToken cancel = default(CancellationToken))
 {
     return GetOrderedBalanceCoreAsync(new BalanceId(walletId), query, cancel);
 }
 public IEnumerable<Task<List<OrderedBalanceChange>>> GetOrderedBalanceAsync(BalanceId balanceId,
                                                           BalanceQuery query = null,
                                                           CancellationToken cancel = default(CancellationToken))
 {
     return GetOrderedBalanceCoreAsync(balanceId, query, cancel);
 }
 public IEnumerable<OrderedBalanceChange> GetOrderedBalance(BalanceId balanceId,
                                                           BalanceQuery query = null,
                                                           CancellationToken cancel = default(CancellationToken))
 {
     return GetOrderedBalanceCore(balanceId, query, cancel);
 }
 public Task <ICollection <OrderedBalanceChange> > GetOrderedBalanceAsync(BalanceId balanceId,
                                                                          BalanceQuery query       = null,
                                                                          CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(balanceId, query, cancel));
 }
        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);
        }
示例#10
0
 public IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceAsync(Script scriptPubKey, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(new BalanceId(scriptPubKey), query, cancel));
 }
示例#11
0
 public IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceAsync(IDestination destination, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceAsync(destination.ScriptPubKey, query, cancel));
 }
示例#12
0
 public IEnumerable <Task <List <OrderedBalanceChange> > > GetOrderedBalanceAsync(string walletId,
                                                                                  BalanceQuery query       = null,
                                                                                  CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(new BalanceId(walletId), query, cancel));
 }
示例#13
0
 public IEnumerable <OrderedBalanceChange> GetOrderedBalance(BalanceId balanceId,
                                                             BalanceQuery query       = null,
                                                             CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCore(balanceId, query, cancel));
 }
 public Task <ICollection <OrderedBalanceChange> > GetOrderedBalance(Script scriptPubKey, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(new BalanceId(scriptPubKey), query, cancel));
 }
 public Task <ICollection <OrderedBalanceChange> > GetOrderedBalanceAsync(IDestination destination, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceAsync(destination.ScriptPubKey, query, cancel));
 }
 public IEnumerable<Task<List<OrderedBalanceChange>>> GetOrderedBalanceAsync(Script scriptPubKey, BalanceQuery query = null, CancellationToken cancel = default(CancellationToken))
 {
     return GetOrderedBalanceCoreAsync(new BalanceId(scriptPubKey), query, cancel);
 }
 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;
         }
     }
 }
示例#18
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);
         }
     }
 }
        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;
        }
 public Task <ICollection <OrderedBalanceChange> > GetOrderedBalance(string walletId,
                                                                     BalanceQuery query       = null,
                                                                     CancellationToken cancel = default(CancellationToken))
 {
     return(GetOrderedBalanceCoreAsync(new BalanceId(walletId), query, cancel));
 }