sibit 0.29.1 → 0.30.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16d749128c92e0a715c1545d8cb6aa6a41a4afcbd7fc39db0e708fa87ea7383d
4
- data.tar.gz: c522bc105501aedd9f3ef6140ac99bb1b18cec23fc060ff8dd6ceed4d4e69dff
3
+ metadata.gz: 1dd376cf7257a4cf89035007b18896c215315cacacf9f5d228afc27c9f279cb3
4
+ data.tar.gz: a610165efa18b499479a81816086e8ddad79399ee6d2e0d780594f5b38c18e91
5
5
  SHA512:
6
- metadata.gz: 854ede7b60a6cd9e1334341b14f1b712e002b23499a5a192d61b53380b68d3203f4d7c3d0aaa87499d59a885190345e776410e1eb133f26f85b8aaac260772ed
7
- data.tar.gz: f99cee0f4d8615d0a39ee7609c697b4238e0e867193934564d5f2d29cfffe454b630b8da0f4e7f1bda9620d57d395bdf4b365614cf318c6079b808dab330cc2f
6
+ metadata.gz: 588b35b318760b910ba00f2ed13af88ba325f59e21191faab27d7596771d54c9f4e5a6d419d80e6a3e6f4594a1089bfaf58ef107ccf7e78f738aa9258c181a19
7
+ data.tar.gz: b347020232596daa847f6b3398f9cdaa7ad56ea6b03cf157377a8652922d93e7df33c18d639f1ee6bd324254fd453e24fb2992a8cea76ec00b3814ecc6081ae6
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  sibit (0.0.0)
5
5
  backtrace (~> 0.3)
6
+ decoor (~> 0.1)
6
7
  iri (~> 0.5)
7
8
  json (~> 2)
8
9
  loog (~> 0.6)
@@ -57,6 +58,7 @@ GEM
57
58
  cucumber-messages (31.1.0)
58
59
  cucumber-tag-expressions (8.1.0)
59
60
  date (3.5.1)
61
+ decoor (0.1.0)
60
62
  diff-lcs (1.6.2)
61
63
  docile (1.4.1)
62
64
  elapsed (0.2.1)
@@ -75,7 +77,6 @@ GEM
75
77
  logger (~> 1.0)
76
78
  memoist3 (1.0.0)
77
79
  mini_mime (1.1.5)
78
- mini_portile2 (2.8.9)
79
80
  minitest (6.0.1)
80
81
  prism (~> 1.5)
81
82
  minitest-reporters (1.7.1)
@@ -84,8 +85,9 @@ GEM
84
85
  minitest (>= 5.0)
85
86
  ruby-progressbar
86
87
  multi_test (1.1.0)
87
- nokogiri (1.18.10)
88
- mini_portile2 (~> 2.8.2)
88
+ nokogiri (1.18.10-arm64-darwin)
89
+ racc (~> 1.4)
90
+ nokogiri (1.18.10-x86_64-linux-gnu)
89
91
  racc (~> 1.4)
90
92
  openssl (4.0.0)
91
93
  os (1.1.4)
data/README.md CHANGED
@@ -88,6 +88,18 @@ It is recommended to run it with `--dry --verbose` options first,
88
88
  If everything looks correct, remove the `--dry` and run again,
89
89
  the transaction is pushed to the network.
90
90
 
91
+ To use an HTTPS proxy for all requests:
92
+
93
+ ```bash
94
+ sibit --proxy=host:port balance 1PfsYNygsuVL8fvBarJNQnHytkg4rGih1U
95
+ ```
96
+
97
+ The proxy address may include authentication credentials:
98
+
99
+ ```bash
100
+ sibit --proxy=user:password@host:port balance 1PfsYNygsuVL8fvBarJNQnHytkg4rGih1U
101
+ ```
102
+
91
103
  All operations are performed through the [Blockchain API].
92
104
  Transactions are pushed to the Bitcoin network via [this relay].
93
105
 
data/bin/sibit CHANGED
@@ -12,11 +12,13 @@ require 'retriable_proxy'
12
12
  require 'slop'
13
13
  require_relative '../lib/sibit'
14
14
  require_relative '../lib/sibit/http'
15
+ require_relative '../lib/sibit/httpproxy'
15
16
  require_relative '../lib/sibit/bitcoinchain'
16
17
  require_relative '../lib/sibit/blockchain'
17
18
  require_relative '../lib/sibit/blockchair'
18
19
  require_relative '../lib/sibit/btc'
19
20
  require_relative '../lib/sibit/cex'
21
+ require_relative '../lib/sibit/dry'
20
22
  require_relative '../lib/sibit/fake'
21
23
  require_relative '../lib/sibit/firstof'
22
24
  require_relative '../lib/sibit/version'
@@ -61,32 +63,33 @@ Options are:"
61
63
  raise e.message
62
64
  end
63
65
 
66
+ raise 'Try --help' if opts.arguments.empty?
67
+
64
68
  begin
65
- raise 'Try --help' if opts.arguments.empty?
66
69
  log = opts[:verbose] ? Loog::VERBOSE : Loog::NULL
67
70
  http = opts[:proxy] ? Sibit::HttpProxy.new(opts[:proxy]) : Sibit::Http.new
68
71
  apis = opts[:api].map(&:downcase).map do |a|
69
- api = nil
70
72
  case a
71
73
  when 'blockchain'
72
- api = Sibit::Blockchain.new(http: http, log: log, dry: opts[:dry])
74
+ Sibit::Blockchain.new(http: http, log: log)
73
75
  when 'btc'
74
- api = Sibit::Btc.new(http: http, log: log, dry: opts[:dry])
76
+ Sibit::Btc.new(http: http, log: log)
75
77
  when 'bitcoinchain'
76
- api = Sibit::Bitcoinchain.new(http: http, log: log, dry: opts[:dry])
78
+ Sibit::Bitcoinchain.new(http: http, log: log)
77
79
  when 'blockchair'
78
- api = Sibit::Blockchair.new(http: http, log: log, dry: opts[:dry])
80
+ Sibit::Blockchair.new(http: http, log: log)
79
81
  when 'cex'
80
- api = Sibit::Cex.new(http: http, log: log, dry: opts[:dry])
82
+ Sibit::Cex.new(http: http, log: log)
81
83
  when 'fake'
82
- api = Sibit::Fake.new
84
+ Sibit::Fake.new
83
85
  else
84
86
  raise Sibit::Error, "Unknown API \"#{a}\""
85
87
  end
86
- api = RetriableProxy.for_object(api, on: Sibit::Error) if opts[:attempts] > 1
87
- api
88
88
  end
89
- sibit = Sibit.new(log: log, api: Sibit::FirstOf.new(apis, log: log, verbose: true))
89
+ api = Sibit::FirstOf.new(apis, log: log, verbose: true)
90
+ api = Sibit::Dry.new(api, log: log) if opts[:dry]
91
+ api = RetriableProxy.for_object(api, on: Sibit::Error) if opts[:attempts] > 1
92
+ sibit = Sibit.new(log: log, api: api)
90
93
  case opts.arguments[0]
91
94
  when 'price'
92
95
  puts sibit.price
@@ -19,10 +19,9 @@ require_relative 'version'
19
19
  # License:: MIT
20
20
  class Sibit::Bitcoinchain
21
21
  # Constructor.
22
- def initialize(log: Loog::NULL, http: Sibit::Http.new, dry: false)
22
+ def initialize(log: Loog::NULL, http: Sibit::Http.new)
23
23
  @http = http
24
24
  @log = log
25
- @dry = dry
26
25
  end
27
26
 
28
27
  # Current price of BTC in USD (float returned).
@@ -22,10 +22,9 @@ require_relative 'version'
22
22
  # License:: MIT
23
23
  class Sibit::Blockchain
24
24
  # Constructor.
25
- def initialize(log: Loog::NULL, http: Sibit::Http.new, dry: false)
25
+ def initialize(log: Loog::NULL, http: Sibit::Http.new)
26
26
  @http = http
27
27
  @log = log
28
- @dry = dry
29
28
  end
30
29
 
31
30
  # Current price of BTC in USD (float returned).
@@ -108,7 +107,6 @@ class Sibit::Blockchain
108
107
 
109
108
  # Push this transaction (in hex format) to the network.
110
109
  def push(hex)
111
- return if @dry
112
110
  Sibit::Json.new(http: @http, log: @log).post(
113
111
  Iri.new('https://blockchain.info/pushtx'),
114
112
  hex
@@ -20,11 +20,10 @@ require_relative 'version'
20
20
  # License:: MIT
21
21
  class Sibit::Blockchair
22
22
  # Constructor.
23
- def initialize(key: nil, log: Loog::NULL, http: Sibit::Http.new, dry: false)
23
+ def initialize(key: nil, log: Loog::NULL, http: Sibit::Http.new)
24
24
  @key = key
25
25
  @http = http
26
26
  @log = log
27
- @dry = dry
28
27
  end
29
28
 
30
29
  # Current price of BTC in USD (float returned).
data/lib/sibit/btc.rb CHANGED
@@ -21,10 +21,9 @@ require_relative 'version'
21
21
  # License:: MIT
22
22
  class Sibit::Btc
23
23
  # Constructor.
24
- def initialize(log: Loog::NULL, http: Sibit::Http.new, dry: false)
24
+ def initialize(log: Loog::NULL, http: Sibit::Http.new)
25
25
  @http = http
26
26
  @log = log
27
- @dry = dry
28
27
  end
29
28
 
30
29
  # Current price of BTC in USD (float returned).
data/lib/sibit/cex.rb CHANGED
@@ -18,10 +18,9 @@ require_relative 'json'
18
18
  # License:: MIT
19
19
  class Sibit::Cex
20
20
  # Constructor.
21
- def initialize(log: Loog::NULL, http: Sibit::Http.new, dry: false)
21
+ def initialize(log: Loog::NULL, http: Sibit::Http.new)
22
22
  @http = http
23
23
  @log = log
24
- @dry = dry
25
24
  end
26
25
 
27
26
  # Current price of BTC in USD (float returned).
@@ -19,11 +19,10 @@ require_relative 'version'
19
19
  # License:: MIT
20
20
  class Sibit::Cryptoapis
21
21
  # Constructor.
22
- def initialize(key, log: Loog::NULL, http: Sibit::Http.new, dry: false)
22
+ def initialize(key, log: Loog::NULL, http: Sibit::Http.new)
23
23
  @key = key
24
24
  @http = http
25
25
  @log = log
26
- @dry = dry
27
26
  end
28
27
 
29
28
  # Current price of BTC in USD (float returned).
data/lib/sibit/dry.rb ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'decoor'
7
+ require 'loog'
8
+
9
+ # Dry mode decorator for API classes.
10
+ #
11
+ # Wraps any API object and prevents push() from sending transactions.
12
+ # All other methods are delegated to the wrapped API unchanged.
13
+ #
14
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
+ # Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
16
+ # License:: MIT
17
+ class Sibit::Dry
18
+ def initialize(api, log: Loog::NULL)
19
+ @api = api
20
+ @log = log
21
+ end
22
+
23
+ decoor(:api)
24
+
25
+ def push(_hex)
26
+ @log.info("Transaction not pushed, dry mode is ON (#{@origin.class.name})")
27
+ nil
28
+ end
29
+ end
data/lib/sibit/http.rb CHANGED
@@ -20,22 +20,4 @@ class Sibit
20
20
  http
21
21
  end
22
22
  end
23
-
24
- # This HTTP client with proxy.
25
- #
26
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
- # Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
28
- # License:: MIT
29
- class HttpProxy
30
- def initialize(addr)
31
- @host, @port = addr.split(':')
32
- end
33
-
34
- def client(uri)
35
- http = Net::HTTP.new(uri.host, uri.port, @host, @port.to_i)
36
- http.use_ssl = true
37
- http.read_timeout = 240
38
- http
39
- end
40
- end
41
23
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'net/http'
7
+
8
+ # Sibit main class.
9
+ class Sibit
10
+ # HTTP client with proxy.
11
+ #
12
+ # Accepts proxy address in format: host:port or user:password@host:port
13
+ #
14
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
+ # Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
16
+ # License:: MIT
17
+ class HttpProxy
18
+ def initialize(addr)
19
+ @user, @password, @host, @port = parse(addr)
20
+ end
21
+
22
+ def client(uri)
23
+ http = Net::HTTP.new(uri.host, uri.port, @host, @port.to_i, @user, @password)
24
+ http.use_ssl = true
25
+ http.read_timeout = 240
26
+ http
27
+ end
28
+
29
+ private
30
+
31
+ def parse(addr)
32
+ if addr.include?('@')
33
+ auth, hostport = addr.split('@')
34
+ user, password = auth.split(':')
35
+ host, port = hostport.split(':')
36
+ [user, password, host, port]
37
+ else
38
+ host, port = addr.split(':')
39
+ [nil, nil, host, port]
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/sibit/version.rb CHANGED
@@ -9,5 +9,5 @@
9
9
  # License:: MIT
10
10
  class Sibit
11
11
  # Current version of the library.
12
- VERSION = '0.29.1'
12
+ VERSION = '0.30.1'
13
13
  end
data/lib/sibit.rb CHANGED
@@ -4,11 +4,11 @@
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  require 'loog'
7
- require_relative 'sibit/bitcoin/base58'
8
- require_relative 'sibit/bitcoin/key'
9
- require_relative 'sibit/bitcoin/script'
10
- require_relative 'sibit/bitcoin/tx'
11
- require_relative 'sibit/bitcoin/txbuilder'
7
+ require_relative 'sibit/base58'
8
+ require_relative 'sibit/key'
9
+ require_relative 'sibit/script'
10
+ require_relative 'sibit/tx'
11
+ require_relative 'sibit/txbuilder'
12
12
  require_relative 'sibit/blockchain'
13
13
  require_relative 'sibit/version'
14
14
 
@@ -100,7 +100,7 @@ class Sibit
100
100
  # +change+: the address where the change has to be sent to
101
101
  def pay(amount, fee, sources, target, change, skip_utxo: [])
102
102
  p = price('USD')
103
- sources = sources.map { |k| [Key.new(k).addr, k] }.to_h
103
+ sources = sources.to_h { |k| [Key.new(k).addr, k] }
104
104
  satoshi = satoshi(amount)
105
105
  builder = TxBuilder.new
106
106
  unspent = 0
data/sibit.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  if s.respond_to? :required_rubygems_version=
13
13
  s.required_rubygems_version = Gem::Requirement.new('>= 0')
14
14
  end
15
- s.required_ruby_version = '>= 2.5'
15
+ s.required_ruby_version = '>= 3.0'
16
16
  s.name = 'sibit'
17
17
  s.version = Sibit::VERSION
18
18
  s.license = 'MIT'
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.rdoc_options = ['--charset=UTF-8']
31
31
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
32
32
  s.add_dependency 'backtrace', '~> 0.3'
33
+ s.add_dependency 'decoor', '~> 0.1'
33
34
  s.add_dependency 'iri', '~> 0.5'
34
35
  s.add_dependency 'json', '~> 2'
35
36
  s.add_dependency 'loog', '~> 0.6'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.1
4
+ version: 0.30.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0.3'
26
+ - !ruby/object:Gem::Dependency
27
+ name: decoor
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.1'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: iri
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -133,23 +147,25 @@ files:
133
147
  - features/step_definitions/steps.rb
134
148
  - features/support/env.rb
135
149
  - lib/sibit.rb
150
+ - lib/sibit/base58.rb
136
151
  - lib/sibit/bestof.rb
137
- - lib/sibit/bitcoin/base58.rb
138
- - lib/sibit/bitcoin/key.rb
139
- - lib/sibit/bitcoin/script.rb
140
- - lib/sibit/bitcoin/tx.rb
141
- - lib/sibit/bitcoin/txbuilder.rb
142
152
  - lib/sibit/bitcoinchain.rb
143
153
  - lib/sibit/blockchain.rb
144
154
  - lib/sibit/blockchair.rb
145
155
  - lib/sibit/btc.rb
146
156
  - lib/sibit/cex.rb
147
157
  - lib/sibit/cryptoapis.rb
158
+ - lib/sibit/dry.rb
148
159
  - lib/sibit/error.rb
149
160
  - lib/sibit/fake.rb
150
161
  - lib/sibit/firstof.rb
151
162
  - lib/sibit/http.rb
163
+ - lib/sibit/httpproxy.rb
152
164
  - lib/sibit/json.rb
165
+ - lib/sibit/key.rb
166
+ - lib/sibit/script.rb
167
+ - lib/sibit/tx.rb
168
+ - lib/sibit/txbuilder.rb
153
169
  - lib/sibit/version.rb
154
170
  - logo.svg
155
171
  - sibit.gemspec
@@ -165,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
181
  requirements:
166
182
  - - ">="
167
183
  - !ruby/object:Gem::Version
168
- version: '2.5'
184
+ version: '3.0'
169
185
  required_rubygems_version: !ruby/object:Gem::Requirement
170
186
  requirements:
171
187
  - - ">="
File without changes
File without changes
File without changes
File without changes
File without changes