sibit 0.7.3 → 0.7.4
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/version.rb +1 -1
- data/lib/sibit.rb +20 -23
- 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: ebf35087ce8b3d8593fb71fbf92f73663ee1271e5ec12d9b0ce1a96e24acf391
|
|
4
|
+
data.tar.gz: 468f3061a5f8f74d31e5356f6aac583d699524a1267f5a529e58ee69e1e13bbc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea42fd169efa160dd5cbbe4da51f15f23dda6d37a684415156a5dd1b5a84d7dc1010ba586385a69fcfdae2f37eb25055e0001cbfa491324815e807a923f0e681
|
|
7
|
+
data.tar.gz: d187e1c3f6284666bf1f84710cf85d00090f15749a8ef0df5c4d6f7733186e0b402d6b28d34deb4a240689322b2bccb11125f24c23b8d70ebfa48cd05234029e
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED
|
@@ -72,7 +72,7 @@ class Sibit
|
|
|
72
72
|
#
|
|
73
73
|
# You may provide the log you want to see the messages in. If you don't
|
|
74
74
|
# provide anything, the console will be used. The object you provide
|
|
75
|
-
# has to respond to the method +
|
|
75
|
+
# has to respond to the method +info+ or +puts+ in order to receive logging
|
|
76
76
|
# messages.
|
|
77
77
|
def initialize(log: STDOUT)
|
|
78
78
|
@log = log
|
|
@@ -98,8 +98,8 @@ class Sibit
|
|
|
98
98
|
# Gets the balance of the address, in satoshi.
|
|
99
99
|
def balance(address)
|
|
100
100
|
json = get_json("/rawaddr/#{address}")
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
info("Total transactions: #{json['n_tx']}")
|
|
102
|
+
info("Received/sent: #{json['total_received']}/#{json['total_sent']}")
|
|
103
103
|
json['final_balance']
|
|
104
104
|
end
|
|
105
105
|
|
|
@@ -128,7 +128,7 @@ class Sibit
|
|
|
128
128
|
utxos = get_json(
|
|
129
129
|
"/unspent?active=#{sources.keys.join('|')}&limit=1000"
|
|
130
130
|
)['unspent_outputs']
|
|
131
|
-
|
|
131
|
+
info("#{utxos.count} UTXOs found:")
|
|
132
132
|
utxos.each do |utxo|
|
|
133
133
|
unspent += utxo['value']
|
|
134
134
|
builder.input do |i|
|
|
@@ -139,16 +139,20 @@ class Sibit
|
|
|
139
139
|
i.signature_key(key(sources[address]))
|
|
140
140
|
end
|
|
141
141
|
size += 180
|
|
142
|
-
|
|
142
|
+
info(" #{utxo['value']}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
|
|
143
143
|
break if unspent > satoshi
|
|
144
144
|
end
|
|
145
145
|
raise Error, "Not enough funds to send #{amount}, only #{unspent} left" if unspent < satoshi
|
|
146
146
|
builder.output(satoshi, target)
|
|
147
|
+
f = mfee(fee, size)
|
|
147
148
|
tx = builder.tx(
|
|
148
149
|
input_value: unspent,
|
|
149
|
-
leave_fee:
|
|
150
|
+
leave_fee: f,
|
|
150
151
|
change_address: change
|
|
151
152
|
)
|
|
153
|
+
info("A new Bitcoin transaction #{tx.hash} prepared; #{tx.in.count} inputs; \
|
|
154
|
+
#{tx.out.count} outputs; fee is #{f}; size is #{size}; unspent is #{unspent}; \
|
|
155
|
+
amount is #{amount}; target address is #{target}; change address is #{change}")
|
|
152
156
|
post_tx(tx.to_payload.bth)
|
|
153
157
|
tx.hash
|
|
154
158
|
end
|
|
@@ -165,7 +169,7 @@ class Sibit
|
|
|
165
169
|
start = Time.now
|
|
166
170
|
res = Net::HTTP.get_response(URI('https://blockchain.info' + uri))
|
|
167
171
|
raise Error, "Failed to retrieve #{uri}: #{res.code}" unless res.code == '200'
|
|
168
|
-
|
|
172
|
+
info("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
|
|
169
173
|
JSON.parse(res.body)
|
|
170
174
|
end
|
|
171
175
|
|
|
@@ -182,18 +186,11 @@ class Sibit
|
|
|
182
186
|
def mfee(fee, size)
|
|
183
187
|
return fee.to_i if fee.is_a?(Integer)
|
|
184
188
|
raise Error, 'Fee should either be a String or Integer' unless fee.is_a?(String)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
when 'L'
|
|
191
|
-
return 100 * size
|
|
192
|
-
when 'XL'
|
|
193
|
-
return 250 * size
|
|
194
|
-
else
|
|
195
|
-
raise Error, "Can't understand the fee: #{fee.inspect}"
|
|
196
|
-
end
|
|
189
|
+
return 10 * size if fee == 'S'
|
|
190
|
+
return 50 * size if fee == 'M'
|
|
191
|
+
return 100 * size if fee == 'L'
|
|
192
|
+
return 250 * size if fee == 'XL'
|
|
193
|
+
raise Error, "Can't understand the fee: #{fee.inspect}"
|
|
197
194
|
end
|
|
198
195
|
|
|
199
196
|
# Make key from private key string in Hash160.
|
|
@@ -212,12 +209,12 @@ class Sibit
|
|
|
212
209
|
uri = URI('https://blockchain.info/pushtx')
|
|
213
210
|
res = Net::HTTP.post_form(uri, tx: body)
|
|
214
211
|
raise Error, "Failed to post tx to #{uri}: #{res.code}\n#{res.body}" unless res.code == '200'
|
|
215
|
-
|
|
212
|
+
info("POST #{uri}: #{res.code} in #{age(start)}")
|
|
216
213
|
end
|
|
217
214
|
|
|
218
|
-
def
|
|
219
|
-
if @log.respond_to?(:
|
|
220
|
-
@log.
|
|
215
|
+
def info(msg)
|
|
216
|
+
if @log.respond_to?(:info)
|
|
217
|
+
@log.info(msg)
|
|
221
218
|
elsif @log.respond_to?(:puts)
|
|
222
219
|
@log.puts(msg)
|
|
223
220
|
end
|