Class: Hashrate
- Inherits:
-
Object
- Object
- Hashrate
- Defined in:
- lib/hashrate.rb
Constant Summary collapse
- BTC_PER_BLOCK =
25- MH =
1e6- GH =
1e9- TH =
1e12
Class Method Summary collapse
-
.earning(start, stop, hashrate) ⇒ Object
Calculate expected earnings for a bitcoin miner based on a timespan and hashrate.
Class Method Details
.earning(start, stop, hashrate) ⇒ Object
Calculate expected earnings for a bitcoin miner based on a timespan and hashrate.
Example (six months ago to now with 100 GH/s):
>> Hashrate.earning(Time.new.to_i - (60 * 60 * 24 * 30 * 6), Time.new.to_i, 1000 * Hashrate::GH)
=> 201.08229099734106
Arguments:
start: starting mining time
stop: stopping mining time
hashrate: rate of mining in hashes per second
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hashrate.rb', line 22 def self.earning(start, stop, hashrate) # make sure this is loaded before doing anything else # (mmmm, spaghetti) self.get_difficulties # ensure start and stop are in the right format and order start, stop = [start, stop].map{|t| # convert datetime to time t = t.to_time if t.respond_to? :to_time # convert time to unix timestamp t.to_i }.sort difficulty = self.average_difficulty(start, stop) # puts "difficulty: #{difficulty}" # puts "time: #{(stop-start)}" # time to find one share between start and stop (in seconds) # with your hashrate time_for_one_share = (difficulty * 2**32 / hashrate) # number of shares we'll find in (stop-start) time expected_shares = (stop-start) / time_for_one_share # difficulty_time(start, stop) * hashrate * BTC_PER_BLOCK # btc_per_second = average_difficulty(start, stop) * BTC_PER_BLOCK / hashrate expected_shares * self::BTC_PER_BLOCK end |