예제 #1
0
        public void AppendNewTransactions(Wallet wallet, List <Tuple <WalletTransaction, BlockIdentity> > txs)
        {
            var account        = SelectedAccount.Account;
            var totalDebits    = DebitSum;
            var totalCredits   = CreditSum;
            var runningBalance = totalDebits + totalCredits;

            foreach (var tx in txs)
            {
                var accountTxOption = AccountTransaction.Create(account, tx.Item1);
                if (accountTxOption == null)
                {
                    continue;
                }
                var accountTx = accountTxOption.Value;
                var txvm      = new TransactionViewModel(wallet, accountTx.Transaction, tx.Item2);
                totalDebits    += accountTx.Debit;
                totalCredits   += accountTx.Credit;
                runningBalance += accountTx.DebitCredit;
                var histItem = new HistoryItem(txvm, accountTx.Debit, accountTx.Credit, runningBalance);
                App.Current.Dispatcher.Invoke(() => Transactions.Add(histItem));
            }

            DebitSum  = totalDebits;
            CreditSum = totalCredits;
        }
예제 #2
0
        private static IEnumerable <HistoryItem> EnumerateAccountTransactions(Wallet wallet, Account account)
        {
            Amount runningBalance = 0;

            // RecentTransactions currently includes every transaction.
            // This will change in a future release, but for now don't bother using RPC to fetch old transactions.
            // Iterate through them, oldest first.
            foreach (var block in wallet.RecentTransactions.MinedTransactions)
            {
                var minedAccountTxs = block.Transactions.
                                      Select(tx => AccountTransaction.Create(account, tx)).
                                      Where(atx => atx.HasValue).
                                      Select(atx => atx.Value);
                foreach (var accountTx in minedAccountTxs)
                {
                    var txvm = new TransactionViewModel(wallet, accountTx.Transaction, block.Identity);
                    runningBalance += accountTx.DebitCredit;
                    yield return(new HistoryItem(txvm, accountTx.Debit, accountTx.Credit, runningBalance));
                }
            }

            var unminedAccountTxs = wallet.RecentTransactions.UnminedTransactions.
                                    Select(tx => AccountTransaction.Create(account, tx.Value)).
                                    Where(atx => atx.HasValue).
                                    Select(atx => atx.Value).
                                    OrderBy(atx => atx.Transaction.SeenTime);

            foreach (var accountTx in unminedAccountTxs)
            {
                var txvm = new TransactionViewModel(wallet, accountTx.Transaction, BlockIdentity.Unmined);
                runningBalance += accountTx.DebitCredit;
                yield return(new HistoryItem(txvm, accountTx.Debit, accountTx.Credit, runningBalance));
            }
        }