bitcoin_reward_era 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +20 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +44 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +14 -0
- data/bitcoin_reward_era.gemspec +33 -0
- data/exe/btc_money_supply +7 -0
- data/lib/bitcoin_reward_era.rb +23 -0
- data/lib/bitcoin_reward_era/calculator.rb +135 -0
- data/lib/bitcoin_reward_era/report.rb +18 -0
- data/lib/bitcoin_reward_era/representation.rb +62 -0
- data/lib/bitcoin_reward_era/version.rb +5 -0
- data/lib/spec_helper.rb +84 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16608263e0df7b5b6ec7bc9935aedde97fe0dd3c
|
4
|
+
data.tar.gz: eef312efde3b543cbf76b829e08d64882f439043
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1f79db458e33370135bcaa07779784af19d6cca7cfdf5639e6c676c625a1f22061682ee26e67b234a2aed21669ee2a8878d6c7a645d43a3c77071e6f75d998a
|
7
|
+
data.tar.gz: 6fe32ac7ef5bebb96e270e95faa844ded44eecd6366275e66d2a52ba646d0186ea15c3668190b707a021c4ef85234d0c7062f6b2834981ee9313ff88b3fcb5fe
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Metrics/AbcSize:
|
2
|
+
Max: 21
|
3
|
+
|
4
|
+
Metrics/MethodLength:
|
5
|
+
CountComments: false
|
6
|
+
Max: 12
|
7
|
+
|
8
|
+
Style/AlignHash:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedHashRocketStyle: table
|
11
|
+
EnforcedColonStyle: table
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/MethodDefParentheses:
|
17
|
+
EnforcedStyle: require_no_parentheses
|
18
|
+
|
19
|
+
Style/RegexpLiteral:
|
20
|
+
MaxSlashes: 0
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bitcoin_reward_era (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.0.0)
|
10
|
+
astrolabe (1.3.0)
|
11
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
minitest (5.5.1)
|
14
|
+
parser (2.2.0.3)
|
15
|
+
ast (>= 1.1, < 3.0)
|
16
|
+
powerpack (0.1.0)
|
17
|
+
rainbow (2.0.0)
|
18
|
+
rake (10.4.2)
|
19
|
+
rspec-expectations (3.2.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.2.0)
|
22
|
+
rspec-mocks (3.2.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.2.0)
|
25
|
+
rspec-support (3.2.2)
|
26
|
+
rubocop (0.29.1)
|
27
|
+
astrolabe (~> 1.3)
|
28
|
+
parser (>= 2.2.0.1, < 3.0)
|
29
|
+
powerpack (~> 0.1)
|
30
|
+
rainbow (>= 1.99.1, < 3.0)
|
31
|
+
ruby-progressbar (~> 1.4)
|
32
|
+
ruby-progressbar (1.7.5)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bitcoin_reward_era!
|
39
|
+
bundler (~> 1.8)
|
40
|
+
minitest (~> 5.5.1)
|
41
|
+
rake (~> 10)
|
42
|
+
rspec-expectations (~> 3.2)
|
43
|
+
rspec-mocks (~> 3.2)
|
44
|
+
rubocop (~> 0.29)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tom Mornini
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
Gem representing Bitcoin reward eras.
|
2
|
+
|
3
|
+
100% BigDecimal math (not Float or Fixnum).
|
4
|
+
|
5
|
+
```
|
6
|
+
gem install 'bitcoin_reward_era'
|
7
|
+
|
8
|
+
require 'bitcoin_reward_era'
|
9
|
+
|
10
|
+
puts BitcoinRewardEra.report
|
11
|
+
```
|
12
|
+
|
13
|
+
Also installs an executable to demonstrate its usefulness.
|
14
|
+
|
15
|
+
> bitcoin_reward_era
|
16
|
+
|
17
|
+
```
|
18
|
+
Block Reward Era BTC/block Year Start BTC BTC Added End BTC BTC % Increase End BTC % of Limit Supply Inflation Rate
|
19
|
+
0 : 1 : 50.00000000 : 2009.008 : 0.00000000 : 10500000.00000000 : 10500000.00000000 : Inf% : 50.00000006% : Inf%
|
20
|
+
210000 : 2 : 25.00000000 : 2013.000 : 10500000.00000000 : 5250000.00000000 : 15750000.00000000 : 50.00000000% : 75.00000008% : 10.66819197%
|
21
|
+
420000 : 3 : 12.50000000 : 2016.993 : 15750000.00000000 : 2625000.00000000 : 18375000.00000000 : 16.66666667% : 87.50000010% : 3.92898776%
|
22
|
+
630000 : 4 : 6.25000000 : 2020.986 : 18375000.00000000 : 1312500.00000000 : 19687500.00000000 : 7.14285714% : 93.75000010% : 1.73978273%
|
23
|
+
840000 : 5 : 3.12500000 : 2024.978 : 19687500.00000000 : 656250.00000000 : 20343750.00000000 : 3.33333333% : 96.87500011% : 0.82311468%
|
24
|
+
1050000 : 6 : 1.56250000 : 2028.971 : 20343750.00000000 : 328125.00000000 : 20671875.00000000 : 1.61290323% : 98.43750011% : 0.40080964%
|
25
|
+
1260000 : 7 : 0.78125000 : 2032.964 : 20671875.00000000 : 164062.50000000 : 20835937.50000000 : 0.79365079% : 99.21875011% : 0.19782490%
|
26
|
+
1470000 : 8 : 0.39062500 : 2036.957 : 20835937.50000000 : 82031.25000000 : 20917968.75000000 : 0.39370079% : 99.60937511% : 0.09828022%
|
27
|
+
1680000 : 9 : 0.19531250 : 2040.949 : 20917968.75000000 : 41015.62500000 : 20958984.37500000 : 0.19607843% : 99.80468761% : 0.04898361%
|
28
|
+
1890000 : 10 : 0.09765625 : 2044.942 : 20958984.37500000 : 20507.81250000 : 20979492.18750000 : 0.09784736% : 99.90234386% : 0.02445287%
|
29
|
+
2100000 : 11 : 0.04882812 : 2048.935 : 20979492.18750000 : 10253.90520000 : 20989746.09270000 : 0.04887585% : 99.95117198% : 0.01221672%
|
30
|
+
2310000 : 12 : 0.02441406 : 2052.927 : 20989746.09270000 : 5126.95260000 : 20994873.04530000 : 0.02442599% : 99.97558604% : 0.00610594%
|
31
|
+
2520000 : 13 : 0.01220703 : 2056.920 : 20994873.04530000 : 2563.47630000 : 20997436.52160000 : 0.01221001% : 99.98779307% : 0.00305236%
|
32
|
+
2730000 : 14 : 0.00610351 : 2060.913 : 20997436.52160000 : 1281.73710000 : 20998718.25870000 : 0.00610426% : 99.99389658% : 0.00152603%
|
33
|
+
2940000 : 15 : 0.00305175 : 2064.906 : 20998718.25870000 : 640.86750000 : 20999359.12620000 : 0.00305194% : 99.99694833% : 0.00076298%
|
34
|
+
3150000 : 16 : 0.00152587 : 2068.898 : 20999359.12620000 : 320.43270000 : 20999679.55890000 : 0.00152592% : 99.99847420% : 0.00038148%
|
35
|
+
3360000 : 17 : 0.00076293 : 2072.891 : 20999679.55890000 : 160.21530000 : 20999839.77420000 : 0.00076294% : 99.99923713% : 0.00019073%
|
36
|
+
3570000 : 18 : 0.00038146 : 2076.884 : 20999839.77420000 : 80.10660000 : 20999919.88080000 : 0.00038146% : 99.99961859% : 0.00009537%
|
37
|
+
3780000 : 19 : 0.00019073 : 2080.876 : 20999919.88080000 : 40.05330000 : 20999959.93410000 : 0.00019073% : 99.99980932% : 0.00004768%
|
38
|
+
3990000 : 20 : 0.00009536 : 2084.869 : 20999959.93410000 : 20.02560000 : 20999979.95970000 : 0.00009536% : 99.99990468% : 0.00002384%
|
39
|
+
4200000 : 21 : 0.00004768 : 2088.862 : 20999979.95970000 : 10.01280000 : 20999989.97250000 : 0.00004768% : 99.99995236% : 0.00001192%
|
40
|
+
4410000 : 22 : 0.00002384 : 2092.855 : 20999989.97250000 : 5.00640000 : 20999994.97890000 : 0.00002384% : 99.99997620% : 0.00000596%
|
41
|
+
4620000 : 23 : 0.00001192 : 2096.847 : 20999994.97890000 : 2.50320000 : 20999997.48210000 : 0.00001192% : 99.99998812% : 0.00000298%
|
42
|
+
4830000 : 24 : 0.00000596 : 2100.842 : 20999997.48210000 : 1.25160000 : 20999998.73370000 : 0.00000596% : 99.99999408% : 0.00000149%
|
43
|
+
5040000 : 25 : 0.00000298 : 2104.835 : 20999998.73370000 : 0.62580000 : 20999999.35950000 : 0.00000298% : 99.99999706% : 0.00000075%
|
44
|
+
5250000 : 26 : 0.00000149 : 2108.828 : 20999999.35950000 : 0.31290000 : 20999999.67240000 : 0.00000149% : 99.99999855% : 0.00000037%
|
45
|
+
5460000 : 27 : 0.00000074 : 2112.821 : 20999999.67240000 : 0.15540000 : 20999999.82780000 : 0.00000074% : 99.99999929% : 0.00000019%
|
46
|
+
5670000 : 28 : 0.00000037 : 2116.814 : 20999999.82780000 : 0.07770000 : 20999999.90550000 : 0.00000037% : 99.99999966% : 0.00000009%
|
47
|
+
5880000 : 29 : 0.00000018 : 2120.806 : 20999999.90550000 : 0.03780000 : 20999999.94330000 : 0.00000018% : 99.99999984% : 0.00000005%
|
48
|
+
6090000 : 30 : 0.00000009 : 2124.799 : 20999999.94330000 : 0.01890000 : 20999999.96220000 : 0.00000009% : 99.99999993% : 0.00000002%
|
49
|
+
6300000 : 31 : 0.00000004 : 2128.792 : 20999999.96220000 : 0.00840000 : 20999999.97060000 : 0.00000004% : 99.99999997% : 0.00000001%
|
50
|
+
6510000 : 32 : 0.00000002 : 2132.784 : 20999999.97060000 : 0.00420000 : 20999999.97480000 : 0.00000002% : 99.99999999% : 0.00000001%
|
51
|
+
6720000 : 33 : 0.00000001 : 2136.777 : 20999999.97480000 : 0.00210000 : 20999999.97690000 : 0.00000001% : 100.00000000% : 0.00000000%
|
52
|
+
6930000 : 34 : 0.00000000 : 2140.770 : 20999999.97690000 : 0.00000000 : 20999999.97690000 : 0.00000000% : 100.00000000% : 0.00000000%
|
53
|
+
```
|
54
|
+
|
55
|
+
Created to verify table ["Projected Bitcoins Long Term"](https://en.bitcoin.it/wiki/Controlled_supply)
|
56
|
+
|
57
|
+
Thanks to /u/QuasiSteve for help
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
task :default do
|
6
|
+
task('spec:unit').invoke
|
7
|
+
sh 'rubocop --fail-fast --display-cop-name'
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :spec do
|
11
|
+
Rake::TestTask.new :unit do |task|
|
12
|
+
task.test_files = FileList['lib/**/*_spec.rb']
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bitcoin_reward_era/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bitcoin_reward_era'
|
8
|
+
spec.version = BitcoinRewardEra::VERSION
|
9
|
+
spec.authors = ['Tom Mornini']
|
10
|
+
spec.email = ['tom@subledger.com']
|
11
|
+
|
12
|
+
spec.summary = 'Bitcoin reward era gem'
|
13
|
+
|
14
|
+
spec.description = "Bitcoin reward era gem.\n" \
|
15
|
+
'100% BigDecimal math (not Float or Fixnum).'
|
16
|
+
|
17
|
+
spec.homepage = 'https://github.com/tmornini/bitcoin_reward_era'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files =
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(/_spec.rb$/) }
|
22
|
+
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename f }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10'
|
29
|
+
spec.add_development_dependency 'minitest', '~> 5.5', '>= 5.5.1'
|
30
|
+
spec.add_development_dependency 'rspec-expectations', '~> 3.2'
|
31
|
+
spec.add_development_dependency 'rspec-mocks', '~> 3.2'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.29'
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'bitcoin_reward_era/representation'
|
4
|
+
|
5
|
+
module BitcoinRewardEra
|
6
|
+
def self.report
|
7
|
+
report_string = "#{HEADER}\n"
|
8
|
+
|
9
|
+
1.upto(34) do |reward_era_number|
|
10
|
+
report_string +=
|
11
|
+
"#{Representation.new reward_era_number: reward_era_number}\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
report_string
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
HEADER = ' Block Reward Era BTC/block Year' \
|
20
|
+
' Start BTC BTC Added' \
|
21
|
+
' End BTC BTC % Increase' \
|
22
|
+
' End BTC % of Limit Supply Inflation Rate'
|
23
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module BitcoinRewardEra
|
7
|
+
class Calculator
|
8
|
+
BLOCKS_PER_REWARD_ERA = 210_000
|
9
|
+
SECONDS_PER_REWARD_ERA = BLOCKS_PER_REWARD_ERA * 10 * 60
|
10
|
+
GENESIS_BLOCK_TIME = Time.at(1_231_006_505).utc
|
11
|
+
|
12
|
+
attr_reader :reward_era_number
|
13
|
+
|
14
|
+
def initialize config
|
15
|
+
@representation_klass = config[:representation_klass] || Representation
|
16
|
+
@bigdecimal_klass = config[:bigdecimal_klass] || BigDecimal
|
17
|
+
@time_klass = config[:time_klass] || Time
|
18
|
+
|
19
|
+
@reward_era_number = config[:reward_era_number].to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def first_block_in_era
|
23
|
+
last_reward_era_number * BLOCKS_PER_REWARD_ERA
|
24
|
+
end
|
25
|
+
|
26
|
+
def btc_per_block
|
27
|
+
reward = BigDecimal 50
|
28
|
+
|
29
|
+
truncate_at_satoshis reward / (2**last_reward_era_number)
|
30
|
+
end
|
31
|
+
|
32
|
+
def year
|
33
|
+
beginning_of_reward_era.year + portion_of_year
|
34
|
+
end
|
35
|
+
|
36
|
+
def start_btc
|
37
|
+
btc_in_circulation = 0
|
38
|
+
|
39
|
+
1.upto last_reward_era_number do |ren|
|
40
|
+
btc_in_circulation +=
|
41
|
+
self.class.new(reward_era_number: ren)
|
42
|
+
.btc_per_block * BLOCKS_PER_REWARD_ERA
|
43
|
+
end
|
44
|
+
|
45
|
+
btc_in_circulation
|
46
|
+
end
|
47
|
+
|
48
|
+
def btc_added
|
49
|
+
end_btc - start_btc
|
50
|
+
end
|
51
|
+
|
52
|
+
def end_btc
|
53
|
+
next_calculator.start_btc
|
54
|
+
end
|
55
|
+
|
56
|
+
def btc_increase_percentage
|
57
|
+
btc_added / last_calculator.end_btc
|
58
|
+
end
|
59
|
+
|
60
|
+
def end_btc_percent_of_limit
|
61
|
+
end_btc / final_calculator.end_btc
|
62
|
+
end
|
63
|
+
|
64
|
+
def supply_inflation_rate
|
65
|
+
((1 + btc_increase_percentage)**0.25) - 1
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def last_reward_era_number
|
71
|
+
@reward_era_number - 1
|
72
|
+
end
|
73
|
+
|
74
|
+
def next_reward_era_number
|
75
|
+
@reward_era_number + 1
|
76
|
+
end
|
77
|
+
|
78
|
+
def final_reward_era_number
|
79
|
+
34
|
80
|
+
end
|
81
|
+
|
82
|
+
def truncate_at_satoshis btc
|
83
|
+
string = btc.to_s '8F'
|
84
|
+
|
85
|
+
truncation_match = string.match(/^\d+[.]\d+/)
|
86
|
+
|
87
|
+
BigDecimal truncation_match[0]
|
88
|
+
end
|
89
|
+
|
90
|
+
def seconds_since_block_zero
|
91
|
+
first_block_in_era * 60 * 10
|
92
|
+
end
|
93
|
+
|
94
|
+
def beginning_of_reward_era
|
95
|
+
GENESIS_BLOCK_TIME + seconds_since_block_zero
|
96
|
+
end
|
97
|
+
|
98
|
+
def this_year
|
99
|
+
beginning_of_reward_era.year
|
100
|
+
end
|
101
|
+
|
102
|
+
def portion_of_year
|
103
|
+
next_year = this_year + 1
|
104
|
+
|
105
|
+
beginning_of_this_year = Time.new(this_year, 1, 1, 0, 0, 0, '+00:00').utc
|
106
|
+
beginning_of_next_year = Time.new(next_year, 1, 1, 0, 0, 0, '+00:00').utc
|
107
|
+
|
108
|
+
portion_of_this_year =
|
109
|
+
(beginning_of_reward_era - beginning_of_this_year) /
|
110
|
+
(beginning_of_next_year - beginning_of_this_year)
|
111
|
+
|
112
|
+
# ap beginning_of_this_year: beginning_of_this_year,
|
113
|
+
# beginning_of_this_year_i: beginning_of_this_year.to_i,
|
114
|
+
# beginning_of_reward_era: beginning_of_reward_era,
|
115
|
+
# beginning_of_reward_era_i: beginning_of_reward_era.to_i,
|
116
|
+
# beginning_of_next_year: beginning_of_next_year,
|
117
|
+
# beginning_of_next_year_i: beginning_of_next_year.to_i,
|
118
|
+
# portion_of_this_year: portion_of_this_year
|
119
|
+
|
120
|
+
portion_of_this_year
|
121
|
+
end
|
122
|
+
|
123
|
+
def last_calculator
|
124
|
+
self.class.new reward_era_number: last_reward_era_number
|
125
|
+
end
|
126
|
+
|
127
|
+
def next_calculator
|
128
|
+
self.class.new reward_era_number: next_reward_era_number
|
129
|
+
end
|
130
|
+
|
131
|
+
def final_calculator
|
132
|
+
self.class.new reward_era_number: final_reward_era_number
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'bitcoin_reward_era/model'
|
4
|
+
|
5
|
+
module BitcoinRewardEra
|
6
|
+
module Report
|
7
|
+
def self.to_s
|
8
|
+
report_string = header + "\n"
|
9
|
+
|
10
|
+
1.upto(34) do |reward_era_number|
|
11
|
+
report_string += new(reward_era_number: reward_era_number).to_s
|
12
|
+
report_string += "\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
report_string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'bitcoin_reward_era/calculator'
|
4
|
+
|
5
|
+
module BitcoinRewardEra
|
6
|
+
class Representation
|
7
|
+
def initialize config
|
8
|
+
@calculator =
|
9
|
+
Calculator.new reward_era_number: config[:reward_era_number].to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_representation
|
13
|
+
{
|
14
|
+
block: @calculator.first_block_in_era,
|
15
|
+
reward_era_number: @calculator.reward_era_number,
|
16
|
+
btc_per_block: @calculator.btc_per_block,
|
17
|
+
year: @calculator.year,
|
18
|
+
start_btc: @calculator.start_btc,
|
19
|
+
btc_added: @calculator.btc_added,
|
20
|
+
end_btc: @calculator.end_btc,
|
21
|
+
btc_increase_percentage: @calculator.btc_increase_percentage,
|
22
|
+
end_btc_percent_of_limit: @calculator.end_btc_percent_of_limit,
|
23
|
+
supply_inflation_rate: @calculator.supply_inflation_rate
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
[
|
29
|
+
format('%7d', @calculator.first_block_in_era),
|
30
|
+
format('%10d', @calculator.reward_era_number),
|
31
|
+
align(@calculator.btc_per_block, 2),
|
32
|
+
align(@calculator.year, 4, 3),
|
33
|
+
align(@calculator.start_btc),
|
34
|
+
align(@calculator.btc_added),
|
35
|
+
align(@calculator.end_btc),
|
36
|
+
percentage(@calculator.btc_increase_percentage, 4, 8),
|
37
|
+
percentage(@calculator.end_btc_percent_of_limit, 8, 8),
|
38
|
+
percentage(@calculator.supply_inflation_rate, 11, 8)
|
39
|
+
].join ' : '
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def align amount, unit_width = 8, decimal_width = 8
|
45
|
+
total_length = unit_width + 1 + decimal_width
|
46
|
+
|
47
|
+
pattern = "%#{total_length}.#{decimal_width}f"
|
48
|
+
|
49
|
+
format pattern, amount
|
50
|
+
end
|
51
|
+
|
52
|
+
def percentage amount, unit_width = 3, decimal_width = 8
|
53
|
+
total_length = unit_width + 1 + decimal_width
|
54
|
+
|
55
|
+
return format("%#{total_length + 1}s", amount) if amount.is_a? String
|
56
|
+
|
57
|
+
pattern = "%#{total_length}.#{decimal_width}f%"
|
58
|
+
|
59
|
+
format pattern, amount * 100
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/spec_helper.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
gem 'minitest'
|
7
|
+
|
8
|
+
require 'minitest/spec'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
|
11
|
+
MiniTest::Test.parallelize_me!
|
12
|
+
|
13
|
+
# rubocop:disable all
|
14
|
+
|
15
|
+
module Kernel
|
16
|
+
def Class thing, &block
|
17
|
+
describe_set_subject thing, &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def Constant thing, &block
|
21
|
+
describe_set_subject thing, &block
|
22
|
+
end
|
23
|
+
|
24
|
+
def Module thing, &block
|
25
|
+
describe_set_subject thing, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def Instance &block
|
29
|
+
describe 'instance', &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def RespondsTo desc, &block
|
33
|
+
describe "responds to #{desc}", &block
|
34
|
+
end
|
35
|
+
|
36
|
+
def When desc, &block
|
37
|
+
describe "when #{desc}", &block
|
38
|
+
end
|
39
|
+
|
40
|
+
def And desc, &block
|
41
|
+
describe "and #{desc}", &block
|
42
|
+
end
|
43
|
+
|
44
|
+
def RoleTest desc
|
45
|
+
load Subledger::ROOT + "/spec/roles/#{desc}_spec.rb"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Thanks Anton Lindqvist!
|
51
|
+
# https://github.com/mptre/minitest-implicit-subject
|
52
|
+
|
53
|
+
def describe_set_subject *args, &block
|
54
|
+
cls = describe *args, &block
|
55
|
+
|
56
|
+
subject = args.first
|
57
|
+
|
58
|
+
if subject.respond_to?(:included_modules) &&
|
59
|
+
Array(subject.included_modules).include?(Singleton)
|
60
|
+
|
61
|
+
subject = subject.instance
|
62
|
+
end
|
63
|
+
|
64
|
+
cls.subject { subject }
|
65
|
+
|
66
|
+
cls
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module MiniTest
|
71
|
+
class Spec
|
72
|
+
def self.ByRaising desc, &block
|
73
|
+
it "by raising #{desc}", &block
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.ByReturning desc, &block
|
77
|
+
it "by returning #{desc}", &block
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.ByYielding desc, &block
|
81
|
+
it "by yielding #{desc}", &block
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitcoin_reward_era
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Mornini
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.5'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 5.5.1
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '5.5'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 5.5.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-expectations
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.2'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec-mocks
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.2'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.29'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.29'
|
103
|
+
description: |-
|
104
|
+
Bitcoin reward era gem.
|
105
|
+
100% BigDecimal math (not Float or Fixnum).
|
106
|
+
email:
|
107
|
+
- tom@subledger.com
|
108
|
+
executables:
|
109
|
+
- btc_money_supply
|
110
|
+
extensions: []
|
111
|
+
extra_rdoc_files: []
|
112
|
+
files:
|
113
|
+
- ".rubocop.yml"
|
114
|
+
- ".ruby-version"
|
115
|
+
- Gemfile
|
116
|
+
- Gemfile.lock
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- bitcoin_reward_era.gemspec
|
121
|
+
- exe/btc_money_supply
|
122
|
+
- lib/bitcoin_reward_era.rb
|
123
|
+
- lib/bitcoin_reward_era/calculator.rb
|
124
|
+
- lib/bitcoin_reward_era/report.rb
|
125
|
+
- lib/bitcoin_reward_era/representation.rb
|
126
|
+
- lib/bitcoin_reward_era/version.rb
|
127
|
+
- lib/spec_helper.rb
|
128
|
+
homepage: https://github.com/tmornini/bitcoin_reward_era
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.4.5
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Bitcoin reward era gem
|
152
|
+
test_files: []
|