GetDifficulty() public method

public GetDifficulty ( string chain_type, string url_prefix, string chain_name, string chain_abbrev ) : double
chain_type string
url_prefix string
chain_name string
chain_abbrev string
return double
コード例 #1
0
ファイル: Form1.cs プロジェクト: salfter/CoinProfitability
 // load data into form
 private void cbCoinType_SelectedIndexChanged(object sender, EventArgs e)
 {
     ExchangeInformation ei = new ExchangeInformation();
     CoinInformation ci = new CoinInformation();
     lblUpdating.Visible = true;
     this.Refresh();
     string szCoinType=cbCoinType.Items[cbCoinType.SelectedIndex].ToString();
     CoinInfo i = rs.Coins[szCoinType];
     lblAbbrev.Text = lblRewardCurrency.Text = i.Abbreviation;
     lblExchangeRateCurrency.Text = "BTC/" + i.Abbreviation;
     try { tbDifficulty.Text = ci.GetDifficulty(i.ExplorerType, i.ExplorerBaseURL, i.ExplorerChain, i.Abbreviation).ToString(); }
     catch { tbDifficulty.Text = "Unavailable"; }
     try { tbReward.Text = ci.GetReward(i.ExplorerType, i.ExplorerBaseURL, i.ExplorerChain, i.Abbreviation).ToString(); }
     catch { tbReward.Text = "Unavailable"; }
     for (int c = 0; c < cbHashrateUnit.Items.Count; c++)
         if (((Item)cbHashrateUnit.Items[c]).Name == i.DefaultHashRateUnit)
             cbHashrateUnit.SelectedIndex = c;
     try
     {
         if (i.Exchange != null)
             tbExchangeRate.Text = ei.GetExchangeRate(i.Exchange, i.Abbreviation).ToString();
         else
             tbExchangeRate.Text = "";
     }
     catch { tbExchangeRate.Text = "Unavailable"; }
     if (cbCoinType.Items[cbCoinType.SelectedIndex].ToString().ToLower() == "bitcoin") // case-insensitive for Mono compatibility
         tbExchangeRate.Text = "1";
     tbHashrate.Text = i.DefaultHashRate;
     lblUpdating.Visible = false;
     this.Refresh();
     OnChanged();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: salfter/CoinProfitability
 static int Lookup(string szSelectedCoin, decimal hashrate, bool bIncomeInBTC, long interval, string exchange, RegistrySettings rs)
 {
     Profitability p = new Profitability();
     CoinInformation ci = new CoinInformation();
     ExchangeInformation ei = new ExchangeInformation();
     CoinInfo inf = rs.Coins[szSelectedCoin];
     double diff = 0;
     try { diff = ci.GetDifficulty(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); }
     catch { Console.WriteLine("Unable to fetch difficulty"); return -1; }
     decimal reward = 0;
     try { reward = ci.GetReward(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); }
     catch { Console.WriteLine("Unable to fetch reward"); return -1; }
     if (hashrate == 0)
         switch (inf.DefaultHashRateUnit)
         {
             case "H/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate);
                 break;
             case "kH/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000;
                 break;
             case "MH/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000000;
                 break;
             case "GH/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 100000000;
                 break;
             default:
                 throw new ArgumentException("invalid hashrate unit");
         }
     if (!bIncomeInBTC)
         Console.WriteLine(p.ProfitOnInterval(interval, hashrate, reward, (decimal)diff).ToString("F8"));
     else
     {
         decimal exchrate = 0;
         try { exchrate = (szSelectedCoin.ToLower() != "bitcoin") ? ei.GetExchangeRate((exchange != "") ? exchange : inf.Exchange, inf.Abbreviation) : 1; }
         catch { Console.WriteLine("Unable to fetch exchange rate"); return -1; }
         Console.WriteLine(p.ProfitOnIntervalBTC(interval, hashrate, reward, (decimal)diff, exchrate).ToString("F8"));
     }
     return 0;
 }