Beispiel #1
0
 public IndexBalanceTask(IndexerConfiguration conf, WalletRuleEntryCollection walletRules, ILoggerFactory loggerFactory)
     : base(conf, loggerFactory)
 {
     _WalletRules = walletRules;
     this.logger  = loggerFactory.CreateLogger(GetType().FullName);
 }
 public IndexBalanceTask(IndexerConfiguration conf, WalletRuleEntryCollection walletRules)
     : base(conf)
 {
     _WalletRules = walletRules;
 }
        public Task IndexWalletOrderedBalanceAsync(int height, Block block, WalletRuleEntryCollection walletRules)
        {
            var table = Configuration.GetBalanceTable();
            var blockId = block == null ? null : block.GetHash();

            var entities =
                    block
                    .Transactions
                    .SelectMany(t => OrderedBalanceChange.ExtractWalletBalances(null, t, blockId, block.Header, height, walletRules))
                    .Select(t => t.ToEntity())
                    .AsEnumerable();

            return IndexAsync(entities, table);
        }
 public static IEnumerable<OrderedBalanceChange> ExtractWalletBalances(
                                                                     uint256 txId,
                                                                     Transaction tx,
                                                                     uint256 blockId,
                                                                     BlockHeader blockHeader,
                                                                     int height,
                                                                     WalletRuleEntryCollection walletCollection)
 {
     Dictionary<string, OrderedBalanceChange> entitiesByWallet = new Dictionary<string, OrderedBalanceChange>();
     var scriptBalances = ExtractScriptBalances(txId, tx, blockId, blockHeader, height);
     foreach(var scriptBalance in scriptBalances)
     {
         foreach(var walletRuleEntry in walletCollection.GetRulesFor(scriptBalance.ScriptPubKey))
         {
             OrderedBalanceChange walletEntity = null;
             if(!entitiesByWallet.TryGetValue(walletRuleEntry.WalletId, out walletEntity))
             {
                 walletEntity = new OrderedBalanceChange(walletRuleEntry.WalletId, scriptBalance);
                 entitiesByWallet.Add(walletRuleEntry.WalletId, walletEntity);
             }
             walletEntity.Merge(scriptBalance, walletRuleEntry.Rule);
         }
     }
     foreach(var b in entitiesByWallet.Values)
         b.UpdateToScriptCoins();
     return entitiesByWallet.Values;
 }
 public void IndexWalletOrderedBalance(int height, Block block, WalletRuleEntryCollection walletRules)
 {
     try
     {
         IndexWalletOrderedBalanceAsync(height, block, walletRules).Wait();
     }
     catch(AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
     }
 }