voucher 0.2.1 → 0.3.0
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/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +11 -7
- data/README.md +43 -1
- data/lib/voucher.rb +4 -3
- data/lib/voucher/chain_contract.rb +46 -0
- data/lib/voucher/cli.rb +1 -1
- data/lib/voucher/config.rb +17 -9
- data/lib/voucher/config/json/chain.json +753 -0
- data/lib/voucher/errors.rb +2 -2
- data/lib/voucher/metrics.rb +339 -0
- data/lib/voucher/model/segment.rb +45 -95
- data/lib/voucher/validator.rb +4 -4
- data/lib/voucher/version.rb +1 -1
- data/voucher.gemspec +2 -1
- metadata +21 -6
- data/lib/voucher/config/json/election.json +0 -210
- data/lib/voucher/election_contract.rb +0 -41
data/lib/voucher/validator.rb
CHANGED
@@ -22,7 +22,7 @@ module Voucher
|
|
22
22
|
|
23
23
|
def verify(segment)
|
24
24
|
Murky.verify(
|
25
|
-
contract.winning_hash(segment.shard),
|
25
|
+
contract.winning_hash(election.attributes[:block_number], segment.shard),
|
26
26
|
segment.siblings,
|
27
27
|
segment.hash,
|
28
28
|
digest: Hashtastic::EthereumSHA3
|
@@ -30,10 +30,10 @@ module Voucher
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def contract
|
33
|
-
@contract ||=
|
33
|
+
@contract ||= ChainContract.new(
|
34
34
|
address: election.address,
|
35
|
-
ethereum_url:
|
36
|
-
abi:
|
35
|
+
ethereum_url: Config.ethereum_url,
|
36
|
+
abi: Config.chain_abi
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
data/lib/voucher/version.rb
CHANGED
data/voucher.gemspec
CHANGED
@@ -27,8 +27,9 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'ethereum.rb', '~> 2.2'
|
28
28
|
spec.add_dependency 'hashtastic'
|
29
29
|
spec.add_dependency 'murky_waters'
|
30
|
+
spec.add_dependency 'mixlib-config'
|
30
31
|
|
31
|
-
spec.add_development_dependency 'bundler', '~>
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
33
|
spec.add_development_dependency 'pry', '~> 0.11.3'
|
33
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
34
35
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voucher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lucidity
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,20 +94,34 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mixlib-config
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '2.0'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
124
|
+
version: '2.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: pry
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,11 +203,12 @@ files:
|
|
189
203
|
- bin/setup
|
190
204
|
- exe/voucher
|
191
205
|
- lib/voucher.rb
|
206
|
+
- lib/voucher/chain_contract.rb
|
192
207
|
- lib/voucher/cli.rb
|
193
208
|
- lib/voucher/config.rb
|
194
|
-
- lib/voucher/config/json/
|
195
|
-
- lib/voucher/election_contract.rb
|
209
|
+
- lib/voucher/config/json/chain.json
|
196
210
|
- lib/voucher/errors.rb
|
211
|
+
- lib/voucher/metrics.rb
|
197
212
|
- lib/voucher/model/election.rb
|
198
213
|
- lib/voucher/model/segment.rb
|
199
214
|
- lib/voucher/segments_builder.rb
|
@@ -1,210 +0,0 @@
|
|
1
|
-
[
|
2
|
-
{
|
3
|
-
"constant": true,
|
4
|
-
"inputs": [],
|
5
|
-
"name": "endsAt",
|
6
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
7
|
-
"payable": false,
|
8
|
-
"stateMutability": "view",
|
9
|
-
"type": "function"
|
10
|
-
},
|
11
|
-
{
|
12
|
-
"constant": true,
|
13
|
-
"inputs": [],
|
14
|
-
"name": "chairperson",
|
15
|
-
"outputs": [{"name": "", "type": "address"}],
|
16
|
-
"payable": false,
|
17
|
-
"stateMutability": "view",
|
18
|
-
"type": "function"
|
19
|
-
},
|
20
|
-
{
|
21
|
-
"constant": true,
|
22
|
-
"inputs": [],
|
23
|
-
"name": "revealed",
|
24
|
-
"outputs": [{"name": "", "type": "bool"}],
|
25
|
-
"payable": false,
|
26
|
-
"stateMutability": "view",
|
27
|
-
"type": "function"
|
28
|
-
},
|
29
|
-
{
|
30
|
-
"constant": true,
|
31
|
-
"inputs": [],
|
32
|
-
"name": "blockNumber",
|
33
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
34
|
-
"payable": false,
|
35
|
-
"stateMutability": "view",
|
36
|
-
"type": "function"
|
37
|
-
},
|
38
|
-
{
|
39
|
-
"constant": true,
|
40
|
-
"inputs": [{"name": "", "type": "bytes32"}],
|
41
|
-
"name": "blindedProposals",
|
42
|
-
"outputs": [{"name": "", "type": "bool"}],
|
43
|
-
"payable": false,
|
44
|
-
"stateMutability": "view",
|
45
|
-
"type": "function"
|
46
|
-
},
|
47
|
-
{
|
48
|
-
"constant": true,
|
49
|
-
"inputs": [],
|
50
|
-
"name": "chainAddress",
|
51
|
-
"outputs": [{"name": "", "type": "address"}],
|
52
|
-
"payable": false,
|
53
|
-
"stateMutability": "view",
|
54
|
-
"type": "function"
|
55
|
-
},
|
56
|
-
{
|
57
|
-
"constant": true,
|
58
|
-
"inputs": [],
|
59
|
-
"name": "votingEnd",
|
60
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
61
|
-
"payable": false,
|
62
|
-
"stateMutability": "view",
|
63
|
-
"type": "function"
|
64
|
-
},
|
65
|
-
{
|
66
|
-
"constant": true,
|
67
|
-
"inputs": [],
|
68
|
-
"name": "previousRoot",
|
69
|
-
"outputs": [{"name": "", "type": "bytes32"}],
|
70
|
-
"payable": false,
|
71
|
-
"stateMutability": "view",
|
72
|
-
"type": "function"
|
73
|
-
},
|
74
|
-
{
|
75
|
-
"constant": true,
|
76
|
-
"inputs": [{"name": "", "type": "address"}],
|
77
|
-
"name": "voters",
|
78
|
-
"outputs": [
|
79
|
-
{"name": "voted", "type": "bool"},
|
80
|
-
{"name": "blindedProposal", "type": "bytes32"},
|
81
|
-
{"name": "shard", "type": "uint256"},
|
82
|
-
{"name": "proposal", "type": "bytes32"},
|
83
|
-
{"name": "revealed", "type": "bool"}
|
84
|
-
],
|
85
|
-
"payable": false,
|
86
|
-
"stateMutability": "view",
|
87
|
-
"type": "function"
|
88
|
-
},
|
89
|
-
{
|
90
|
-
"constant": true,
|
91
|
-
"inputs": [],
|
92
|
-
"name": "revealEnd",
|
93
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
94
|
-
"payable": false,
|
95
|
-
"stateMutability": "view",
|
96
|
-
"type": "function"
|
97
|
-
},
|
98
|
-
{
|
99
|
-
"constant": true,
|
100
|
-
"inputs": [],
|
101
|
-
"name": "startsAt",
|
102
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
103
|
-
"payable": false,
|
104
|
-
"stateMutability": "view",
|
105
|
-
"type": "function"
|
106
|
-
},
|
107
|
-
{
|
108
|
-
"constant": true,
|
109
|
-
"inputs": [{"name": "", "type": "uint256"}],
|
110
|
-
"name": "roots",
|
111
|
-
"outputs": [{"name": "", "type": "bytes32"}],
|
112
|
-
"payable": false,
|
113
|
-
"stateMutability": "view",
|
114
|
-
"type": "function"
|
115
|
-
},
|
116
|
-
{
|
117
|
-
"constant": true,
|
118
|
-
"inputs": [],
|
119
|
-
"name": "registryAddress",
|
120
|
-
"outputs": [{"name": "", "type": "address"}],
|
121
|
-
"payable": false,
|
122
|
-
"stateMutability": "view",
|
123
|
-
"type": "function"
|
124
|
-
},
|
125
|
-
{
|
126
|
-
"constant": true,
|
127
|
-
"inputs": [{"name": "", "type": "uint256"}],
|
128
|
-
"name": "addresses",
|
129
|
-
"outputs": [{"name": "", "type": "address"}],
|
130
|
-
"payable": false,
|
131
|
-
"stateMutability": "view",
|
132
|
-
"type": "function"
|
133
|
-
},
|
134
|
-
{
|
135
|
-
"constant": true,
|
136
|
-
"inputs": [],
|
137
|
-
"name": "counted",
|
138
|
-
"outputs": [{"name": "", "type": "bool"}],
|
139
|
-
"payable": false,
|
140
|
-
"stateMutability": "view",
|
141
|
-
"type": "function"
|
142
|
-
},
|
143
|
-
{
|
144
|
-
"constant": true,
|
145
|
-
"inputs": [
|
146
|
-
{"name": "", "type": "uint256"},
|
147
|
-
{"name": "", "type": "bytes32"}
|
148
|
-
],
|
149
|
-
"name": "counts",
|
150
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
151
|
-
"payable": false,
|
152
|
-
"stateMutability": "view",
|
153
|
-
"type": "function"
|
154
|
-
},
|
155
|
-
{
|
156
|
-
"inputs": [
|
157
|
-
{"name": "_registryAddress", "type": "address"},
|
158
|
-
{"name": "_chainAddress", "type": "address"},
|
159
|
-
{"name": "_chairperson", "type": "address"},
|
160
|
-
{"name": "_blockNumber", "type": "uint256"},
|
161
|
-
{"name": "_previousRoot", "type": "bytes32"},
|
162
|
-
{"name": "_startsAt", "type": "uint256"},
|
163
|
-
{"name": "_endsAt", "type": "uint256"},
|
164
|
-
{"name": "_votingTime", "type": "uint256"},
|
165
|
-
{"name": "_revealTime", "type": "uint256"}
|
166
|
-
],
|
167
|
-
"payable": false,
|
168
|
-
"stateMutability": "nonpayable",
|
169
|
-
"type": "constructor"
|
170
|
-
},
|
171
|
-
{
|
172
|
-
"constant": true,
|
173
|
-
"inputs": [],
|
174
|
-
"name": "getNumberOfVerifiers",
|
175
|
-
"outputs": [{"name": "", "type": "uint256"}],
|
176
|
-
"payable": false,
|
177
|
-
"stateMutability": "view",
|
178
|
-
"type": "function"
|
179
|
-
},
|
180
|
-
{
|
181
|
-
"constant": false,
|
182
|
-
"inputs": [{"name": "_blindedProposal", "type": "bytes32"}],
|
183
|
-
"name": "vote",
|
184
|
-
"outputs": [],
|
185
|
-
"payable": false,
|
186
|
-
"stateMutability": "nonpayable",
|
187
|
-
"type": "function"
|
188
|
-
},
|
189
|
-
{
|
190
|
-
"constant": false,
|
191
|
-
"inputs": [
|
192
|
-
{"name": "_proposal", "type": "bytes32"},
|
193
|
-
{"name": "_secret", "type": "bytes32"}
|
194
|
-
],
|
195
|
-
"name": "reveal",
|
196
|
-
"outputs": [],
|
197
|
-
"payable": false,
|
198
|
-
"stateMutability": "nonpayable",
|
199
|
-
"type": "function"
|
200
|
-
},
|
201
|
-
{
|
202
|
-
"constant": false,
|
203
|
-
"inputs": [],
|
204
|
-
"name": "count",
|
205
|
-
"outputs": [],
|
206
|
-
"payable": false,
|
207
|
-
"stateMutability": "nonpayable",
|
208
|
-
"type": "function"
|
209
|
-
}
|
210
|
-
]
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Voucher
|
4
|
-
class ElectionContract
|
5
|
-
attr_reader :contract, :ethereum
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
@ethereum = Ethereum::HttpClient.new(options[:ethereum_url])
|
9
|
-
|
10
|
-
@contract = Ethereum::Contract.create(
|
11
|
-
name: options[:name] || 'ElectionContractClient',
|
12
|
-
address: options[:address],
|
13
|
-
abi: options[:abi],
|
14
|
-
client: ethereum
|
15
|
-
)
|
16
|
-
|
17
|
-
@roots = {}
|
18
|
-
@formatter = Ethereum::Formatter.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def winning_hash(shard)
|
22
|
-
@roots[shard] ||= find_root(shard)
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def find_root(shard)
|
28
|
-
root = contract.call.roots(shard)
|
29
|
-
|
30
|
-
raise RootHashNotFound, shard if root.blank?
|
31
|
-
|
32
|
-
eth_format(root)
|
33
|
-
end
|
34
|
-
|
35
|
-
def eth_format(value)
|
36
|
-
hex = @formatter.from_ascii(value)
|
37
|
-
|
38
|
-
"0x#{hex}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|