sibit 0.3.0 → 0.3.1
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/bin/sibit +5 -2
- data/features/cli.feature +1 -1
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +34 -17
- data/sibit.gemspec +3 -4
- metadata +14 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f80cc342ac38e79dc1fd04b6bf020fb650b7daf17403082afc90a92fee3732f
|
|
4
|
+
data.tar.gz: bd83f713454e8a6b490b9a5d64982a51928e8a0511aa032bdbfec67a716027e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9021d4dc32b50715c33959e4dbd20a61e2051d0f95dd662581328242140568ad398f4a7af6bf296bede38dc55a5e397d55afc9528e3a2f6bba83388b4f141ee3
|
|
7
|
+
data.tar.gz: 4438637556ea58c5a402f5048156f2d306d09748001a13ca5738d2589d1262795783eed810dff0473f20aa9c1ae4b8f6bff4829b4f52ab5b81e012150547b243
|
data/bin/sibit
CHANGED
|
@@ -76,7 +76,10 @@ Options are:"
|
|
|
76
76
|
raise "Command #{opts.arguments[0]} is not supported"
|
|
77
77
|
end
|
|
78
78
|
rescue StandardError => ex
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
if opts[:verbose]
|
|
80
|
+
puts Backtrace.new(ex).to_s
|
|
81
|
+
else
|
|
82
|
+
puts "ERROR: #{ex.message}"
|
|
83
|
+
end
|
|
81
84
|
exit(255)
|
|
82
85
|
end
|
data/features/cli.feature
CHANGED
|
@@ -15,5 +15,5 @@ Feature: Command Line Processing
|
|
|
15
15
|
Then Exit code is zero
|
|
16
16
|
|
|
17
17
|
Scenario: Bitcoin balance can be checked
|
|
18
|
-
When I run bin/sibit with "balance 1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f"
|
|
18
|
+
When I run bin/sibit with "balance 1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f --verbose"
|
|
19
19
|
Then Exit code is zero
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
# SOFTWARE.
|
|
22
22
|
|
|
23
|
+
require 'net/http'
|
|
24
|
+
require 'uri'
|
|
23
25
|
require 'bitcoin'
|
|
24
|
-
require 'typhoeus'
|
|
25
26
|
require 'json'
|
|
26
27
|
|
|
27
28
|
# Sibit main class.
|
|
@@ -34,21 +35,26 @@ require 'json'
|
|
|
34
35
|
# License:: MIT
|
|
35
36
|
class Sibit
|
|
36
37
|
# Constructor.
|
|
38
|
+
#
|
|
39
|
+
# You may provide the log you want to see the messages in. If you don't
|
|
40
|
+
# provide anything, the console will be used. The object you provide
|
|
41
|
+
# has to respond to the method +debug+ or +puts+ in order to receive logging
|
|
42
|
+
# messages.
|
|
37
43
|
def initialize(log: STDOUT)
|
|
38
44
|
@log = log
|
|
39
45
|
end
|
|
40
46
|
|
|
41
|
-
#
|
|
47
|
+
# Generates new Bitcon private key and returns in Hash160 format.
|
|
42
48
|
def generate
|
|
43
49
|
Bitcoin::Key.generate.priv
|
|
44
50
|
end
|
|
45
51
|
|
|
46
|
-
#
|
|
52
|
+
# Creates Bitcon address using the private key in Hash160 format.
|
|
47
53
|
def create(pvt)
|
|
48
54
|
key(pvt).addr
|
|
49
55
|
end
|
|
50
56
|
|
|
51
|
-
#
|
|
57
|
+
# Gets the balance of the address, in satoshi.
|
|
52
58
|
def balance(address)
|
|
53
59
|
json = get_json("https://blockchain.info/rawaddr/#{address}")
|
|
54
60
|
debug("Total transactions: #{json['n_tx']}")
|
|
@@ -56,7 +62,16 @@ class Sibit
|
|
|
56
62
|
json['final_balance']
|
|
57
63
|
end
|
|
58
64
|
|
|
59
|
-
#
|
|
65
|
+
# Sends a payment and returns the transaction hash.
|
|
66
|
+
#
|
|
67
|
+
# If the payment can't be signed (the key is wrong, for example) or the
|
|
68
|
+
# previous transaction is not found, or there is a network error, or
|
|
69
|
+
# any other reason, you will get an exception. In this case, just try again.
|
|
70
|
+
# It's safe to try as many times as you need. Don't worry about duplicating
|
|
71
|
+
# your transaction, the Bitcoin network will filter duplicates out.
|
|
72
|
+
#
|
|
73
|
+
# If there are more than 1000 UTXOs in the address where you are trying
|
|
74
|
+
# to send bitcoins from, this method won't be helpful.
|
|
60
75
|
#
|
|
61
76
|
# +pvt+: the private key as a Hash160 string
|
|
62
77
|
# +amount+: the amount either in satoshis or ending with 'BTC', like '0.7BTC'
|
|
@@ -127,22 +142,24 @@ class Sibit
|
|
|
127
142
|
key
|
|
128
143
|
end
|
|
129
144
|
|
|
145
|
+
def age(start)
|
|
146
|
+
"#{((Time.now - start) * 1000).round}ms"
|
|
147
|
+
end
|
|
148
|
+
|
|
130
149
|
def post_tx(body)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
debug("POST #{uri}: #{response.code}")
|
|
150
|
+
start = Time.now
|
|
151
|
+
uri = URI('https://blockchain.info/pushtx')
|
|
152
|
+
res = Net::HTTP.post_form(uri, tx: body)
|
|
153
|
+
raise "Failed to post tx to #{uri}: #{res.code}" unless res.code == '200'
|
|
154
|
+
debug("POST #{uri}: #{res.code} in #{age(start)}")
|
|
137
155
|
end
|
|
138
156
|
|
|
139
157
|
def get_json(uri)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
JSON.parse(response.body)
|
|
158
|
+
start = Time.now
|
|
159
|
+
res = Net::HTTP.get_response(URI(uri))
|
|
160
|
+
raise "Failed to retrieve #{uri}: #{res.code}" unless res.code == '200'
|
|
161
|
+
debug("GET #{uri}: #{res.code} in #{age(start)}")
|
|
162
|
+
JSON.parse(res.body)
|
|
146
163
|
end
|
|
147
164
|
|
|
148
165
|
def debug(msg)
|
data/sibit.gemspec
CHANGED
|
@@ -48,11 +48,10 @@ and Ruby 2.3+.'
|
|
|
48
48
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
|
49
49
|
s.rdoc_options = ['--charset=UTF-8']
|
|
50
50
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
|
51
|
-
s.add_runtime_dependency 'backtrace', '0.3
|
|
51
|
+
s.add_runtime_dependency 'backtrace', '>=0.3'
|
|
52
52
|
s.add_runtime_dependency 'bitcoin', '0.2.0'
|
|
53
|
-
s.add_runtime_dependency 'json', '2
|
|
54
|
-
s.add_runtime_dependency 'slop', '4.6
|
|
55
|
-
s.add_runtime_dependency 'typhoeus', '1.3.1'
|
|
53
|
+
s.add_runtime_dependency 'json', '>=2'
|
|
54
|
+
s.add_runtime_dependency 'slop', '>=4.6'
|
|
56
55
|
s.add_development_dependency 'codecov', '0.1.10'
|
|
57
56
|
s.add_development_dependency 'cucumber', '1.3.17'
|
|
58
57
|
s.add_development_dependency 'debase', '0.2.2'
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sibit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-04-
|
|
11
|
+
date: 2019-04-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- -
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.3
|
|
19
|
+
version: '0.3'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- -
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.3
|
|
26
|
+
version: '0.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bitcoin
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -42,44 +42,30 @@ dependencies:
|
|
|
42
42
|
name: json
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 2
|
|
47
|
+
version: '2'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 2
|
|
54
|
+
version: '2'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: slop
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- -
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 4.6
|
|
61
|
+
version: '4.6'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- -
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: 4.6.2
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: typhoeus
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - '='
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: 1.3.1
|
|
76
|
-
type: :runtime
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - '='
|
|
66
|
+
- - ">="
|
|
81
67
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
68
|
+
version: '4.6'
|
|
83
69
|
- !ruby/object:Gem::Dependency
|
|
84
70
|
name: codecov
|
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|