/// <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
        void InitData()
        {
            if (runningTask != null)
            {
                return;
            }
            if (settingModel == null)
            {
                settingModel = BootStrapService.Default.GetPage(Pages.SendSettingPage).DataContext as SendSettingViewModel;
            }
            StaticViewModel.GlobalViewModel.IsLoading = true;
            Task task = new Task(() =>
            {
                var min = Convert.ToInt64(MinAmount * pow);
                var max = Convert.ToInt64(MaxAmount * pow);
                var listUnspentResult = UtxoService.Default.ListPageUnspent(7, CurrentPage, PageSize, 9999999, min, max, true);
                if (!listUnspentResult.IsFail)
                {
                    var itemCount = Convert.ToInt32(listUnspentResult.Value.Count);
                    var pageCount = itemCount / PageSize;
                    if (itemCount % PageSize > 0)
                    {
                        pageCount++;
                    }
                    PageCount = pageCount;
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        Utxos.Clear();
                        var items = listUnspentResult.Value.UnspentList;
                        var utxos = settingModel.Setting.UTXO;
                        if (utxos != null)
                        {
                            items = items.Where(x => !utxos.Any(u => u.Txid == x.Txid && u.Vout == x.Vout)).ToList();
                        }
                        items.ForEach(x => Utxos.Add(x));
                        runningTask = null;
                    });
                }
            });

            task.ContinueWith(t =>
            {
                StaticViewModel.GlobalViewModel.IsLoading = false;
                runningTask = null;
            });

            task.Start();
            runningTask = task;
        }
Beispiel #3
0
        public void UpdateUtxos()
        {
            lock (Utxos)
            {
                var inEntries = Chain.SelectMany(x => x.Transactions.SelectMany(tx => tx.Inputs));
                var txO       =
                    Chain.SelectMany(x => x.Transactions)
                    .Select(x => (x.Outputs, x.Id))
                    .SelectMany((x) => ToTxO(x.Outputs, x.Id));

                var newUtxos = txO
                               .Where(x =>
                                      !inEntries.Any(input =>
                                                     input.TransactionId.Equals(x.TransactionId) &&
                                                     input.OutputIndex == x.OutIndex
                                                     )
                                      );
                Utxos.Clear();
                Utxos.AddRange(newUtxos);
            }
        }