bitcoin_reward_era 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/Gemfile.lock +5 -3
- data/README.md +1 -1
- data/bitcoin_reward_era.gemspec +2 -1
- data/lib/bitcoin_reward_era/amount.rb +28 -0
- data/lib/bitcoin_reward_era/calculator.rb +40 -43
- data/lib/bitcoin_reward_era/representation.rb +2 -2
- data/lib/bitcoin_reward_era/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f73829b4afd9b52f56b93e78605af2df905510
|
4
|
+
data.tar.gz: ad12bf9921581b06e81f943ca4a4ad1b9419b4ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3fee494ac3a35aa3e524ad8d5fe4e142465b3e46473d526dbea19a48bf2ed7d2fd2ddb587769fe5c9355d3e1176b8546b58710a6ea9adbddb6169dc3e37da2
|
7
|
+
data.tar.gz: f3b6d46f2bbe24487345179c0186d81b9d895de4d566bb1c6b9a31241add6faf1a781d542ec3baac11a5a46c8a4dc6ae91b73470fef3678fcd253c000facd794
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bitcoin_reward_era (0.0.
|
4
|
+
bitcoin_reward_era (0.0.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -9,6 +9,7 @@ GEM
|
|
9
9
|
ast (2.0.0)
|
10
10
|
astrolabe (1.3.0)
|
11
11
|
parser (>= 2.2.0.pre.3, < 3.0)
|
12
|
+
awesome_print (1.6.1)
|
12
13
|
diff-lcs (1.2.5)
|
13
14
|
minitest (5.5.1)
|
14
15
|
parser (2.2.0.3)
|
@@ -23,7 +24,7 @@ GEM
|
|
23
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
25
|
rspec-support (~> 3.2.0)
|
25
26
|
rspec-support (3.2.2)
|
26
|
-
rubocop (0.
|
27
|
+
rubocop (0.30.0)
|
27
28
|
astrolabe (~> 1.3)
|
28
29
|
parser (>= 2.2.0.1, < 3.0)
|
29
30
|
powerpack (~> 0.1)
|
@@ -35,9 +36,10 @@ PLATFORMS
|
|
35
36
|
ruby
|
36
37
|
|
37
38
|
DEPENDENCIES
|
39
|
+
awesome_print (~> 1.6)
|
38
40
|
bitcoin_reward_era!
|
39
41
|
bundler (~> 1.8)
|
40
|
-
minitest (~> 5.5.1)
|
42
|
+
minitest (~> 5.5, >= 5.5.1)
|
41
43
|
rake (~> 10)
|
42
44
|
rspec-expectations (~> 3.2)
|
43
45
|
rspec-mocks (~> 3.2)
|
data/README.md
CHANGED
data/bitcoin_reward_era.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = 'Bitcoin reward era gem'
|
13
13
|
|
14
14
|
spec.description = "Bitcoin reward era gem.\n" \
|
15
|
-
'100% BigDecimal
|
15
|
+
'100% BigDecimal arithmetic.'
|
16
16
|
|
17
17
|
spec.homepage = 'https://github.com/tmornini/bitcoin_reward_era'
|
18
18
|
spec.license = 'MIT'
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename f }
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
+
spec.add_development_dependency 'awesome_print', '~> 1.6'
|
27
28
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
28
29
|
spec.add_development_dependency 'rake', '~> 10'
|
29
30
|
spec.add_development_dependency 'minitest', '~> 5.5', '>= 5.5.1'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'delegate'
|
4
|
+
require 'bigdecimal'
|
5
|
+
|
6
|
+
module BitcoinRewardEra
|
7
|
+
class Amount < SimpleDelegator
|
8
|
+
def initialize amount
|
9
|
+
super(BigDecimal amount)
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_json _state_ = nil
|
17
|
+
%("#{self}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s pattern = 'F'
|
21
|
+
__getobj__.to_s pattern
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_str
|
25
|
+
to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
require 'bigdecimal'
|
4
3
|
require 'time'
|
5
4
|
|
5
|
+
require 'bitcoin_reward_era/amount'
|
6
|
+
|
6
7
|
module BitcoinRewardEra
|
7
8
|
class Calculator
|
8
|
-
BLOCKS_PER_REWARD_ERA = 210_000
|
9
|
-
SECONDS_PER_REWARD_ERA = BLOCKS_PER_REWARD_ERA * 10 * 60
|
9
|
+
BLOCKS_PER_REWARD_ERA = Amount.new(210_000)
|
10
|
+
SECONDS_PER_REWARD_ERA = Amount.new(BLOCKS_PER_REWARD_ERA * 10 * 60)
|
10
11
|
GENESIS_BLOCK_TIME = Time.at(1_231_006_505).utc
|
11
12
|
|
12
13
|
attr_reader :reward_era_number
|
13
14
|
|
14
15
|
def initialize config
|
15
|
-
@representation_klass = config[:representation_klass] || Representation
|
16
|
-
@bigdecimal_klass = config[:bigdecimal_klass] || BigDecimal
|
17
16
|
@time_klass = config[:time_klass] || Time
|
17
|
+
@amount_klass = config[:amount_klass] || Amount
|
18
18
|
|
19
|
-
@reward_era_number = config[:reward_era_number]
|
19
|
+
@reward_era_number = @amount_klass.new config[:reward_era_number]
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
last_reward_era_number * BLOCKS_PER_REWARD_ERA
|
22
|
+
def first_block
|
23
|
+
Amount.new last_reward_era_number * BLOCKS_PER_REWARD_ERA
|
24
24
|
end
|
25
25
|
|
26
26
|
def btc_per_block
|
27
|
-
|
27
|
+
initial_reward = @amount_klass.new 50
|
28
28
|
|
29
|
-
truncate_at_satoshis
|
29
|
+
truncate_at_satoshis initial_reward / (2**last_reward_era_number)
|
30
30
|
end
|
31
31
|
|
32
32
|
def year
|
33
|
-
|
33
|
+
Amount.new this_year + portion_of_year
|
34
34
|
end
|
35
35
|
|
36
36
|
def start_btc
|
37
|
-
btc_in_circulation = 0
|
37
|
+
btc_in_circulation = BigDecimal 0
|
38
38
|
|
39
39
|
1.upto last_reward_era_number do |ren|
|
40
40
|
btc_in_circulation +=
|
@@ -42,11 +42,11 @@ module BitcoinRewardEra
|
|
42
42
|
.btc_per_block * BLOCKS_PER_REWARD_ERA
|
43
43
|
end
|
44
44
|
|
45
|
-
btc_in_circulation
|
45
|
+
Amount.new btc_in_circulation
|
46
46
|
end
|
47
47
|
|
48
48
|
def btc_added
|
49
|
-
end_btc - start_btc
|
49
|
+
Amount.new end_btc - start_btc
|
50
50
|
end
|
51
51
|
|
52
52
|
def end_btc
|
@@ -54,41 +54,41 @@ module BitcoinRewardEra
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def btc_increase_percentage
|
57
|
-
btc_added / last_calculator.end_btc
|
57
|
+
Amount.new btc_added / last_calculator.end_btc
|
58
58
|
end
|
59
59
|
|
60
60
|
def end_btc_percent_of_limit
|
61
|
-
end_btc / final_calculator.end_btc
|
61
|
+
Amount.new end_btc / final_calculator.end_btc
|
62
62
|
end
|
63
63
|
|
64
64
|
def supply_inflation_rate
|
65
|
-
((1 + btc_increase_percentage)**0.25) - 1
|
65
|
+
Amount.new(((1 + btc_increase_percentage)**0.25) - 1)
|
66
66
|
end
|
67
67
|
|
68
68
|
private
|
69
69
|
|
70
|
+
def truncate_at_satoshis amount
|
71
|
+
string = amount.to_s '8F'
|
72
|
+
|
73
|
+
truncation_match = string.match(/^\d+[.]\d+/)
|
74
|
+
|
75
|
+
@amount_klass.new truncation_match[0]
|
76
|
+
end
|
77
|
+
|
70
78
|
def last_reward_era_number
|
71
|
-
@reward_era_number - 1
|
79
|
+
Amount.new @reward_era_number - 1
|
72
80
|
end
|
73
81
|
|
74
82
|
def next_reward_era_number
|
75
|
-
@reward_era_number + 1
|
83
|
+
Amount.new @reward_era_number + 1
|
76
84
|
end
|
77
85
|
|
78
86
|
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]
|
87
|
+
Amount.new 34
|
88
88
|
end
|
89
89
|
|
90
90
|
def seconds_since_block_zero
|
91
|
-
|
91
|
+
Amount.new first_block * 60 * 10
|
92
92
|
end
|
93
93
|
|
94
94
|
def beginning_of_reward_era
|
@@ -96,28 +96,25 @@ module BitcoinRewardEra
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def this_year
|
99
|
-
beginning_of_reward_era.year
|
99
|
+
Amount.new beginning_of_reward_era.year
|
100
100
|
end
|
101
101
|
|
102
102
|
def portion_of_year
|
103
103
|
next_year = this_year + 1
|
104
104
|
|
105
|
-
beginning_of_this_year =
|
106
|
-
|
105
|
+
beginning_of_this_year =
|
106
|
+
Time.new(this_year, 1, 1, 0, 0, 0, '+00:00').utc.to_i
|
107
|
+
|
108
|
+
beginning_of_next_year =
|
109
|
+
Time.new(next_year, 1, 1, 0, 0, 0, '+00:00').utc.to_i
|
107
110
|
|
108
|
-
|
109
|
-
(beginning_of_reward_era - beginning_of_this_year) /
|
110
|
-
(beginning_of_next_year - beginning_of_this_year)
|
111
|
+
bd_beginning_of_reward_era = BigDecimal beginning_of_reward_era.to_i
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
113
|
+
bd_portion_of_year =
|
114
|
+
BigDecimal(bd_beginning_of_reward_era - beginning_of_this_year) /
|
115
|
+
BigDecimal(beginning_of_next_year - beginning_of_this_year)
|
119
116
|
|
120
|
-
|
117
|
+
Amount.new bd_portion_of_year
|
121
118
|
end
|
122
119
|
|
123
120
|
def last_calculator
|
@@ -11,7 +11,7 @@ module BitcoinRewardEra
|
|
11
11
|
|
12
12
|
def to_representation
|
13
13
|
{
|
14
|
-
|
14
|
+
first_block: @calculator.first_block,
|
15
15
|
reward_era_number: @calculator.reward_era_number,
|
16
16
|
btc_per_block: @calculator.btc_per_block,
|
17
17
|
year: @calculator.year,
|
@@ -26,7 +26,7 @@ module BitcoinRewardEra
|
|
26
26
|
|
27
27
|
def to_s
|
28
28
|
[
|
29
|
-
format('%7d', @calculator.
|
29
|
+
format('%7d', @calculator.first_block),
|
30
30
|
format('%10d', @calculator.reward_era_number),
|
31
31
|
align(@calculator.btc_per_block, 2),
|
32
32
|
align(@calculator.year, 4, 3),
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitcoin_reward_era
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Mornini
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +116,7 @@ dependencies:
|
|
102
116
|
version: '0.29'
|
103
117
|
description: |-
|
104
118
|
Bitcoin reward era gem.
|
105
|
-
100% BigDecimal
|
119
|
+
100% BigDecimal arithmetic.
|
106
120
|
email:
|
107
121
|
- tom@subledger.com
|
108
122
|
executables:
|
@@ -120,6 +134,7 @@ files:
|
|
120
134
|
- bitcoin_reward_era.gemspec
|
121
135
|
- exe/btc_money_supply
|
122
136
|
- lib/bitcoin_reward_era.rb
|
137
|
+
- lib/bitcoin_reward_era/amount.rb
|
123
138
|
- lib/bitcoin_reward_era/calculator.rb
|
124
139
|
- lib/bitcoin_reward_era/report.rb
|
125
140
|
- lib/bitcoin_reward_era/representation.rb
|