mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-22 15:44:20 +01:00
Summary: cleanups suggested by @cdecker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -9,6 +9,11 @@ plugin = Plugin(autopatch=True)
|
|||||||
|
|
||||||
|
|
||||||
class PriceThread(threading.Thread):
|
class PriceThread(threading.Thread):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.daemon = True
|
||||||
|
self.start()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
r = requests.get('https://apiv2.bitcoinaverage.com/convert/global'
|
r = requests.get('https://apiv2.bitcoinaverage.com/convert/global'
|
||||||
@@ -43,13 +48,11 @@ def summary(plugin):
|
|||||||
else:
|
else:
|
||||||
reply['my_address'] = plugin.my_address
|
reply['my_address'] = plugin.my_address
|
||||||
|
|
||||||
utxo_amount = Millisatoshi(0)
|
|
||||||
reply['num_utxos'] = 0
|
utxos = [int(f['amount_msat']) for f in funds['outputs']
|
||||||
for f in funds['outputs']:
|
if f['status'] == 'confirmed']
|
||||||
if f['status'] != 'confirmed':
|
reply['num_utxos'] = len(utxos)
|
||||||
continue
|
utxo_amount = Millisatoshi(sum(utxos))
|
||||||
utxo_amount += f['amount_msat']
|
|
||||||
reply['num_utxos'] += 1
|
|
||||||
reply['utxo_amount'] = utxo_amount.to_btc_str()
|
reply['utxo_amount'] = utxo_amount.to_btc_str()
|
||||||
|
|
||||||
avail_out = Millisatoshi(0)
|
avail_out = Millisatoshi(0)
|
||||||
@@ -85,9 +88,9 @@ def summary(plugin):
|
|||||||
reply['avail_in'] = avail_in.to_btc_str()
|
reply['avail_in'] = avail_in.to_btc_str()
|
||||||
|
|
||||||
if plugin.fiat_per_btc:
|
if plugin.fiat_per_btc:
|
||||||
reply['utxo_amount'] += ' = ' + to_fiatstr(utxo_amount)
|
reply['utxo_amount'] += ' = {}'.format(to_fiatstr(utxo_amount))
|
||||||
reply['avail_out'] += ' = ' + to_fiatstr(avail_out)
|
reply['avail_out'] += ' = {}'.format(to_fiatstr(avail_out))
|
||||||
reply['avail_in'] += ' = ' + to_fiatstr(avail_in)
|
reply['avail_in'] += ' = '.format(to_fiatstr(avail_in))
|
||||||
|
|
||||||
if chans != []:
|
if chans != []:
|
||||||
reply['channels'] = []
|
reply['channels'] = []
|
||||||
@@ -117,7 +120,7 @@ def init(options, configuration, plugin):
|
|||||||
info = plugin.rpc.getinfo()
|
info = plugin.rpc.getinfo()
|
||||||
|
|
||||||
# Try to grab conversion price
|
# Try to grab conversion price
|
||||||
PriceThread().start()
|
PriceThread()
|
||||||
|
|
||||||
# Prefer IPv4, otherwise take any to give out address.
|
# Prefer IPv4, otherwise take any to give out address.
|
||||||
best_address = None
|
best_address = None
|
||||||
@@ -131,6 +134,8 @@ def init(options, configuration, plugin):
|
|||||||
plugin.my_address = info['id'] + '@' + best_address['address']
|
plugin.my_address = info['id'] + '@' + best_address['address']
|
||||||
if best_address['port'] != 9735:
|
if best_address['port'] != 9735:
|
||||||
plugin.my_address += ':' + str(best_address['port'])
|
plugin.my_address += ':' + str(best_address['port'])
|
||||||
|
else:
|
||||||
|
plugin.my_address = None
|
||||||
|
|
||||||
plugin.log("Plugin summary.py initialized")
|
plugin.log("Plugin summary.py initialized")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user