예제 #1
0
        public void UpdateTimerTick(object state)
        {
            this.LastUpdate = DateTime.Now;

            // grab current mtgox ticker
            ticker = MtGox.GetTickerData();

            // don't update without a valid api key
            if (btcguildapikey == string.Empty || btcguildapikey.Length != btcguild_apikey_length)
            {
                return;
            }

            try
            {
                // grab stats from json api
                stats = BTCGuild.GetStats(btcguildapikey);
                if (stats == default(BTCGuild.Stats))
                {
                    throw new System.Runtime.Serialization.SerializationException("Failed to deserialize BTCGuild stats!");
                }

                // grab current difficulty
                currentDifficulty = Utility.Deserialize <double>("http://blockexplorer.com/q/getdifficulty");

                UpdateGUI(() =>
                {
                    try
                    {
                        // update mtgox exchange rate
                        if (ticker == default(MtGox.TickerData))
                        {
                            // failed to retrieve mtgox data, leave current value
                        }
                        else
                        {
                            this.usd.Text             = ticker.buy.ToString("C");
                            this.UpArrow.Visibility   = this.ticker.buy > this.ticker.last ? Visibility.Visible : Visibility.Hidden;
                            this.DownArrow.Visibility = this.ticker.buy < this.ticker.last ? Visibility.Visible : Visibility.Hidden;
                            this.usd.Foreground       = this.ticker.buy >= this.ticker.last ? Brushes.LightGreen : Brushes.LightPink;
                        }

                        // bind user stats
                        this.User.Clear();
                        this.User.Add(stats.user);

                        // bind pool stats
                        this.PoolStats.Clear();
                        this.PoolStats.Add(stats.pool);

                        // bind worker stats
                        var workerstats = stats.workers.Values.ToList();
                        this.Workers.Clear();
                        workerstats.ForEach(worker => this.Workers.Add(worker));

                        // calculate totals
                        var totals = new BTCGuild.WorkerTotals();
                        workerstats.ForEach(worker =>
                        {
                            totals.total_hash_rate    += worker.hash_rate;
                            totals.blocks_found_total += worker.blocks_found;
                            totals.reset_shares_total += worker.reset_shares;
                            totals.reset_stales_total += worker.reset_stales;
                            totals.round_shares_total += worker.round_shares;
                            totals.round_stales_total += worker.round_stales;
                            totals.total_shares_total += worker.total_shares;
                            totals.total_stales_total += worker.total_stales;
                        });

                        if (currentDifficulty == default(double))
                        {
                            // failed to retrieve difficulty, btc per day calculation not possible
                        }
                        else
                        {
                            // from the gribble bot:
                            // The expected generation output, at $1 Khps, given current difficulty of [bc,diff
                            // is [math calc 50*24*60*60 / (1/((2**224-1)/[bc,diff]*$1*1000/2**256))]
                            // BTC per day and [math calc 50*60*60 / (1/((2**224-1)/[bc,diff]*$1*1000/2**256))] BTC per hour.".
                            totals.btc_per_day       = 50 * TimeSpan.FromDays(1).TotalSeconds / (1 / (Math.Pow(2, 224) - 1)) / currentDifficulty * totals.total_hash_rate * 1000000 / Math.Pow(2, 256);
                            totals.usd_per_day_stats = ((decimal)totals.btc_per_day * ticker.buy).ToString("C");
                        }

                        this.WorkerTotals.Clear();
                        this.WorkerTotals.Add(totals);

                        this.test.Text = "BTCGuild Stats"; // reset error
                    }
                    catch (Exception e)
                    {
                        // probably an error updating the gui
                        this.test.Text = e.Message;
                    }
                });
            }
            catch (Exception e)
            {
                UpdateGUI(() =>
                {
                    // probably an error deserializing the json, or we timed out trying to read it
                    this.test.Text = e.Message;
                });
            }
        }
예제 #2
0
        public void UpdateTimerTick(object state)
        {
            this.LastUpdate = DateTime.Now;

            // don't update without a valid api key
            if (apiKey == string.Empty || apiKey.Length != apikey_length) return;

            try
            {
                var poolstats = BTCMine.GetPoolStats(apiKey);
                var userstats = BTCMine.GetUserStats(apiKey);
                var minerstats = BTCMine.GetMinerStats(apiKey);

                // grab stats from json api
                stats = BTCGuild.GetStats(apiKey);
                if (poolstats == default(BTCMine.Pool) || userstats == default(BTCMine.UserStats) || minerstats == default(BTCMine.MinerStats))
                    throw new System.Runtime.Serialization.SerializationException("Failed to deserialize from JSON!");

                // grab current difficulty
                currentDifficulty = Utility.Deserialize<double>("http://blockexplorer.com/q/getdifficulty");

                // grab current mtgox ticker
                ticker = MtGox.GetTickerData();

                UpdateGUI(() =>
                {
                    try
                    {
                        if (currentDifficulty == default(double))
                        {
                            // failed to retrieve difficulty, btc per day calculation not possible
                        }
                        else
                        {
                            // from the gribble bot:
                            // The expected generation output, at $1 Khps, given current difficulty of [bc,diff
                            // is [math calc 50*24*60*60 / (1/((2**224-1)/[bc,diff]*$1*1000/2**256))]
                            // BTC per day and [math calc 50*60*60 / (1/((2**224-1)/[bc,diff]*$1*1000/2**256))] BTC per hour.".
                            userstats.btc_per_day = 50 * TimeSpan.FromDays(1).TotalSeconds / (1 / (Math.Pow(2, 224) - 1)) / currentDifficulty * userstats.hashrate * 1000000 / Math.Pow(2, 256);
                            userstats.btc_per_hour = userstats.btc_per_day / 24f;
                        }
                        // update mtgox exchange rate
                        if (ticker == default(MtGox.TickerData))
                        {
                            // failed to retrieve mtgox data, leave current value
                        }
                        else
                        {
                            this.usd.Text = ticker.buy.ToString("C");
                            this.UpArrow.Visibility = this.ticker.buy > this.ticker.last ? Visibility.Visible : Visibility.Hidden;
                            this.DownArrow.Visibility = this.ticker.buy < this.ticker.last ? Visibility.Visible : Visibility.Hidden;
                            this.usd.Foreground = this.ticker.buy >= this.ticker.last ? Brushes.LightGreen : Brushes.LightPink;
                            userstats.usd_per_day_stats = ((decimal)userstats.btc_per_day * ticker.buy).ToString("C");
                        }

                        // bind user stats
                        this.UserStats.Clear();
                        this.UserStats.Add(userstats);

                        // bind pool stats
                        this.PoolStats.Clear();
                        this.PoolStats.Add(poolstats);

                        // bind worker stats
                        this.MinerStats.Clear();
                        minerstats.miners.ForEach(miner => this.MinerStats.Add(miner));

                        this.test.Text = "BTCMine Stats"; // reset error
                    }
                    catch (Exception e)
                    {
                        // probably an error updating the gui
                        this.test.Text = e.Message;
                    }
                });
            }
            catch (Exception e)
            {
                UpdateGUI(() =>
                {
                    // probably an error deserializing the json, or we timed out trying to read it
                    this.test.Text = e.Message;
                });
            }
        }