sibit 0.31.0 → 0.32.1
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 +44 -34
- 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: c756b3d04936258f2bfa46b7a385fbb3f5f9ca696728dc2895504b1f5691e65c
|
|
4
|
+
data.tar.gz: 3d88e0ab75c369c989dfaf360a4b332ac0d5e7479f8e9657734d710e58b712ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4c385350b69515c9a92a32901afd99685dca40cfc38f85be613e7527421b29481a838eceb6cc21ec1bdce70deee2b8d295806118c8039f7bb78a3fd80547ac70
|
|
7
|
+
data.tar.gz: acba7a669a53cbb92918751723e9d09a690b1f4e927f275d97633d9e538317bd4c00a355326ee0aa0fbd11a873a41fdf721570f32d73d56ef40fdc489d132b10
|
data/REUSE.toml
CHANGED
data/bin/sibit
CHANGED
|
@@ -24,6 +24,10 @@ 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?('--quiet') &&
|
|
28
|
+
(ARGV.include?('--verbose') || ENV.fetch('SIBIT_VERBOSE', nil))
|
|
29
|
+
LOG = VERBOSE ? Loog::VERBOSE : Loog::REGULAR
|
|
30
|
+
|
|
27
31
|
# Command-line interface for Sibit.
|
|
28
32
|
# Provides commands to interact with the Bitcoin network.
|
|
29
33
|
class Bin < Thor
|
|
@@ -33,6 +37,7 @@ class Bin < Thor
|
|
|
33
37
|
class_option :dry, type: :boolean, default: false,
|
|
34
38
|
desc: "Don't send a real payment, run in a read-only mode"
|
|
35
39
|
class_option :verbose, type: :boolean, default: false, desc: 'Print all possible debug messages'
|
|
40
|
+
class_option :quiet, type: :boolean, default: false, desc: 'Print only informative messages'
|
|
36
41
|
class_option :api, type: :array, default: %w[blockchain btc bitcoinchain blockchair cex],
|
|
37
42
|
desc: 'Ordered List of APIs to use, e.g. "blockchain,btc,bitcoinchain"'
|
|
38
43
|
|
|
@@ -47,7 +52,7 @@ class Bin < Thor
|
|
|
47
52
|
|
|
48
53
|
desc 'price', 'Get current price of BTC in USD'
|
|
49
54
|
def price
|
|
50
|
-
|
|
55
|
+
LOG.info(client.price)
|
|
51
56
|
end
|
|
52
57
|
|
|
53
58
|
desc 'fees', 'Get currently recommended transaction fees'
|
|
@@ -59,39 +64,45 @@ class Bin < Thor
|
|
|
59
64
|
usd = sat * sibit.price / 100_000_000
|
|
60
65
|
"#{m}: #{sat}sat / $#{format('%<usd>.02f', usd: usd)}"
|
|
61
66
|
end.join("\n")
|
|
62
|
-
|
|
67
|
+
LOG.info(text)
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
desc 'latest', 'Get hash of the latest block'
|
|
66
71
|
def latest
|
|
67
|
-
|
|
72
|
+
LOG.info(client.latest)
|
|
68
73
|
end
|
|
69
74
|
|
|
70
75
|
desc 'generate', 'Generate a new private key'
|
|
71
76
|
def generate
|
|
72
|
-
|
|
77
|
+
LOG.info(client.generate)
|
|
73
78
|
end
|
|
74
79
|
|
|
75
80
|
desc 'create KEY', 'Create a public Bitcoin address from the private key'
|
|
76
81
|
def create(key)
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
LOG.debug("Private key provided: #{key.ellipsized(8).inspect}")
|
|
83
|
+
LOG.info(client.create(key))
|
|
79
84
|
end
|
|
80
85
|
|
|
81
86
|
desc 'balance ADDRESS', 'Check the balance of the Bitcoin address'
|
|
82
87
|
def balance(address)
|
|
83
|
-
|
|
88
|
+
LOG.info(client.balance(address))
|
|
84
89
|
end
|
|
85
90
|
|
|
86
|
-
desc 'pay AMOUNT FEE SOURCES TARGET CHANGE',
|
|
91
|
+
desc 'pay AMOUNT FEE SOURCES TARGET CHANGE',
|
|
92
|
+
'Send a new Bitcoin transaction (AMOUNT can be "MAX" to use full balance)'
|
|
87
93
|
option :skip_utxo, type: :array, default: [],
|
|
88
94
|
desc: 'List of UTXO that must be skipped while paying'
|
|
89
95
|
option :yes, type: :boolean, default: false,
|
|
90
96
|
desc: 'Skip confirmation prompt and send the payment immediately'
|
|
91
97
|
def pay(amount, fee, sources, target, change)
|
|
92
|
-
|
|
98
|
+
keys = sources.split(',')
|
|
99
|
+
if amount.upcase == 'MAX'
|
|
100
|
+
addrs = keys.map { |k| Sibit::Key.new(k).bech32 }
|
|
101
|
+
amount = addrs.sum { |a| client.balance(a) }
|
|
102
|
+
end
|
|
103
|
+
amount = amount.to_i if amount.is_a?(String) && /^[0-9]+$/.match?(amount)
|
|
93
104
|
fee = fee.to_i if /^[0-9]+$/.match?(fee)
|
|
94
|
-
args = [amount, fee,
|
|
105
|
+
args = [amount, fee, keys, target, change]
|
|
95
106
|
kwargs = { skip_utxo: options[:skip_utxo] }
|
|
96
107
|
unless options[:yes] || options[:dry]
|
|
97
108
|
client(dry: true).pay(*args, **kwargs)
|
|
@@ -99,55 +110,54 @@ class Bin < Thor
|
|
|
99
110
|
answer = $stdin.gets&.strip&.downcase
|
|
100
111
|
raise Sibit::Error, 'Payment cancelled by user' unless answer == 'yes'
|
|
101
112
|
end
|
|
102
|
-
|
|
113
|
+
LOG.info(client.pay(*args, **kwargs))
|
|
103
114
|
end
|
|
104
115
|
|
|
105
116
|
desc 'version', 'Print program version'
|
|
106
117
|
def version
|
|
107
|
-
|
|
118
|
+
LOG.info(Sibit::VERSION)
|
|
108
119
|
end
|
|
109
120
|
|
|
110
121
|
private
|
|
111
122
|
|
|
112
|
-
def log
|
|
113
|
-
@log ||= options[:verbose] ? Loog::VERBOSE : Loog::REGULAR
|
|
114
|
-
end
|
|
115
|
-
|
|
116
123
|
def client(dry: false)
|
|
117
|
-
|
|
124
|
+
proxy = options[:proxy] || ENV.fetch('SIBIT_PROXY', nil)
|
|
125
|
+
http = proxy ? Sibit::HttpProxy.new(proxy) : Sibit::Http.new
|
|
126
|
+
LOG.debug("Using proxy at #{http.host}") if proxy
|
|
118
127
|
apis = options[:api].flat_map { |a| a.split(',') }.map(&:downcase).map do |a|
|
|
119
128
|
case a
|
|
120
129
|
when 'blockchain'
|
|
121
|
-
Sibit::Blockchain.new(http: http, log:
|
|
130
|
+
Sibit::Blockchain.new(http: http, log: LOG)
|
|
122
131
|
when 'btc'
|
|
123
|
-
Sibit::Btc.new(http: http, log:
|
|
132
|
+
Sibit::Btc.new(http: http, log: LOG)
|
|
124
133
|
when 'bitcoinchain'
|
|
125
|
-
Sibit::Bitcoinchain.new(http: http, log:
|
|
134
|
+
Sibit::Bitcoinchain.new(http: http, log: LOG)
|
|
126
135
|
when 'blockchair'
|
|
127
|
-
Sibit::Blockchair.new(http: http, log:
|
|
136
|
+
Sibit::Blockchair.new(http: http, log: LOG)
|
|
128
137
|
when 'cex'
|
|
129
|
-
Sibit::Cex.new(http: http, log:
|
|
138
|
+
Sibit::Cex.new(http: http, log: LOG)
|
|
130
139
|
when 'fake'
|
|
131
140
|
Sibit::Fake.new
|
|
132
141
|
else
|
|
133
142
|
raise Sibit::Error, "Unknown API \"#{a}\""
|
|
134
143
|
end
|
|
135
144
|
end
|
|
136
|
-
api = Sibit::FirstOf.new(apis, log:
|
|
137
|
-
api = Sibit::Dry.new(api, log:
|
|
145
|
+
api = Sibit::FirstOf.new(apis, log: LOG, verbose: true)
|
|
146
|
+
api = Sibit::Dry.new(api, log: LOG) if options[:dry] || dry
|
|
138
147
|
api = RetriableProxy.for_object(api, on: Sibit::Error) if options[:attempts] > 1
|
|
139
|
-
Sibit.new(log:
|
|
148
|
+
Sibit.new(log: LOG, api: api)
|
|
140
149
|
end
|
|
141
150
|
end
|
|
142
151
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
if __FILE__ == $PROGRAM_NAME
|
|
153
|
+
begin
|
|
154
|
+
Bin.start(ARGV)
|
|
155
|
+
rescue StandardError => e
|
|
156
|
+
if VERBOSE
|
|
157
|
+
LOG.error(Backtrace.new(e))
|
|
158
|
+
else
|
|
159
|
+
LOG.error(e.message)
|
|
160
|
+
end
|
|
161
|
+
exit(255)
|
|
151
162
|
end
|
|
152
|
-
exit(255)
|
|
153
163
|
end
|
data/lib/sibit/httpproxy.rb
CHANGED
data/lib/sibit/version.rb
CHANGED