sibit 0.32.2 → 0.32.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: 5b5729226952c9b63bbe126e8f4471de9a69b5fe5cdd1735500901a39d957c43
4
- data.tar.gz: 4c9fac6187bbb379fd4874e81abb26e23073878a73f6877d92566d89d666b231
3
+ metadata.gz: 196fa93e65ec890ca33a83d3d56358f311d57933e20432e61b5e3df32ae8515d
4
+ data.tar.gz: 0d02c5a2f773d84dbd13c614c6e52533e88a88dff5c07e4ff304650311ce5a22
5
5
  SHA512:
6
- metadata.gz: ad897361c466fef868dc4d526dbf5fc154d0d39039be448c34dceaef22e0622a08f8e2f2f6e98f9f8192a8e4f3955e92629c9b0bf6fabc71c5e748a4255a2c88
7
- data.tar.gz: 3f9138f939d908f8c65f07fb10a70e9c02c900b8cc0a6edf827187ea59b97394a1b055e3baf4a539cb798e3662ec9bf4b680550159c3272c1758e04118be0443
6
+ metadata.gz: b62032df000f92c6e58147224c5055c3db2ac1798308022899b0e5a5706b691deb9b948733514bcbbac80e70b2ea9f31e085a1da9557a37fd60076240face315
7
+ data.tar.gz: 21601d77cf209b9980caef8567321f018efe4442eec5caa96f2e791865519c7499d3f7c64111c01823e90ffeb2ed808608fc7e3387c3fda47d3056612a13449c
data/lib/sibit/bin.rb CHANGED
@@ -22,13 +22,13 @@ class Sibit
22
22
  class Bin < Thor
23
23
  class_option :proxy, type: :string, desc: 'HTTPS proxy for all requests, e.g. "localhost:3128"'
24
24
  class_option :attempts, type: :numeric, default: 1,
25
- desc: 'How many times should we try before failing'
25
+ desc: 'How many times should we try before failing'
26
26
  class_option :dry, type: :boolean, default: false,
27
- desc: "Don't send a real payment, run in a read-only mode"
27
+ desc: "Don't send a real payment, run in a read-only mode"
28
28
  class_option :verbose, type: :boolean, default: false, desc: 'Print all possible debug messages'
29
29
  class_option :quiet, type: :boolean, default: false, desc: 'Print only informative messages'
30
30
  class_option :api, type: :array, default: %w[blockchain btc bitcoinchain blockchair cex],
31
- desc: 'Ordered List of APIs to use, e.g. "blockchain,btc,bitcoinchain"'
31
+ desc: 'Ordered List of APIs to use, e.g. "blockchain,btc,bitcoinchain"'
32
32
 
33
33
  def self.exit_on_failure?
34
34
  true
@@ -77,22 +77,28 @@ class Sibit
77
77
  log.info(client.balance(address))
78
78
  end
79
79
 
80
- desc 'pay AMOUNT FEE SOURCES TARGET CHANGE',
81
- 'Send a new Bitcoin transaction (AMOUNT can be "MAX" to use full balance)'
80
+ desc \
81
+ 'pay AMOUNT FEE SOURCES TARGET CHANGE',
82
+ 'Send a new Bitcoin transaction (AMOUNT can be "MAX" to use full balance)'
82
83
  option :skip_utxo, type: :array, default: [],
83
- desc: 'List of UTXO that must be skipped while paying'
84
+ desc: 'List of UTXO that must be skipped while paying'
85
+ option :base58, type: :boolean, default: false,
86
+ desc: 'Convert private addresses to public in base58'
84
87
  option :yes, type: :boolean, default: false,
85
- desc: 'Skip confirmation prompt and send the payment immediately'
88
+ desc: 'Skip confirmation prompt and send the payment immediately'
86
89
  def pay(amount, fee, sources, target, change)
87
90
  keys = sources.split(',')
88
91
  if amount.upcase == 'MAX'
89
- addrs = keys.map { |k| Sibit::Key.new(k).bech32 }
92
+ addrs = keys.map do |k|
93
+ kk = Sibit::Key.new(k)
94
+ options[:base58] ? kk.base58 : kk.bech32
95
+ end
90
96
  amount = addrs.sum { |a| client.balance(a) }
91
97
  end
92
98
  amount = amount.to_i if amount.is_a?(String) && /^[0-9]+$/.match?(amount)
93
99
  fee = fee.to_i if /^[0-9]+$/.match?(fee)
94
100
  args = [amount, fee, keys, target, change]
95
- kwargs = { skip_utxo: options[:skip_utxo] }
101
+ kwargs = { skip_utxo: options[:skip_utxo], base58: options[:base58] }
96
102
  unless options[:yes] || options[:dry]
97
103
  client(dry: true).pay(*args, **kwargs)
98
104
  print 'Do you confirm this payment? (yes/no): '
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.32.2' unless defined?(VERSION)
12
+ VERSION = '0.32.3' unless defined?(VERSION)
13
13
  end
data/lib/sibit.rb CHANGED
@@ -103,18 +103,26 @@ class Sibit
103
103
  # +target+: the target address to send to
104
104
  # +change+: the address where the change has to be sent to
105
105
  # +network+: optional network override (:mainnet, :testnet, :regtest)
106
- def pay(amount, fee, sources, target, change, skip_utxo: [], network: nil)
106
+ def pay(amount, fee, sources, target, change, skip_utxo: [], network: nil, base58: false)
107
107
  p = price('USD')
108
108
  keys = sources.map { |k| Key.new(k, network: network) }
109
109
  network = keys.first&.network || :mainnet
110
- sources = keys.to_h { |k| [k.bech32, k.priv] }
110
+ sources = keys.to_h do |k|
111
+ pub =
112
+ if base58
113
+ k.base58
114
+ else
115
+ k.bech32
116
+ end
117
+ @log.debug("Private key #{k.priv.ellipsized(8).inspect} is public as #{pub}:")
118
+ [pub, k.priv]
119
+ end
111
120
  satoshi = satoshi(amount)
112
121
  builder = TxBuilder.new
113
122
  unspent = 0
114
123
  size = 100
115
124
  utxos = @api.utxos(sources.keys)
116
- @log.debug("#{utxos.count} UTXOs found, these will be used \
117
- (value/confirmations at tx_hash):")
125
+ @log.debug("#{utxos.count} UTXOs found, these will be used (value/confirmations at tx_hash):")
118
126
  utxos.each do |utxo|
119
127
  if skip_utxo.include?(utxo[:hash])
120
128
  @log.debug("UTXO skipped: #{utxo[:hash]}")
@@ -224,8 +232,10 @@ class Sibit
224
232
  checked += 1
225
233
  end
226
234
  count += 1
227
- @log.debug("We checked #{checked} txns and #{checked_outputs} outputs \
228
- in block #{block} (by #{json[:provider]})")
235
+ @log.debug(
236
+ "Checked #{checked} txns and #{checked_outputs} outputs " \
237
+ "in block #{block} (by #{json[:provider]})"
238
+ )
229
239
  block = json[:next]
230
240
  begin
231
241
  if block.nil?
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.32.2
4
+ version: 0.32.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko