sibit 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/bin/sibit +4 -1
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +35 -21
- 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: abe4c1faeac9709e415789d44665ea4085bbb8b32a17c24513f4253dc348ff06
|
4
|
+
data.tar.gz: eb36a0305ec3ec0a2a402ff2b82daa14e4a4033b9b9634b3e3f187da762316ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac511a6fc0ab21f688cd15785d0c6d802ad207d6a30c7229297d8da2e6bfae9304d8c50c69dee4e16589b52d870d50d2584ce08a912aa0c74b9e97e938d27429
|
7
|
+
data.tar.gz: e9a5dea41cd26bb9af6afa4d764e23ac61793b5c465827e687d467255237792295b3a6a59e5b4d8cdacd1d3382f457df8629b5f9ea9cd99ecc620eedd5090e26
|
data/README.md
CHANGED
@@ -77,6 +77,10 @@ The transaction hash will be returned.
|
|
77
77
|
Not all [UTXOs](https://en.wikipedia.org/wiki/Unspent_transaction_output)
|
78
78
|
will be used, but only the necessary amount of them.
|
79
79
|
|
80
|
+
It is recommended to run it with `--dry --verbose` options first, to see
|
81
|
+
what's going to be sent to the network. If everything looks correct, remove
|
82
|
+
the `--dry` and run again, the transaction will be pushed to the network.
|
83
|
+
|
80
84
|
All operations are performed through the
|
81
85
|
[Blockchain API](https://www.blockchain.com/api/blockchain_api).
|
82
86
|
Transactions are pushed to the Bitcoin network via
|
data/bin/sibit
CHANGED
@@ -39,6 +39,8 @@ Commands are:
|
|
39
39
|
pay: Send a new Bitcoin transaction
|
40
40
|
Options are:"
|
41
41
|
o.string '--proxy', 'HTTPS proxy for all requests, e.g. "localhost:3128"'
|
42
|
+
o.integer '--attempts',
|
43
|
+
'How many times should we try before failing', default: 1
|
42
44
|
o.bool '--dry', 'Don\'t send a real payment, run in a read-only mode'
|
43
45
|
o.bool '--help', 'Read this: https://github.com/yegor256/sibit' do
|
44
46
|
puts o
|
@@ -53,7 +55,8 @@ Options are:"
|
|
53
55
|
sibit = Sibit.new(
|
54
56
|
log: opts[:verbose] ? STDOUT : nil,
|
55
57
|
http: opts[:proxy] ? Sibit.proxy_http(opts[:proxy]) : Sibit.default_http,
|
56
|
-
dry: opts[:dry]
|
58
|
+
dry: opts[:dry],
|
59
|
+
attempts: opts[:attempts]
|
57
60
|
)
|
58
61
|
case opts.arguments[0]
|
59
62
|
when 'price'
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED
@@ -91,10 +91,11 @@ class Sibit
|
|
91
91
|
# provide anything, the console will be used. The object you provide
|
92
92
|
# has to respond to the method +info+ or +puts+ in order to receive logging
|
93
93
|
# messages.
|
94
|
-
def initialize(log: STDOUT, http: Sibit.default_http, dry: false)
|
94
|
+
def initialize(log: STDOUT, http: Sibit.default_http, dry: false, attempts: 1)
|
95
95
|
@log = log
|
96
96
|
@http = http
|
97
97
|
@dry = dry
|
98
|
+
@attempts = attempts
|
98
99
|
end
|
99
100
|
|
100
101
|
# Current price of 1 BTC.
|
@@ -202,15 +203,22 @@ class Sibit
|
|
202
203
|
# response for correctness.
|
203
204
|
def get_json(uri)
|
204
205
|
start = Time.now
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
206
|
+
attempt = 0
|
207
|
+
begin
|
208
|
+
res = @http.get(
|
209
|
+
uri,
|
210
|
+
'Accept' => 'text/plain',
|
211
|
+
'User-Agent' => user_agent,
|
212
|
+
'Accept-Encoding' => ''
|
213
|
+
)
|
214
|
+
raise Error, "Failed to retrieve #{uri} (#{res.code}): #{res.body}" unless res.code == '200'
|
215
|
+
info("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
|
216
|
+
JSON.parse(res.body)
|
217
|
+
rescue StandardError => e
|
218
|
+
attempt += 1
|
219
|
+
raise e if attempt >= @attempts
|
220
|
+
retry
|
221
|
+
end
|
214
222
|
end
|
215
223
|
|
216
224
|
private
|
@@ -254,17 +262,23 @@ class Sibit
|
|
254
262
|
|
255
263
|
def post_tx(body)
|
256
264
|
start = Time.now
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
265
|
+
begin
|
266
|
+
uri = '/pushtx'
|
267
|
+
res = @http.post(
|
268
|
+
'/pushtx',
|
269
|
+
"tx=#{CGI.escape(body)}",
|
270
|
+
'Accept' => 'text/plain',
|
271
|
+
'User-Agent' => user_agent,
|
272
|
+
'Accept-Encoding' => '',
|
273
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
274
|
+
)
|
275
|
+
raise Error, "Failed to post tx to #{uri}: #{res.code}\n#{res.body}" unless res.code == '200'
|
276
|
+
info("POST #{uri}: #{res.code} in #{age(start)}")
|
277
|
+
rescue StandardError => e
|
278
|
+
attempt += 1
|
279
|
+
raise e if attempt >= @attempts
|
280
|
+
retry
|
281
|
+
end
|
268
282
|
end
|
269
283
|
|
270
284
|
def info(msg)
|
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.10.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-05-
|
11
|
+
date: 2019-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|