sibit 0.7.3 → 0.7.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sibit/version.rb +1 -1
  3. data/lib/sibit.rb +20 -23
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97fc6e459620d8c1b470291e6680c8a163c34b54ca78c8f47a8e95812cef273d
4
- data.tar.gz: 5af36c2a284b1bad0746da7c05c8afd6685a7726dd79129bce050a4f7e8ed524
3
+ metadata.gz: ebf35087ce8b3d8593fb71fbf92f73663ee1271e5ec12d9b0ce1a96e24acf391
4
+ data.tar.gz: 468f3061a5f8f74d31e5356f6aac583d699524a1267f5a529e58ee69e1e13bbc
5
5
  SHA512:
6
- metadata.gz: 9523d9228dde8234aebfaf1af0e0f7d3046c58694581aaff0795450c7508b26f98fa698b4c1669a4f11445e8a99e0f0a5c54da0b4034c01e2bbb3575f1e00516
7
- data.tar.gz: e9f384160b3ab50f61f697a47860620bd39caeade8636ee8611630577f0d6f1c0c88cd01d1a0560fd4370ea2d6fd94dd46c50c9da28befa2500c2e858c2b858a
6
+ metadata.gz: ea42fd169efa160dd5cbbe4da51f15f23dda6d37a684415156a5dd1b5a84d7dc1010ba586385a69fcfdae2f37eb25055e0001cbfa491324815e807a923f0e681
7
+ data.tar.gz: d187e1c3f6284666bf1f84710cf85d00090f15749a8ef0df5c4d6f7733186e0b402d6b28d34deb4a240689322b2bccb11125f24c23b8d70ebfa48cd05234029e
data/lib/sibit/version.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.7.3'
29
+ VERSION = '0.7.4'
30
30
  end
data/lib/sibit.rb CHANGED
@@ -72,7 +72,7 @@ class Sibit
72
72
  #
73
73
  # You may provide the log you want to see the messages in. If you don't
74
74
  # provide anything, the console will be used. The object you provide
75
- # has to respond to the method +debug+ or +puts+ in order to receive logging
75
+ # has to respond to the method +info+ or +puts+ in order to receive logging
76
76
  # messages.
77
77
  def initialize(log: STDOUT)
78
78
  @log = log
@@ -98,8 +98,8 @@ class Sibit
98
98
  # Gets the balance of the address, in satoshi.
99
99
  def balance(address)
100
100
  json = get_json("/rawaddr/#{address}")
101
- debug("Total transactions: #{json['n_tx']}")
102
- debug("Received/sent: #{json['total_received']}/#{json['total_sent']}")
101
+ info("Total transactions: #{json['n_tx']}")
102
+ info("Received/sent: #{json['total_received']}/#{json['total_sent']}")
103
103
  json['final_balance']
104
104
  end
105
105
 
@@ -128,7 +128,7 @@ class Sibit
128
128
  utxos = get_json(
129
129
  "/unspent?active=#{sources.keys.join('|')}&limit=1000"
130
130
  )['unspent_outputs']
131
- debug("#{utxos.count} UTXOs found:")
131
+ info("#{utxos.count} UTXOs found:")
132
132
  utxos.each do |utxo|
133
133
  unspent += utxo['value']
134
134
  builder.input do |i|
@@ -139,16 +139,20 @@ class Sibit
139
139
  i.signature_key(key(sources[address]))
140
140
  end
141
141
  size += 180
142
- debug(" #{utxo['value']}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
142
+ info(" #{utxo['value']}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
143
143
  break if unspent > satoshi
144
144
  end
145
145
  raise Error, "Not enough funds to send #{amount}, only #{unspent} left" if unspent < satoshi
146
146
  builder.output(satoshi, target)
147
+ f = mfee(fee, size)
147
148
  tx = builder.tx(
148
149
  input_value: unspent,
149
- leave_fee: mfee(fee, size),
150
+ leave_fee: f,
150
151
  change_address: change
151
152
  )
153
+ info("A new Bitcoin transaction #{tx.hash} prepared; #{tx.in.count} inputs; \
154
+ #{tx.out.count} outputs; fee is #{f}; size is #{size}; unspent is #{unspent}; \
155
+ amount is #{amount}; target address is #{target}; change address is #{change}")
152
156
  post_tx(tx.to_payload.bth)
153
157
  tx.hash
154
158
  end
@@ -165,7 +169,7 @@ class Sibit
165
169
  start = Time.now
166
170
  res = Net::HTTP.get_response(URI('https://blockchain.info' + uri))
167
171
  raise Error, "Failed to retrieve #{uri}: #{res.code}" unless res.code == '200'
168
- debug("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
172
+ info("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
169
173
  JSON.parse(res.body)
170
174
  end
171
175
 
@@ -182,18 +186,11 @@ class Sibit
182
186
  def mfee(fee, size)
183
187
  return fee.to_i if fee.is_a?(Integer)
184
188
  raise Error, 'Fee should either be a String or Integer' unless fee.is_a?(String)
185
- case fee
186
- when 'S'
187
- return 10 * size
188
- when 'M'
189
- return 50 * size
190
- when 'L'
191
- return 100 * size
192
- when 'XL'
193
- return 250 * size
194
- else
195
- raise Error, "Can't understand the fee: #{fee.inspect}"
196
- end
189
+ return 10 * size if fee == 'S'
190
+ return 50 * size if fee == 'M'
191
+ return 100 * size if fee == 'L'
192
+ return 250 * size if fee == 'XL'
193
+ raise Error, "Can't understand the fee: #{fee.inspect}"
197
194
  end
198
195
 
199
196
  # Make key from private key string in Hash160.
@@ -212,12 +209,12 @@ class Sibit
212
209
  uri = URI('https://blockchain.info/pushtx')
213
210
  res = Net::HTTP.post_form(uri, tx: body)
214
211
  raise Error, "Failed to post tx to #{uri}: #{res.code}\n#{res.body}" unless res.code == '200'
215
- debug("POST #{uri}: #{res.code} in #{age(start)}")
212
+ info("POST #{uri}: #{res.code} in #{age(start)}")
216
213
  end
217
214
 
218
- def debug(msg)
219
- if @log.respond_to?(:debug)
220
- @log.debug(msg)
215
+ def info(msg)
216
+ if @log.respond_to?(:info)
217
+ @log.info(msg)
221
218
  elsif @log.respond_to?(:puts)
222
219
  @log.puts(msg)
223
220
  end
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.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko