vanitygen-wrapper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +11 -1
- data/lib/vanitygen.rb +25 -16
- data/lib/vanitygen/version.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- data/spec/vanitygen_spec.rb +51 -28
- data/vanitygen-wrapper.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7acb4fcb9c91d2780d7fd860a8fc77fc029e059b
|
4
|
+
data.tar.gz: 946aad92bb08fac89a0129d2303c30625c61e832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fe174885c90d8653dbfca10fa42cc8fa55b01f22e19222f88aff97e8d1d9ea2ca0283a67fcef7cee7288fd0b3b6d770e753eb97cf958d4133efd3d50ef05e27
|
7
|
+
data.tar.gz: 861a9d35b6be688a67e4d4426c998b068578287b20fb7962fa312dabf48b31ac1f07142c97fcd80e7bb633648e679db73b1f0bc73af65d72c7e5927a97c26c02
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
0.0.1 - 2014-12-02
|
2
|
+
=====
|
3
|
+
Mostly feature complete:
|
4
|
+
* Vanitygen.network
|
5
|
+
* Vanitygen.valid?
|
6
|
+
* Vanitygen.difficulty
|
7
|
+
* Vanitygen.generate
|
8
|
+
* Vanitygen.continuous
|
9
|
+
|
10
|
+
Options supported:
|
11
|
+
* case_insensitive
|
12
|
+
* regex patterns
|
13
|
+
* that's about it...
|
data/README.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
Thin ruby wrapper around vanitygen executable. Sibling project of <https://github.com/bitvain/vanitygen-ruby>.
|
4
4
|
|
5
|
+
## Warning
|
6
|
+
|
7
|
+
Due to rampant use of pipes, signals, and subprocesses, this gem probably does
|
8
|
+
not work in JRuby or Windows.
|
9
|
+
|
10
|
+
This also cannot be effectively tested in CI due to depending on an external
|
11
|
+
executable.
|
12
|
+
|
13
|
+
Discretion is advised.
|
14
|
+
|
5
15
|
## Installation
|
6
16
|
|
7
17
|
Download and install <https://github.com/samr7/vanitygen>
|
@@ -11,7 +21,7 @@ Make sure `vanitygen` is available in your `$PATH`.
|
|
11
21
|
Add this line to your application's Gemfile:
|
12
22
|
|
13
23
|
```ruby
|
14
|
-
gem 'vanitygen-wrapper', require 'vanitygen'
|
24
|
+
gem 'vanitygen-wrapper', require: 'vanitygen'
|
15
25
|
```
|
16
26
|
|
17
27
|
And then execute:
|
data/lib/vanitygen.rb
CHANGED
@@ -9,8 +9,15 @@ module Vanitygen
|
|
9
9
|
NETWORKS = {
|
10
10
|
bitcoin: nil,
|
11
11
|
testnet3: '-T',
|
12
|
+
namecoin: '-N',
|
13
|
+
litecoin: '-L',
|
12
14
|
}
|
13
15
|
|
16
|
+
attr_accessor :executable
|
17
|
+
def executable
|
18
|
+
@executable ||= 'vanitygen'
|
19
|
+
end
|
20
|
+
|
14
21
|
def network
|
15
22
|
@network ||= :bitcoin
|
16
23
|
end
|
@@ -25,7 +32,7 @@ module Vanitygen
|
|
25
32
|
flags = flags_from({simulate: true,
|
26
33
|
patterns: [pattern]
|
27
34
|
}.merge(options))
|
28
|
-
pid = Process.spawn(
|
35
|
+
pid = Process.spawn(executable, *flags, out: '/dev/null', err: '/dev/null')
|
29
36
|
pid, status = Process.wait2(pid)
|
30
37
|
status == 0
|
31
38
|
end
|
@@ -35,7 +42,7 @@ module Vanitygen
|
|
35
42
|
patterns: [pattern]
|
36
43
|
}.merge(options))
|
37
44
|
msg = ''
|
38
|
-
Open3.popen3(
|
45
|
+
Open3.popen3(executable, *flags) do |stdin, stdout, stderr, wait_thr|
|
39
46
|
stdin.close
|
40
47
|
stdout.close
|
41
48
|
while !stderr.eof?
|
@@ -52,7 +59,7 @@ module Vanitygen
|
|
52
59
|
}.merge(options))
|
53
60
|
|
54
61
|
msg = ''
|
55
|
-
Open3.popen3(
|
62
|
+
Open3.popen3(executable, *flags) do |stdin, stdout, stderr, wait_thr|
|
56
63
|
stdin.close
|
57
64
|
while !stdout.eof?
|
58
65
|
msg << stdout.read
|
@@ -85,23 +92,16 @@ module Vanitygen
|
|
85
92
|
patterns: patterns,
|
86
93
|
}.merge(options))
|
87
94
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
block.call(data)
|
95
|
-
end
|
96
|
-
end
|
95
|
+
# Unfortunately, vanitygen spams stdout with progress
|
96
|
+
pid_vanitygen = Process.spawn(executable, *flags, out: '/dev/null', err: '/dev/null')
|
97
|
+
while child_alive?(pid_vanitygen)
|
98
|
+
File.open(tmp_pipe, 'r') do |file|
|
99
|
+
while !file.eof? and (msg = file.read)
|
100
|
+
parse(msg).each(&block)
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
100
|
-
|
101
|
-
pid_vanitygen = Process.spawn('vanitygen', *flags, out: '/dev/null', err: '/dev/null')
|
102
|
-
Process.wait(pid_vanitygen)
|
103
104
|
ensure
|
104
|
-
thread && thread.kill
|
105
105
|
if pid_vanitygen
|
106
106
|
begin
|
107
107
|
Process.kill('TERM', pid_vanitygen)
|
@@ -120,6 +120,15 @@ module Vanitygen
|
|
120
120
|
|
121
121
|
private
|
122
122
|
|
123
|
+
def child_alive?(pid)
|
124
|
+
# Very unix like
|
125
|
+
# Unfortunately, not very ruby like :(
|
126
|
+
Process.kill(0, pid)
|
127
|
+
true
|
128
|
+
rescue Errno::ESRCH
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
123
132
|
def flags_from(options)
|
124
133
|
[].tap do |flags|
|
125
134
|
patterns =
|
data/lib/vanitygen/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
data/spec/vanitygen_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'vanitygen'
|
2
4
|
|
3
5
|
require 'bitcoin'
|
4
|
-
require 'devnull'
|
5
6
|
require 'timeout'
|
6
7
|
|
7
8
|
describe Vanitygen do
|
@@ -16,16 +17,16 @@ describe Vanitygen do
|
|
16
17
|
subject { Vanitygen.generate(pattern_string_a) }
|
17
18
|
|
18
19
|
it 'has valid address' do
|
19
|
-
|
20
|
+
assert{ Bitcoin.valid_address?(subject[:address]) }
|
20
21
|
end
|
21
22
|
|
22
23
|
it 'has address starting with pattern' do
|
23
|
-
|
24
|
+
assert{ subject[:address].start_with?(pattern_string_a) }
|
24
25
|
end
|
25
26
|
|
26
27
|
it 'has correct private_key to unlock pattern' do
|
27
28
|
bkey = Bitcoin::Key.from_base58(subject[:private_key])
|
28
|
-
|
29
|
+
assert{ subject[:address] == bkey.addr }
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -33,23 +34,25 @@ describe Vanitygen do
|
|
33
34
|
subject { Vanitygen.generate(pattern_regex_ab) }
|
34
35
|
|
35
36
|
it 'has valid address' do
|
36
|
-
|
37
|
+
assert{ Bitcoin.valid_address?(subject[:address]) }
|
37
38
|
end
|
38
39
|
|
39
40
|
it 'has address matching pattern' do
|
40
|
-
|
41
|
+
assert{ subject[:address] =~ pattern_regex_ab }
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
46
|
describe '.continuous' do
|
46
47
|
it 'requires a block' do
|
47
|
-
|
48
|
+
error = rescuing{ Vanitygen.continuous([pattern_any]) }
|
49
|
+
assert{ error.is_a?(LocalJumpError) }
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'requires same type' do
|
51
53
|
noop = proc{}
|
52
|
-
|
54
|
+
error = rescuing{ Vanitygen.continuous([pattern_regex_ab, pattern_string_a], &noop) }
|
55
|
+
assert{ error.is_a?(TypeError) }
|
53
56
|
end
|
54
57
|
|
55
58
|
context 'threaded with capture block' do
|
@@ -80,42 +83,39 @@ describe Vanitygen do
|
|
80
83
|
end
|
81
84
|
|
82
85
|
it 'runs a lot' do
|
83
|
-
|
86
|
+
assert{ captured.count > 10 }
|
84
87
|
end
|
85
88
|
|
86
89
|
it 'returns valid addresses' do
|
87
|
-
|
90
|
+
assert{ captured.all? { |addr| Bitcoin.valid_address?(addr) } }
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
91
94
|
context 'with string' do
|
92
95
|
it 'starts with matching pattern' do
|
93
96
|
continuous_with_timeout([pattern_string_a], &capture(:address))
|
94
|
-
|
95
|
-
|
97
|
+
assert{ captured.size > 1 }
|
98
|
+
assert{ captured.all? { |addr| addr.start_with?(pattern_string_a) } }
|
96
99
|
end
|
97
100
|
|
98
101
|
it 'matches with case insensitivity' do
|
99
102
|
continuous_with_timeout([pattern_string_ab], case_insensitive: true, &capture(:address))
|
100
103
|
prefixes = captured.map { |addr| addr[0..2] }
|
101
|
-
|
104
|
+
assert{ prefixes.uniq.size > 1 }
|
102
105
|
end
|
103
106
|
|
104
107
|
it 'matches multiple patterns' do
|
105
108
|
continuous_with_timeout([pattern_string_a, pattern_string_b], &capture(:address))
|
106
|
-
|
107
|
-
|
108
|
-
# expect(captured).to any(addr.start_with?(pattern_string_b))
|
109
|
-
expect(captured).to satisfy { |a| a.any? { |addr| addr.start_with?(pattern_string_a) } }
|
110
|
-
expect(captured).to satisfy { |a| a.any? { |addr| addr.start_with?(pattern_string_b) } }
|
109
|
+
assert{ captured.any? { |addr| addr.start_with?(pattern_string_a) } }
|
110
|
+
assert{ captured.any? { |addr| addr.start_with?(pattern_string_b) } }
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
context 'with regex' do
|
115
115
|
it 'matches the regex' do
|
116
116
|
continuous_with_timeout([pattern_regex_ab], &capture(:address))
|
117
|
-
|
118
|
-
|
117
|
+
assert{ captured.size > 1 }
|
118
|
+
assert{ captured.all? { |addr| addr =~ pattern_regex_ab } }
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -123,28 +123,51 @@ describe Vanitygen do
|
|
123
123
|
|
124
124
|
describe '.difficulty' do
|
125
125
|
it 'returns difficulty in Numeric' do
|
126
|
-
|
126
|
+
assert{ Vanitygen.difficulty(pattern_string_a).is_a?(Numeric) }
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
130
|
describe '.valid?' do
|
131
131
|
it 'is true for starting with 1' do
|
132
|
-
|
132
|
+
assert{ Vanitygen.valid?('1abc') }
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'is false for starting with something else' do
|
136
|
-
|
136
|
+
assert{ not Vanitygen.valid?('abc') }
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'is false for really long strings' do
|
140
|
-
|
140
|
+
assert{ not Vanitygen.valid?('1abcdefghijklmnopqrstuvwxyz') }
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'is false for illegal characters' do
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
assert{ not Vanitygen.valid?('10') }
|
145
|
+
assert{ not Vanitygen.valid?('1O') }
|
146
|
+
assert{ not Vanitygen.valid?('1I') }
|
147
|
+
assert{ not Vanitygen.valid?('1l') }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '.network' do
|
152
|
+
it 'switches to :testnet3' do
|
153
|
+
assert{ not Vanitygen.valid?('mm') }
|
154
|
+
Vanitygen.network = :testnet3
|
155
|
+
assert{ Vanitygen.valid?('mm') }
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'switches to "testnet3"' do
|
159
|
+
Vanitygen.network = 'testnet3'
|
160
|
+
assert{ Vanitygen.valid?('mm') }
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'stays on :bitcoin' do
|
164
|
+
Vanitygen.network = :bitcoin
|
165
|
+
assert{ Vanitygen.valid?('1a') }
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'dies for missing network' do
|
169
|
+
error = rescuing{ Vanitygen.network = :foobar }
|
170
|
+
assert{ error.message =~ /not supported/ }
|
148
171
|
end
|
149
172
|
end
|
150
173
|
end
|
data/vanitygen-wrapper.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanitygen-wrapper
|
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
|
- Benjamin Feng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mkfifo
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: wrong
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.7.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.7.1
|
97
111
|
description: Thin ruby wrapper around vanitygen executable. Sibling project of <https://github.com/bitvain/vanitygen-ruby>.
|
98
112
|
email:
|
99
113
|
- contact@fengb.info
|
@@ -102,12 +116,14 @@ extensions: []
|
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
118
|
- ".gitignore"
|
119
|
+
- CHANGELOG.md
|
105
120
|
- Gemfile
|
106
121
|
- LICENSE.txt
|
107
122
|
- README.md
|
108
123
|
- Rakefile
|
109
124
|
- lib/vanitygen.rb
|
110
125
|
- lib/vanitygen/version.rb
|
126
|
+
- spec/spec_helper.rb
|
111
127
|
- spec/vanitygen_spec.rb
|
112
128
|
- vanitygen-wrapper.gemspec
|
113
129
|
homepage: https://github.com/bitvain/vanitygen-wrapper
|
@@ -135,4 +151,5 @@ signing_key:
|
|
135
151
|
specification_version: 4
|
136
152
|
summary: Thin ruby wrapper around vanitygen executable
|
137
153
|
test_files:
|
154
|
+
- spec/spec_helper.rb
|
138
155
|
- spec/vanitygen_spec.rb
|