Skip to content

Instantly share code, notes, and snippets.

@suanmiao
Created June 6, 2014 12:20
Show Gist options
  • Save suanmiao/0c8699e0d07c7c1880fd to your computer and use it in GitHub Desktop.
Save suanmiao/0c8699e0d07c7c1880fd to your computer and use it in GitHub Desktop.
BTC Mining Calculator

BitCoin Mining Calcuator

  • Code:

      float price =nowBean.getPrice();  
      float elecPriceFloat = nowBean.getElecPrice(); 
      float deviceCostFloat = nowBean.getDeviceCost();
      float currency = nowBean.getCurrency();
      String unitString = "";
      
      // /
      BigDecimal difficulty = new
                  BigDecimal(nowBean.getDifficulty());
    
      // common
      BigDecimal gToBigDecimal = new
                  BigDecimal(1000).pow(3);
      BigDecimal twoPow32 = new      
                  BigDecimal("4294967296");
    
      //
      BigDecimal coinPrice = new BigDecimal(price);
    
      // / G unit
      BigDecimal calAbility = new 
                  BigDecimal(nowBean.getCalability());
    
      BigDecimal blockTimeSecond = 
                  difficulty.multiply(twoPow32).divide(
      		    calAbility.multiply(gToBigDecimal),  
      		    DECIMAL_SCALE,
      		BigDecimal.ROUND_DOWN);
      BigDecimal blockTimeHour = 
                  blockTimeSecond.divide(new     
                  BigDecimal(3600),
      		DECIMAL_SCALE, BigDecimal.ROUND_DOWN);
    
      // input
      BigDecimal deviceCost = new 
                  BigDecimal(deviceCostFloat);
    
      BigDecimal elecPrice = new 
                  BigDecimal(elecPriceFloat);
    
      // w unit
      BigDecimal devicePower = new 
                  BigDecimal(nowBean.getDevicePower());
      BigDecimal devicePowerInKw =  
                  devicePower.divide(new 
                   BigDecimal(1000),
      		DECIMAL_SCALE, BigDecimal.ROUND_DOWN);
    
      // output
      BigDecimal deviceCostPerG = 
                  deviceCost.divide(calAbility,
      		DECIMAL_SCALE, BigDecimal.ROUND_DOWN);
      BigDecimal elecCostPerG =  
                devicePowerInKw.multiply(elecPrice)
                .divide(calAbility, DECIMAL_SCALE,   
             BigDecimal.ROUND_DOWN);
    
      BigDecimal coinPerDay = (new BigDecimal(25)
      	       .multiply(new 
      	       BigDecimal(24))).divide(blockTimeHour,
      		DECIMAL_SCALE, BigDecimal.ROUND_DOWN);
    
      BigDecimal moneyPerDay = 
                coinPerDay.multiply(coinPrice);
    
      //  about time distance
      BigDecimal diffChangeCycle = new BigDecimal(
      		nowBean.getDiffChangeCycle());
      // 
      BigDecimal diffGrowPercent = new BigDecimal(
      		nowBean.getDiffGrowPercent());
    
      //  local logic
      long nextDiffTimeInSecond = 
                  Long.parseLong(nowBean
      		.getNextDifficultyTime());
    
      long nextDiffTimeInDay = nextDiffTimeInSecond / 
                    3600 / 24;
    
      BigDecimal nextDiffTime = new 
               BigDecimal(nextDiffTimeInDay);
    
      BigDecimal elecCostPerDay = 
               elecPrice.multiply(devicePowerInKw)
      		.multiply(new BigDecimal(24));
    
  • Explain

      输入变量:
        算力
        btc价格
        电价
        设备价格
        汇率
        
      btc变量:
        难度
        
      算法:
        区块时间 = 难度 * 2^32 / 算力
        每日获取的币 = 24小时 / 区块时间 * 每个区块得到的币
        设备成本 = 设备价格 / 算力
        电力成本 = 电力价格 / 算力
        每日净利润 = 每日获取的币 * btc价格 - 每日电力成本
        回本时间 = 设备成本 / 每日净利润
        
      
    
  • 附加说明

    1.关于每个区块得到的币:

      目前为25个币/区块,以后会进行调整,但调整周期较长,目前不考虑这种情况
    

    2.关于难度调整:

      对于btc,难度调整的周期为11天左右,具体周期会浮动,目前未找到相应算法,所以以11天作为周期
    
  • 参考

    1.比特币基础教学之:BLOCK产生难度及挖矿

    2.Bitcoinwidsom BTC Calculator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment