sibit 0.31.0 → 0.32.0

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: d7d8d002bcff6bcb41fc9dcd1a4a4ebd2d622460a23777e36da39406e4de8684
4
- data.tar.gz: 91d217414aec0258cd458dbbae530738e2efc211f3d259888413a0532554d203
3
+ metadata.gz: ccc8435725361e992237efffbe4f53e4f6698e8217cbac39ce0f08f8b407cb68
4
+ data.tar.gz: 8a787c829a4539a6b69be2764ef90b09e61b13797375b382e6a4df69826165cf
5
5
  SHA512:
6
- metadata.gz: '099247f1d77cdb32d500e5798f7480b03ce48279d198c059e410f35ca9bb1fc345ee5b6f8342aa8b4ac9982079c9ec0848a26ae8201bb35af04f9bed67f9d2bc'
7
- data.tar.gz: 16c9a7c880dc2bb401383bb5e0593fdfcafcdc7ebd77cfe19a7bc0509be14f8e7946b0a663bcd3e71826e60d93296533104a1d094bd25fb0955a1bdc181f6442
6
+ metadata.gz: 253013c5f6b978ea0db8ea3c2800aad241e2d277fbd743f21130dff952610b37fc27366ec8e67728dba64a97efbe1750c1dd7455faf991e856e8af5d06f52e88
7
+ data.tar.gz: ce524cedb5ae7420113a0d9f6526792f9c47dee863724e64adf7909b94aca0ede25cee286f203063ff65166e00c58512b6310f6ced1ee52a28bd7516ab563e9c
data/REUSE.toml CHANGED
@@ -6,6 +6,7 @@ version = 1
6
6
  path = [
7
7
  ".DS_Store",
8
8
  ".gitattributes",
9
+ ".gitleaksignore",
9
10
  ".gitignore",
10
11
  ".pdd",
11
12
  "**.json",
data/bin/sibit CHANGED
@@ -24,6 +24,9 @@ require_relative '../lib/sibit/fake'
24
24
  require_relative '../lib/sibit/firstof'
25
25
  require_relative '../lib/sibit/version'
26
26
 
27
+ VERBOSE = ARGV.include?('--verbose') || ENV.fetch('SIBIT_VERBOSE', nil)
28
+ LOG = VERBOSE ? Loog::VERBOSE : Loog::REGULAR
29
+
27
30
  # Command-line interface for Sibit.
28
31
  # Provides commands to interact with the Bitcoin network.
29
32
  class Bin < Thor
@@ -83,15 +86,21 @@ class Bin < Thor
83
86
  log.info(client.balance(address))
84
87
  end
85
88
 
86
- desc 'pay AMOUNT FEE SOURCES TARGET CHANGE', 'Send a new Bitcoin transaction'
89
+ desc 'pay AMOUNT FEE SOURCES TARGET CHANGE',
90
+ 'Send a new Bitcoin transaction (AMOUNT can be "MAX" to use full balance)'
87
91
  option :skip_utxo, type: :array, default: [],
88
92
  desc: 'List of UTXO that must be skipped while paying'
89
93
  option :yes, type: :boolean, default: false,
90
94
  desc: 'Skip confirmation prompt and send the payment immediately'
91
95
  def pay(amount, fee, sources, target, change)
92
- amount = amount.to_i if /^[0-9]+$/.match?(amount)
96
+ keys = sources.split(',')
97
+ if amount.upcase == 'MAX'
98
+ addrs = keys.map { |k| Sibit::Key.new(k).bech32 }
99
+ amount = addrs.sum { |a| client.balance(a) }
100
+ end
101
+ amount = amount.to_i if amount.is_a?(String) && /^[0-9]+$/.match?(amount)
93
102
  fee = fee.to_i if /^[0-9]+$/.match?(fee)
94
- args = [amount, fee, sources.split(','), target, change]
103
+ args = [amount, fee, keys, target, change]
95
104
  kwargs = { skip_utxo: options[:skip_utxo] }
96
105
  unless options[:yes] || options[:dry]
97
106
  client(dry: true).pay(*args, **kwargs)
@@ -110,11 +119,13 @@ class Bin < Thor
110
119
  private
111
120
 
112
121
  def log
113
- @log ||= options[:verbose] ? Loog::VERBOSE : Loog::REGULAR
122
+ LOG
114
123
  end
115
124
 
116
125
  def client(dry: false)
117
- http = options[:proxy] ? Sibit::HttpProxy.new(options[:proxy]) : Sibit::Http.new
126
+ proxy = options[:proxy] || ENV.fetch('SIBIT_PROXY', nil)
127
+ http = proxy ? Sibit::HttpProxy.new(proxy) : Sibit::Http.new
128
+ log.debug("Using proxy at #{http.host}") if proxy
118
129
  apis = options[:api].flat_map { |a| a.split(',') }.map(&:downcase).map do |a|
119
130
  case a
120
131
  when 'blockchain'
@@ -140,14 +151,15 @@ class Bin < Thor
140
151
  end
141
152
  end
142
153
 
143
- begin
144
- Bin.start(ARGV)
145
- rescue StandardError => e
146
- log = ARGV.include?('--verbose') ? Loog::VERBOSE : Loog::REGULAR
147
- if ARGV.include?('--verbose')
148
- log.error(Backtrace.new(e))
149
- else
150
- log.error(e.message)
154
+ if __FILE__ == $PROGRAM_NAME
155
+ begin
156
+ Bin.start(ARGV)
157
+ rescue StandardError => e
158
+ if VERBOSE
159
+ LOG.error(Backtrace.new(e))
160
+ else
161
+ LOG.error(e.message)
162
+ end
163
+ exit(255)
151
164
  end
152
- exit(255)
153
165
  end
@@ -19,6 +19,8 @@ class Sibit
19
19
  @user, @password, @host, @port = parse(addr)
20
20
  end
21
21
 
22
+ attr_reader :host
23
+
22
24
  def client(uri)
23
25
  http = Net::HTTP.new(uri.host, uri.port, @host, @port.to_i, @user, @password)
24
26
  http.use_ssl = true
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.31.0' unless defined?(VERSION)
12
+ VERSION = '0.32.0' unless defined?(VERSION)
13
13
  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.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko