public long IndexTransactions(ChainBase chain = null) { long txCount = 0; SetThrottling(); BlockingCollection <TransactionEntry.Entity[]> transactions = new BlockingCollection <TransactionEntry.Entity[]>(20); var tasks = CreateTaskPool(transactions, (txs) => Index(txs), 30); using (IndexerTrace.NewCorrelation("Import transactions to azure started").Open()) { Configuration.GetTransactionTable().CreateIfNotExists(); var buckets = new MultiValueDictionary <string, TransactionEntry.Entity>(); using (var storedBlocks = Enumerate("transactions", chain)) { foreach (var block in storedBlocks) { foreach (var transaction in block.Block.Transactions) { txCount++; var indexed = new TransactionEntry.Entity(null, transaction, block.BlockId); buckets.Add(indexed.PartitionKey, indexed); var collection = buckets[indexed.PartitionKey]; if (collection.Count == 100) { PushTransactions(buckets, collection, transactions); } if (storedBlocks.NeedSave) { foreach (var kv in buckets.AsLookup().ToArray()) { PushTransactions(buckets, kv, transactions); } tasks.Stop(); storedBlocks.SaveCheckpoint(); tasks.Start(); } } } foreach (var kv in buckets.AsLookup().ToArray()) { PushTransactions(buckets, kv, transactions); } tasks.Stop(); storedBlocks.SaveCheckpoint(); } } return(txCount); }
public IEnumerable <WalletRuleEntry> GetRulesForWallet(string walletName) { if (_EntriesByWalletLookup == null) { _EntriesByWallet = new MultiValueDictionary <string, WalletRuleEntry>(); foreach (var entry in this) { _EntriesByWallet.Add(entry.WalletId, entry); } _EntriesByWalletLookup = _EntriesByWallet.AsLookup(); } return(_EntriesByWalletLookup[walletName]); }
public IEnumerable <WalletRuleEntry> GetRulesFor(Script script) { if (_EntriesByAddress == null) { _EntriesByAddress = new MultiValueDictionary <Script, WalletRuleEntry>(); foreach (var entry in this) { var rule = entry.Rule as ScriptRule; if (rule != null) { _EntriesByAddress.Add(rule.ScriptPubKey, entry); } } _EntriesByAddressLookup = _EntriesByAddress.AsLookup(); } return(_EntriesByAddressLookup[script]); }
internal WalletRuleEntryCollection(IEnumerable <WalletRuleEntry> walletRules) { if (walletRules == null) { throw new ArgumentNullException("walletRules"); } _WalletRules = new List <WalletRuleEntry>(); _EntriesByWallet = new MultiValueDictionary <string, WalletRuleEntry>(); _EntriesByWalletLookup = _EntriesByWallet.AsLookup(); _EntriesByAddress = new MultiValueDictionary <Script, WalletRuleEntry>(); _EntriesByAddressLookup = _EntriesByAddress.AsLookup(); foreach (var rule in walletRules) { Add(rule); } }
private void IndexBalances(ChainBase chain, string checkpointName, Func <uint256, Transaction, uint256, BlockHeader, int, IEnumerable <OrderedBalanceChange> > extract) { SetThrottling(); BlockingCollection <OrderedBalanceChange[]> indexedEntries = new BlockingCollection <OrderedBalanceChange[]>(100); var tasks = CreateTaskPool(indexedEntries, (entries) => Index(entries.Select(e => e.ToEntity()), this.Configuration.GetBalanceTable()), 30); using (IndexerTrace.NewCorrelation("Import balances " + checkpointName + " to azure started").Open()) { this.Configuration.GetBalanceTable().CreateIfNotExists(); var buckets = new MultiValueDictionary <string, OrderedBalanceChange>(); using (var storedBlocks = Enumerate(checkpointName, chain)) { foreach (var block in storedBlocks) { foreach (var tx in block.Block.Transactions) { var txId = tx.GetHash(); try { var entries = extract(txId, tx, block.BlockId, block.Block.Header, block.Height); foreach (var entry in entries) { buckets.Add(entry.PartitionKey, entry); var bucket = buckets[entry.PartitionKey]; if (bucket.Count == 100) { indexedEntries.Add(bucket.ToArray()); buckets.Remove(entry.PartitionKey); } } if (storedBlocks.NeedSave) { foreach (var kv in buckets.AsLookup().ToArray()) { indexedEntries.Add(kv.ToArray()); } buckets.Clear(); tasks.Stop(); storedBlocks.SaveCheckpoint(); tasks.Start(); } } catch (Exception ex) { IndexerTrace.ErrorWhileImportingBalancesToAzure(ex, txId); throw; } } } foreach (var kv in buckets.AsLookup().ToArray()) { indexedEntries.Add(kv.ToArray()); } tasks.Stop(); storedBlocks.SaveCheckpoint(); } } }