Esempio n. 1
0
        public WalletRuleEntry AddWalletRule(string walletId, WalletRule walletRule)
        {
            var table  = Configuration.GetWalletRulesTable();
            var entry  = new WalletRuleEntry(walletId, walletRule);
            var entity = entry.CreateTableEntity();

            table.ExecuteAsync(TableOperation.InsertOrReplace(entity)).GetAwaiter().GetResult();
            return(entry);
        }
Esempio n. 2
0
        internal void Merge(OrderedBalanceChange other, WalletRule walletRule)
        {
            if (other.ReceivedCoins.Count != 0)
            {
                ReceivedCoins.AddRange(other.ReceivedCoins);
                ReceivedCoins = new CoinCollection(ReceivedCoins.Distinct <ICoin, OutPoint>(c => c.Outpoint));
                if (walletRule != null)
                {
                    foreach (var c in other.ReceivedCoins)
                    {
                        this.MatchedRules.Add(new MatchedRule()
                        {
                            Index     = c.Outpoint.N,
                            Rule      = walletRule,
                            MatchType = MatchLocation.Output
                        });
                    }
                }
            }

            if (other.SpentIndices.Count != 0)
            {
                SpentIndices.AddRange(other.SpentIndices);
                SpentIndices = SpentIndices.Distinct().ToList();

                SpentOutpoints.AddRange(other.SpentOutpoints);
                SpentOutpoints = SpentOutpoints.Distinct().ToList();

                //Remove cached value, no longer correct
                UpdateToUncoloredCoins();
                SpentCoins = null;

                if (walletRule != null)
                {
                    foreach (var c in other.SpentIndices)
                    {
                        this.MatchedRules.Add(new MatchedRule()
                        {
                            Index     = c,
                            Rule      = walletRule,
                            MatchType = MatchLocation.Input
                        });
                    }
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public bool MergeIntoWallet(string walletId, string walletSource,
                             WalletRule rule          = null,
                             CancellationToken cancel = default(CancellationToken))
 {
     return(MergeIntoWalletCore(walletId, new BalanceId(walletSource), rule, cancel));
 }
Esempio n. 5
0
 public bool MergeIntoWallet(string walletId, Script scriptPubKey, WalletRule rule = null, CancellationToken cancel = default(CancellationToken))
 {
     return(MergeIntoWalletCore(walletId, new BalanceId(scriptPubKey), rule, cancel));
 }
Esempio n. 6
0
 public WalletRuleEntry(string walletId, WalletRule rule)
 {
     WalletId = walletId;
     Rule     = rule;
 }