sibit 0.7.8 → 0.8.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/.rubocop.yml +1 -1
- data/README.md +2 -0
- data/bin/sibit +5 -1
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +37 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd8d72ab658b0424c135882a0787001395a69db720bc8283cf6b2155729c5a96
|
|
4
|
+
data.tar.gz: 37c2fab8a0bd840620e57c2a38ac831dcab13232f6274299c11477675e41734a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e70e784fdf68578e1919ce2989cdfb53c8fc50289e41b57d5df0429fdb28d6679eaf0e558f34112517019f372b16f0c2212b45b7c5104ad3bafd704cf3516b8
|
|
7
|
+
data.tar.gz: 11123bef8e29dde1689907f4536325f807510e9dd3dd10002afea284925176b37543060083ea17a8934e72d43a88cb2fc51c86697938d565bcfceb0d1487b937
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
[](http://www.0pdd.com/p?name=yegor256/sibit)
|
|
11
11
|
[](http://badge.fury.io/rb/sibit)
|
|
12
12
|
[](https://codeclimate.com/github/yegor256/sibit/maintainability)
|
|
13
|
+
|
|
13
14
|
[](https://codecov.io/github/yegor256/sibit?branch=master)
|
|
15
|
+
[](https://hitsofcode.com/view/github/yegor256/sibit)
|
|
14
16
|
|
|
15
17
|
To understand how Bitcoin protocol works, I recommend you watching
|
|
16
18
|
this [short video](https://www.youtube.com/watch?v=IV9pRBq5A4g).
|
data/bin/sibit
CHANGED
|
@@ -38,6 +38,7 @@ Commands are:
|
|
|
38
38
|
balance: Check the balance of the Bitcoin address
|
|
39
39
|
pay: Send a new Bitcoin transaction
|
|
40
40
|
Options are:"
|
|
41
|
+
o.string '--proxy', 'HTTPS proxy for all requests, e.g. "localhost:3128"'
|
|
41
42
|
o.bool '--help', 'Read this: https://github.com/yegor256/sibit' do
|
|
42
43
|
puts o
|
|
43
44
|
exit
|
|
@@ -48,7 +49,10 @@ Options are:"
|
|
|
48
49
|
raise "#{ex.message}"
|
|
49
50
|
end
|
|
50
51
|
raise 'Try --help' if opts.arguments.empty?
|
|
51
|
-
sibit = Sibit.new(
|
|
52
|
+
sibit = Sibit.new(
|
|
53
|
+
log: opts[:verbose] ? STDOUT : nil,
|
|
54
|
+
http: opts[:proxy] ? Sibit.proxy_http(opts[:proxy]) : Sibit.default_http
|
|
55
|
+
)
|
|
52
56
|
case opts.arguments[0]
|
|
53
57
|
when 'price'
|
|
54
58
|
puts sibit.price
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED
|
@@ -24,6 +24,7 @@ require 'net/http'
|
|
|
24
24
|
require 'uri'
|
|
25
25
|
require 'bitcoin'
|
|
26
26
|
require 'json'
|
|
27
|
+
require 'cgi'
|
|
27
28
|
|
|
28
29
|
# Sibit main class.
|
|
29
30
|
#
|
|
@@ -68,14 +69,30 @@ class Sibit
|
|
|
68
69
|
end
|
|
69
70
|
end
|
|
70
71
|
|
|
72
|
+
# This HTTP client will be used by default.
|
|
73
|
+
def self.default_http
|
|
74
|
+
http = Net::HTTP.new('blockchain.info', 443)
|
|
75
|
+
http.use_ssl = true
|
|
76
|
+
http
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# This HTTP client with proxy.
|
|
80
|
+
def self.proxy_http(addr)
|
|
81
|
+
host, port = addr.split(':')
|
|
82
|
+
http = Net::HTTP.new('blockchain.info', 443, host, port.to_i)
|
|
83
|
+
http.use_ssl = true
|
|
84
|
+
http
|
|
85
|
+
end
|
|
86
|
+
|
|
71
87
|
# Constructor.
|
|
72
88
|
#
|
|
73
89
|
# You may provide the log you want to see the messages in. If you don't
|
|
74
90
|
# provide anything, the console will be used. The object you provide
|
|
75
91
|
# has to respond to the method +info+ or +puts+ in order to receive logging
|
|
76
92
|
# messages.
|
|
77
|
-
def initialize(log: STDOUT)
|
|
93
|
+
def initialize(log: STDOUT, http: Sibit.default_http)
|
|
78
94
|
@log = log
|
|
95
|
+
@http = http
|
|
79
96
|
end
|
|
80
97
|
|
|
81
98
|
# Current price of 1 BTC.
|
|
@@ -181,7 +198,12 @@ class Sibit
|
|
|
181
198
|
# response for correctness.
|
|
182
199
|
def get_json(uri)
|
|
183
200
|
start = Time.now
|
|
184
|
-
res =
|
|
201
|
+
res = @http.get(
|
|
202
|
+
uri,
|
|
203
|
+
'Accept' => 'text/plain',
|
|
204
|
+
'User-Agent' => user_agent,
|
|
205
|
+
'Accept-Encoding' => ''
|
|
206
|
+
)
|
|
185
207
|
raise Error, "Failed to retrieve #{uri} (#{res.code}): #{res.body}" unless res.code == '200'
|
|
186
208
|
info("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
|
|
187
209
|
JSON.parse(res.body)
|
|
@@ -224,8 +246,15 @@ class Sibit
|
|
|
224
246
|
|
|
225
247
|
def post_tx(body)
|
|
226
248
|
start = Time.now
|
|
227
|
-
uri =
|
|
228
|
-
res =
|
|
249
|
+
uri = '/pushtx'
|
|
250
|
+
res = @http.post(
|
|
251
|
+
'/pushtx',
|
|
252
|
+
"tx=#{CGI.escape(body)}",
|
|
253
|
+
'Accept' => 'text/plain',
|
|
254
|
+
'User-Agent' => user_agent,
|
|
255
|
+
'Accept-Encoding' => '',
|
|
256
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
|
257
|
+
)
|
|
229
258
|
raise Error, "Failed to post tx to #{uri}: #{res.code}\n#{res.body}" unless res.code == '200'
|
|
230
259
|
info("POST #{uri}: #{res.code} in #{age(start)}")
|
|
231
260
|
end
|
|
@@ -237,4 +266,8 @@ class Sibit
|
|
|
237
266
|
@log.puts(msg)
|
|
238
267
|
end
|
|
239
268
|
end
|
|
269
|
+
|
|
270
|
+
def user_agent
|
|
271
|
+
"Anonymous/#{Sibit::VERSION}"
|
|
272
|
+
end
|
|
240
273
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sibit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
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-
|
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|