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 +4 -4
- data/REUSE.toml +1 -0
- data/bin/sibit +26 -14
- data/lib/sibit/httpproxy.rb +2 -0
- data/lib/sibit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ccc8435725361e992237efffbe4f53e4f6698e8217cbac39ce0f08f8b407cb68
|
|
4
|
+
data.tar.gz: 8a787c829a4539a6b69be2764ef90b09e61b13797375b382e6a4df69826165cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 253013c5f6b978ea0db8ea3c2800aad241e2d277fbd743f21130dff952610b37fc27366ec8e67728dba64a97efbe1750c1dd7455faf991e856e8af5d06f52e88
|
|
7
|
+
data.tar.gz: ce524cedb5ae7420113a0d9f6526792f9c47dee863724e64adf7909b94aca0ede25cee286f203063ff65166e00c58512b6310f6ced1ee52a28bd7516ab563e9c
|
data/REUSE.toml
CHANGED
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',
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
122
|
+
LOG
|
|
114
123
|
end
|
|
115
124
|
|
|
116
125
|
def client(dry: false)
|
|
117
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
data/lib/sibit/httpproxy.rb
CHANGED
data/lib/sibit/version.rb
CHANGED