mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-23 16:14:20 +01:00
autopilot: return messages on run_once
This commit is contained in:
@@ -107,15 +107,19 @@ class CLightning_autopilot(Autopilot):
|
|||||||
def connect(self, candidates, balance=1000000, dryrun=False):
|
def connect(self, candidates, balance=1000000, dryrun=False):
|
||||||
pdf = self.calculate_statistics(candidates)
|
pdf = self.calculate_statistics(candidates)
|
||||||
connection_dict = self.calculate_proposed_channel_capacities(pdf, balance)
|
connection_dict = self.calculate_proposed_channel_capacities(pdf, balance)
|
||||||
|
messages = []
|
||||||
for nodeid, fraction in connection_dict.items():
|
for nodeid, fraction in connection_dict.items():
|
||||||
try:
|
try:
|
||||||
satoshis = min(math.ceil(balance * fraction), 16777215)
|
satoshis = min(math.ceil(balance * fraction), 16777215)
|
||||||
print("Try to open channel with a capacity of {} to node {}".format(satoshis, nodeid))
|
messages.append(f"Try to open channel with a capacity of {satoshis} to node {nodeid}")
|
||||||
|
plugin.log(messages[-1])
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
self.__rpc_interface.connect(nodeid)
|
self.__rpc_interface.connect(nodeid)
|
||||||
self.__rpc_interface.fundchannel(nodeid, satoshis, None, True, 0)
|
self.__rpc_interface.fundchannel(nodeid, satoshis, None, True, 0)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print("Could not open a channel to {} with capacity of {}. Error: {}".format(nodeid, satoshis, str(e)))
|
messages.append(f"Could not open a channel to {nodeid} with capacity of {satoshis}. Error: {str(e)}")
|
||||||
|
plugin.log(messages[-1], 'error')
|
||||||
|
return messages
|
||||||
|
|
||||||
|
|
||||||
@plugin.init()
|
@plugin.init()
|
||||||
@@ -179,7 +183,7 @@ def run_once(plugin, dryrun=False):
|
|||||||
strategy=Strategy.DIVERSE,
|
strategy=Strategy.DIVERSE,
|
||||||
percentile=0.5
|
percentile=0.5
|
||||||
)
|
)
|
||||||
plugin.autopilot.connect(candidates, available_funds, dryrun=dryrun)
|
return plugin.autopilot.connect(candidates, available_funds, dryrun=dryrun)
|
||||||
|
|
||||||
|
|
||||||
plugin.add_option(
|
plugin.add_option(
|
||||||
|
|||||||
Reference in New Issue
Block a user