sibit 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sibit/version.rb +1 -1
  3. data/lib/sibit.rb +25 -9
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae183604ee6f09fa79e8f857ce4a50d519d8601414ac7dbc719e951e880ca25a
4
- data.tar.gz: 1642d87a24d1262027d1310e472afbdf39578df6e2298bd472882720f2681fa5
3
+ metadata.gz: 45ecd94da9a09da7f98b1997ec5a4bc809586fd0df18ffc5e83f3868fb57cf1d
4
+ data.tar.gz: bc0cbf54e5606685cf7c6729c49b5eadbc6b5590d7942cd880e4fd82daa5c1d6
5
5
  SHA512:
6
- metadata.gz: b33923c39c53ac6bb6d5da80465d3ccee850426d5e6ada0beee6e5f094e42e9db8afce5a892a9c99853366272a1197dd9c0a38fdbcf73f48b84c512466745308
7
- data.tar.gz: 3eb142b889f41a114e166ef1d1308fa1baf17acfdf685881aabf0d6c55306ac7f571e79369ed4dc11bfe8a636bccbae68db2ff9a7d66a4629d9c37db37844dd4
6
+ metadata.gz: 2049ad467b90e2b87d7f4149aa5d79d86810fc3b0fa56b278e17a7de3c9e3613c38eb53fb82fe3f5d8a68184921fadc04c9d3e3433c912034afe411e3509cd22
7
+ data.tar.gz: 3e15a316137cb4d01c8b9a1dd3339865920fe7006fdd52e31bf79ea284160eaeda73283414f75eeaad6805d27933b3b1538cdf71eda4566e7233da92ccf7ec6a
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.5'
29
+ VERSION = '0.7.6'
30
30
  end
data/lib/sibit.rb CHANGED
@@ -128,7 +128,8 @@ class Sibit
128
128
  utxos = get_json(
129
129
  "/unspent?active=#{sources.keys.join('|')}&limit=1000"
130
130
  )['unspent_outputs']
131
- info("#{utxos.count} UTXOs found (value/confirmations at tx_hash):")
131
+ info("#{utxos.count} UTXOs found, these will be used \
132
+ (value/confirmations at tx_hash):")
132
133
  utxos.each do |utxo|
133
134
  unspent += utxo['value']
134
135
  builder.input do |i|
@@ -139,22 +140,33 @@ class Sibit
139
140
  i.signature_key(key(sources[address]))
140
141
  end
141
142
  size += 180
142
- info(" #{utxo['value']}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
143
+ info(" #{num(utxo['value'])}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
143
144
  break if unspent > satoshi
144
145
  end
145
- raise Error, "Not enough funds to send #{amount}, only #{unspent} left" if unspent < satoshi
146
+ if unspent < satoshi
147
+ raise Error, "Not enough funds to send #{num(amount)}, only #{num(unspent)} left"
148
+ end
146
149
  builder.output(satoshi, target)
147
150
  f = mfee(fee, size)
148
151
  tx = builder.tx(
149
152
  input_value: unspent,
150
- leave_fee: f,
153
+ leave_fee: true,
154
+ extra_fee: f - Bitcoin.network[:min_tx_fee],
151
155
  change_address: change
152
156
  )
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 #{satoshi}; target address is #{target}; change address is #{change}:
156
- #{tx.inputs.map { |i| " in: #{i.prev_out.bth}:#{i.prev_out_index}" }.join("\n ")}
157
- #{tx.outputs.map { |o| "out: #{o.script.bth}:#{o.value}" }.join("\n ")}")
157
+ info("A new Bitcoin transaction #{tx.hash} prepared:
158
+ #{tx.in.count} input#{tx.in.count > 1 ? 's' : ''}:
159
+ #{tx.inputs.map { |i| " in: #{i.prev_out.bth}:#{i.prev_out_index}" }.join("\n ")}
160
+ #{tx.out.count} output#{tx.out.count > 1 ? 's' : ''}:
161
+ #{tx.outputs.map { |o| "out: #{o.script.bth} / #{num(o.value)}" }.join("\n ")}
162
+ Fee required: #{num(f)} satoshi
163
+ Min tx fee: #{num(Bitcoin.network[:min_tx_fee])} satoshi
164
+ Fee left: #{num(unspent - tx.outputs.map(&:value).inject(&:+))} satoshi
165
+ Tx size: #{num(size)} bytes
166
+ Unspent: #{num(unspent)} satoshi
167
+ Amount: #{num(satoshi)} satoshi
168
+ Target address: #{target}
169
+ Change address is #{change}")
158
170
  post_tx(tx.to_payload.bth)
159
171
  tx.hash
160
172
  end
@@ -177,6 +189,10 @@ amount is #{satoshi}; target address is #{target}; change address is #{change}:
177
189
 
178
190
  private
179
191
 
192
+ def num(int)
193
+ int.to_s.gsub(/\d(?=(...)+$)/, '\0,')
194
+ end
195
+
180
196
  # Convert text to amount.
181
197
  def satoshi(amount)
182
198
  return amount if amount.is_a?(Integer)
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.7.5
4
+ version: 0.7.6
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-04-13 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace