diff --git a/logic.py b/logic.py index 0b4eebf..5cf1ee8 100644 --- a/logic.py +++ b/logic.py @@ -1,8 +1,7 @@ import math -import output from output import Output, format_alias, format_fee_msat, format_ppm, format_amount, format_boring_string, \ - format_fee_sat, format_warning, format_error, format_earning, format_fee_msat_red + format_fee_sat, format_warning, format_error, format_earning, format_fee_msat_red, format_channel_id from routes import Routes DEFAULT_BASE_FEE_SAT_MSAT = 1_000 @@ -50,7 +49,7 @@ def rebalance(self): first_channel_id = 0 if self.first_hop_channel: first_hop_alias_formatted = format_alias(self.lnd.get_node_alias(self.first_hop_channel.remote_pubkey)) - first_channel_id = format_boring_string(self.first_hop_channel.chan_id) + first_channel_id = format_channel_id(self.first_hop_channel.chan_id) if self.last_hop_channel: last_hop_alias_formatted = format_alias(self.lnd.get_node_alias(self.last_hop_channel.remote_pubkey)) amount_formatted = format_amount(self.amount) @@ -368,7 +367,7 @@ def initialize_ignored_channels(self, routes, fee_limit_msat, min_ppm_last_hop): if self.low_outbound_liquidity_after_sending(channel, self.amount): routes.ignore_first_hop(channel, show_message=False) if channel.chan_id in self.excluded: - self.output.print_line(f"Channel {format_boring_string(channel.chan_id)} is excluded:") + self.output.print_line(f"Channel {format_channel_id(channel.chan_id)} is excluded:") routes.ignore_first_hop(channel) def ignore_low_ppm_channels_for_last_hop(self, min_ppm_last_hop, routes): diff --git a/output.py b/output.py index b7abadd..02d5d55 100644 --- a/output.py +++ b/output.py @@ -24,7 +24,7 @@ def print_route(self, route): self.print_line(route_str) def get_channel_representation(self, chan_id, pubkey_to, pubkey_from=None): - channel_id_formatted = format_boring_string(chan_id) + channel_id_formatted = format_channel_id(chan_id) if pubkey_from: alias_to_formatted = format_alias(self.lnd.get_node_alias(pubkey_to)) alias_from = format_alias(self.lnd.get_node_alias(pubkey_from)) @@ -92,6 +92,10 @@ def format_boring_string(string): return chalk.bg_black(chalk.gray(string)) +def format_channel_id(channel_id): + return format_boring_string(channel_id) + + def format_warning(warning): return chalk.yellow(warning) diff --git a/rebalance.py b/rebalance.py index cf0afe7..0928ecd 100755 --- a/rebalance.py +++ b/rebalance.py @@ -8,10 +8,10 @@ from yachalk import chalk -import output from lnd import Lnd from logic import Logic -from output import Output, format_alias, format_ppm, format_amount, format_amount_green, format_boring_string, print_bar +from output import Output, format_alias, format_ppm, format_amount, format_amount_green, format_boring_string, \ + print_bar, format_channel_id, format_error MAX_SATOSHIS_PER_TRANSACTION = 4294967 @@ -80,7 +80,7 @@ def get_rebalance_amount(self, channel): def get_amount(self): if self.arguments.amount: if self.arguments.reckless and self.arguments.amount > MAX_SATOSHIS_PER_TRANSACTION: - self.output.print_line(output.format_error("Trying to send wumbo transaction")) + self.output.print_line(format_error("Trying to send wumbo transaction")) return self.arguments.amount else: return min(self.arguments.amount, MAX_SATOSHIS_PER_TRANSACTION) @@ -94,8 +94,8 @@ def get_amount(self): if can_send < 0: from_alias = self.lnd.get_node_alias(self.first_hop_channel.remote_pubkey) print( - f"Error: source channel {output.format_boring_string(self.first_hop_channel.chan_id)} to " - f"{output.format_alias(from_alias)} needs to {chalk.green('receive')} funds to be within bounds," + f"Error: source channel {format_channel_id(self.first_hop_channel.chan_id)} to " + f"{format_alias(from_alias)} needs to {chalk.green('receive')} funds to be within bounds," f" you want it to {chalk.red('send')} funds. " "Specify amount manually if this was intended." ) @@ -110,8 +110,8 @@ def get_amount(self): if can_receive < 0: to_alias = self.lnd.get_node_alias(self.last_hop_channel.remote_pubkey) print( - f"Error: target channel {output.format_boring_string(self.last_hop_channel.chan_id)} to " - f"{output.format_alias(to_alias)} needs to {chalk.green('send')} funds to be within bounds, " + f"Error: target channel {format_channel_id(self.last_hop_channel.chan_id)} to " + f"{format_alias(to_alias)} needs to {chalk.green('send')} funds to be within bounds, " f"you want it to {chalk.red('receive')} funds." f" Specify amount manually if this was intended." ) @@ -165,7 +165,7 @@ def show_channel(self, channel, reverse=False): ) own_ppm = self.lnd.get_ppm_to(channel.chan_id) remote_ppm = self.lnd.get_ppm_from(channel.chan_id) - print(f"Channel ID: {format_boring_string(channel.chan_id)}") + print(f"Channel ID: {format_channel_id(channel.chan_id)}") print(f"Alias: {format_alias(self.lnd.get_node_alias(channel.remote_pubkey))}") print(f"Pubkey: {format_boring_string(channel.remote_pubkey)}") print(f"Channel Point: {format_boring_string(channel.channel_point)}") @@ -185,7 +185,7 @@ def list_channels_compact(self): reverse=False ) for candidate in candidates: - id_formatted = format_boring_string(candidate.chan_id) + id_formatted = format_channel_id(candidate.chan_id) local_formatted = format_amount_green(get_local_available(candidate), 11) remote_formatted = format_amount(get_remote_available(candidate), 11) alias_formatted = format_alias(self.lnd.get_node_alias(candidate.remote_pubkey)) @@ -236,7 +236,7 @@ def start(self): sys.exit(0) if self.arguments.reckless: - self.output.print_line(output.format_error("Reckless mode enabled!")) + self.output.print_line(format_error("Reckless mode enabled!")) fee_factor = self.arguments.fee_factor fee_limit_sat = self.arguments.fee_limit