示例#1
0
        /// <summary>
        /// Get the address total spendable value for both confirmed and unconfirmed UTXO.
        /// </summary>
        public (Money confirmedAmount, Money unConfirmedAmount, bool anyTrx) GetBalances(IWalletStore walletStore, bool excludeColdStakeUtxo)
        {
            var trx = walletStore.GetForAddress(this.Address).ToList();

            List <TransactionOutputData> allTransactions = excludeColdStakeUtxo
                ? trx.Where(t => t.IsColdCoinStake != true).ToList()
                : trx;

            long confirmed = allTransactions.Sum(t => t.GetUnspentAmount(true));
            long total     = allTransactions.Sum(t => t.GetUnspentAmount(false));

            return(confirmed, total - confirmed, trx.Any());
        }
示例#2
0
        /// <summary>
        /// Gets the first account that contains no transaction.
        /// </summary>
        /// <returns>An unused account</returns>
        public HdAccount GetFirstUnusedAccount(IWalletStore walletStore)
        {
            if (this.Accounts == null)
            {
                return(null);
            }

            List <HdAccount> unusedAccounts = this.Accounts
                                              .Where(Wallet.NormalAccounts)
                                              .Where(acc =>
                                                     !acc.ExternalAddresses.SelectMany(add => walletStore.GetForAddress(add.Address)).Any()
                                                     &&
                                                     !acc.InternalAddresses.SelectMany(add => walletStore.GetForAddress(add.Address)).Any()).ToList();

            if (!unusedAccounts.Any())
            {
                return(null);
            }

            // gets the unused account with the lowest index
            int index = unusedAccounts.Min(a => a.Index);

            return(unusedAccounts.Single(a => a.Index == index));
        }