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 +4 -4
- data/lib/sibit/bin.rb +15 -9
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +16 -6
- 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: 196fa93e65ec890ca33a83d3d56358f311d57933e20432e61b5e3df32ae8515d
|
|
4
|
+
data.tar.gz: 0d02c5a2f773d84dbd13c614c6e52533e88a88dff5c07e4ff304650311ce5a22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
25
|
+
desc: 'How many times should we try before failing'
|
|
26
26
|
class_option :dry, type: :boolean, default: false,
|
|
27
|
-
|
|
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
|
-
|
|
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
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
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
|
|
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(
|
|
228
|
-
|
|
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?
|