/// <summary>
        /// Reload address Utxos list. It will sort descending the utxos based on the utxos number of confirmations.
        /// Smallest number of confirmations leads to newest transations
        /// </summary>
        /// <returns></returns>
        public async Task ReloadUtxos()
        {
            var count = Utxos.Count;

            GetAddressUtxosResponse ux = null;

            try
            {
                ux = await DogeTransactionHelpers.AddressUtxosAsync(Address);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot get dogecoin address utxos. Please check the internet connection. " + ex.Message);
                return;
            }
            if (ux == null)
            {
                Console.WriteLine("Cannot get dogecoin address utxos. Please check the internet connection. ");
                return;
            }

            var ouxox = ux.Data.Utxos.OrderBy(u => u.Confirmations).ToList();

            if (ouxox.Count > 0)
            {
                lock (_lock)
                {
                    Utxos.Clear();
                }
                TotalBalance            = 0.0;
                TotalUnconfirmedBalance = 0.0;
                TotalSpendableBalance   = 0.0;
                // add new ones
                foreach (var u in ouxox)
                {
                    if (u.Confirmations <= DogeTransactionHelpers.MinimumConfirmations)
                    {
                        TotalUnconfirmedBalance += (Convert.ToDouble(u.Value, CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        TotalSpendableBalance += (Convert.ToDouble(u.Value, CultureInfo.InvariantCulture));
                        lock (_lock)
                        {
                            Utxos.Add(u);
                        }
                    }
                }

                TotalBalance = TotalSpendableBalance + TotalUnconfirmedBalance;
            }

            if (count != Utxos.Count)
            {
                NewDogeUtxos?.Invoke(this, await EventFactory.GetEvent(EventType.Info,
                                                                       "New Doge Transactions",
                                                                       "Received new dogecoin transactions."));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns list of spendable utxos which together match some input required amount for some transaction
        /// </summary>
        /// <param name="addr">address which has utxos for spend - sender in tx</param>
        /// <param name="minAmount">minimum amount of one utxo</param>
        /// <param name="requiredAmount">amount what must be collected even by multiple utxos</param>
        /// <returns></returns>
        public static async Task <ICollection <Utxo> > GetAddressSpendableUtxo(string addr, double minAmount = 0.0001, double requiredAmount = 0.0001)
        {
            var resp = new List <Utxo>();
            GetAddressUtxosResponse addinfo = null;

            try
            {
                addinfo = await GetClient().GetAddressUtxosAsync(addr);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot obtain dogecoin address Utxos." + ex.Message);
                return(null);
            }
            if (addinfo == null)
            {
                return(null);
            }

            var utxos = addinfo.Data.Utxos;

            if (utxos == null)
            {
                return(null);
            }

            utxos = utxos.OrderBy(u => Convert.ToDouble(u.Value, CultureInfo.InvariantCulture)).Reverse().ToList();

            var founded = 0.0;

            foreach (var utx in utxos)
            {
                var val = Convert.ToDouble(utx.Value, CultureInfo.InvariantCulture) * FromSatToMainRatio;
                if (utx.Confirmations > MinimumConfirmations && val > 10000)
                {
                    if (val > (minAmount * FromSatToMainRatio))
                    {
                        resp.Add(utx);
                        founded += (val / FromSatToMainRatio);
                        if (founded > requiredAmount)
                        {
                            return(resp);
                        }
                    }
                }
            }
            return(null);
        }