sibit 0.34.1 → 0.34.3

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: 469905d53f542975d0fe59c8b429289423762f4b36aca8b703928d54f5ba394f
4
- data.tar.gz: c68a4237d70f25a11ea2e98c36d76c7b0917a6355353e6d23c22336eedd94f31
3
+ metadata.gz: 9fab8abde581e74b8a0aa55666754632639f070361cefdf3a2fb5766b6c8cf59
4
+ data.tar.gz: 87f523aa5a0dab63bf34e85b5de55afa9983333cf7202a4c6b062174b3e6289d
5
5
  SHA512:
6
- metadata.gz: f5aa717192c0417c572226c3a0f79924f61e5d70b0bc84efe53d0cc760c16515f3cd6ef63b00de57e4228dbcd82fdb60a269f35df858b0c1ff8bec81006db6bc
7
- data.tar.gz: fe9f402e207051f02e31b54d0a4e41cca76efd2a0260fbc6dfb3fb69f1aa543af2a9af6045590bd653c6c26472c97fdb6d5ba3a8b5a98f4ca282e351d88f53ee
6
+ metadata.gz: 130efd165f0f20537dca059b0ad4c88022294a020b66be1c0d598c5c0789fec9b56088c52ae680cdd4864adc33b953d81696b7929514125d2d9ed31fbd755d10
7
+ data.tar.gz: e5209eda4d7a20d157c0512a229d57e907879cb02b581c8f1afd1d81c335fdbbce3c9a723b77d8d3881d5c6d9881b0a986aeb48ba7e1d4d6c98d06970ffa6446
data/Gemfile.lock CHANGED
@@ -83,7 +83,7 @@ GEM
83
83
  rdoc (>= 4.0.0)
84
84
  reline (>= 0.4.2)
85
85
  iri (0.11.8)
86
- json (2.21.1)
86
+ json (2.21.2)
87
87
  language_server-protocol (3.17.0.6)
88
88
  lint_roller (1.1.0)
89
89
  logger (1.7.0)
@@ -144,8 +144,8 @@ GEM
144
144
  diff-lcs (>= 1.2.0, < 2.0)
145
145
  rspec-support (~> 3.13.0)
146
146
  rspec-support (3.13.7)
147
- rubocop (1.88.2)
148
- json (~> 2.3)
147
+ rubocop (1.90.0)
148
+ json (>= 2.3)
149
149
  language_server-protocol (~> 3.17.0.2)
150
150
  lint_roller (~> 1.1.0)
151
151
  parallel (>= 1.10)
@@ -158,16 +158,16 @@ GEM
158
158
  rubocop-ast (1.50.0)
159
159
  parser (>= 3.3.7.2)
160
160
  prism (~> 1.7)
161
- rubocop-elegant (0.7.1)
161
+ rubocop-elegant (0.8.0)
162
162
  lint_roller (~> 1.1)
163
163
  rubocop (~> 1.75)
164
164
  rubocop-minitest (0.40.0)
165
165
  lint_roller (~> 1.1)
166
166
  rubocop (>= 1.75.0, < 2.0)
167
167
  rubocop-ast (>= 1.38.0, < 2.0)
168
- rubocop-performance (1.26.1)
168
+ rubocop-performance (1.27.0)
169
169
  lint_roller (~> 1.1)
170
- rubocop (>= 1.75.0, < 2.0)
170
+ rubocop (>= 1.89.0, < 2.0)
171
171
  rubocop-ast (>= 1.47.1, < 2.0)
172
172
  rubocop-rake (0.7.1)
173
173
  lint_roller (~> 1.1)
@@ -191,7 +191,7 @@ GEM
191
191
  unicode-display_width (3.2.0)
192
192
  unicode-emoji (~> 4.1)
193
193
  unicode-emoji (4.2.0)
194
- webmock (3.26.2)
194
+ webmock (3.26.4)
195
195
  addressable (>= 2.8.0)
196
196
  crack (>= 0.3.2)
197
197
  hashdiff (>= 0.4.0, < 2.0.0)
data/lib/sibit/bin.rb CHANGED
@@ -145,10 +145,21 @@ class Sibit
145
145
  end
146
146
  end
147
147
 
148
+ def proxy
149
+ addr = options[:proxy] || ENV.fetch('SIBIT_PROXY', nil)
150
+ return if addr.nil?
151
+ if options[:proxy]
152
+ log.debug("Proxy found in the --proxy command line option (#{addr.length} symbols)")
153
+ else
154
+ log.debug("Proxy found in the SIBIT_PROXY env variable (#{addr.length} symbols)")
155
+ end
156
+ addr
157
+ end
158
+
148
159
  def client(dry: false)
149
- proxy = options[:proxy] || ENV.fetch('SIBIT_PROXY', nil)
150
- http = proxy ? Sibit::HttpProxy.new(proxy) : Sibit::Http.new
151
- log.debug("Using proxy at #{http.host}") if proxy
160
+ addr = proxy
161
+ http = addr ? Sibit::HttpProxy.new(addr) : Sibit::Http.new
162
+ log.debug("Using proxy at #{http}") if addr
152
163
  api = Sibit::FirstOf.new(
153
164
  options[:api].flat_map { |a| a.split(',') }.map(&:downcase).map do |a|
154
165
  case a
@@ -19,7 +19,13 @@ class Sibit
19
19
  @user, @password, @host, @port = parse(addr)
20
20
  end
21
21
 
22
- attr_reader :host
22
+ def to_s
23
+ [
24
+ "#{@host}:#{@port}",
25
+ @user ? " as #{@user}" : '',
26
+ @password ? ", password #{'*' * @password.length}" : ''
27
+ ].join
28
+ end
23
29
 
24
30
  def client(uri)
25
31
  http = Net::HTTP.new(uri.host, uri.port, @host, Integer(@port, 10), @user, @password)
data/lib/sibit/tx.rb CHANGED
@@ -24,9 +24,10 @@ class Sibit
24
24
 
25
25
  attr_reader :inputs, :outputs
26
26
 
27
- def initialize
27
+ def initialize(network: :mainnet)
28
28
  @inputs = []
29
29
  @outputs = []
30
+ @network = network
30
31
  end
31
32
 
32
33
  def add_input(hash:, index:, script:, key:, value: 0)
@@ -34,7 +35,7 @@ class Sibit
34
35
  end
35
36
 
36
37
  def add_output(value, address)
37
- @outputs << Output.new(value, address)
38
+ @outputs << Output.new(value, address, @network)
38
39
  end
39
40
 
40
41
  def hash
@@ -103,20 +104,33 @@ class Sibit
103
104
  class Output
104
105
  attr_reader :value
105
106
 
106
- def initialize(value, address)
107
+ def initialize(value, address, network = :mainnet)
107
108
  @value = value
108
109
  @address = address
110
+ @network = network
109
111
  end
110
112
 
111
113
  def script
112
114
  return segwit_script if segwit?
113
- return p2pkh_script if %w[00 6f].include?(version)
114
- return p2sh_script if %w[05 c4].include?(version)
115
- raise(Sibit::Error, "Address '#{@address}' has an unsupported version byte 0x#{version}")
115
+ return p2pkh_script if version == (@network == :mainnet ? '00' : '6f')
116
+ return p2sh_script if version == (@network == :mainnet ? '05' : 'c4')
117
+ raise(
118
+ Sibit::Error,
119
+ "Address '#{@address}' has version byte 0x#{version}, " \
120
+ "which does not belong to the #{@network} network"
121
+ )
116
122
  end
117
123
 
118
124
  def segwit?
119
- @address.downcase.start_with?('bc1', 'tb1', 'bcrt1')
125
+ down = @address.downcase
126
+ return true if down.start_with?(*(@network == :mainnet ? ['bc1'] : %w[tb1 bcrt1]))
127
+ if down.start_with?(*(@network == :mainnet ? %w[tb1 bcrt1] : ['bc1']))
128
+ raise(
129
+ Sibit::Error,
130
+ "Address '#{@address}' is a Bech32 address of a different network than #{@network}"
131
+ )
132
+ end
133
+ false
120
134
  end
121
135
 
122
136
  def script_hex
@@ -20,9 +20,10 @@ class Sibit
20
20
  class TxBuilder
21
21
  DUST = 546
22
22
 
23
- def initialize
23
+ def initialize(network = :mainnet)
24
24
  @inputs = []
25
25
  @outputs = []
26
+ @network = network
26
27
  end
27
28
 
28
29
  def input
@@ -36,7 +37,7 @@ class Sibit
36
37
  end
37
38
 
38
39
  def tx(input_value:, leave_fee:, extra_fee:, change_address:)
39
- txn = Tx.new
40
+ txn = Tx.new(network: @network)
40
41
  @inputs.each do |inp|
41
42
  txn.add_input(
42
43
  hash: inp.prev_out_hash,
data/lib/sibit/version.rb CHANGED
@@ -8,5 +8,5 @@
8
8
  # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
9
9
  # License:: MIT
10
10
  class Sibit
11
- VERSION = '0.34.1' unless defined?(VERSION)
11
+ VERSION = '0.34.3' unless defined?(VERSION)
12
12
  end
data/lib/sibit.rb CHANGED
@@ -152,7 +152,7 @@ class Sibit
152
152
  [pub, k.priv]
153
153
  end
154
154
  satoshi = satoshi(amount)
155
- builder = TxBuilder.new
155
+ builder = TxBuilder.new(network)
156
156
  unspent = 0
157
157
  size = 100
158
158
  utxos = @api.utxos(sources.keys).sort_by { |u| [u[:hash], u[:index]] }
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.34.1
4
+ version: 0.34.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko