From aa0efca2bcae3972db04e1d2ec5f02cd32014e6b Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Tue, 31 Aug 2021 11:55:08 +0200 Subject: [PATCH] autopilot: return messages on run_once --- autopilot/autopilot.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/autopilot/autopilot.py b/autopilot/autopilot.py index 6698ba9..ce7b9c6 100755 --- a/autopilot/autopilot.py +++ b/autopilot/autopilot.py @@ -107,15 +107,19 @@ class CLightning_autopilot(Autopilot): def connect(self, candidates, balance=1000000, dryrun=False): pdf = self.calculate_statistics(candidates) connection_dict = self.calculate_proposed_channel_capacities(pdf, balance) + messages = [] for nodeid, fraction in connection_dict.items(): try: 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: self.__rpc_interface.connect(nodeid) self.__rpc_interface.fundchannel(nodeid, satoshis, None, True, 0) 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() @@ -179,7 +183,7 @@ def run_once(plugin, dryrun=False): strategy=Strategy.DIVERSE, percentile=0.5 ) - plugin.autopilot.connect(candidates, available_funds, dryrun=dryrun) + return plugin.autopilot.connect(candidates, available_funds, dryrun=dryrun) plugin.add_option(