Skip to content

Commit

Permalink
improve robustness w.r.t commas and whitespace in chan/node list files (
Browse files Browse the repository at this point in the history
fixes #67)
  • Loading branch information
accumulator committed Apr 21, 2022
1 parent c68adef commit 87891b5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions charge_lnd/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def debug(message):

def read_nodelist(url):
with open(url.replace("file://",""),'r') as idfile:
raw_ids = idfile.read().splitlines()
raw_ids = idfile.read().replace(',','\n').splitlines()
node_list = []
for raw_id in raw_ids:
raw_id = raw_id.split('#')[0]
match = re.match("^([0-9a-z]{66})", raw_id)
raw_id = raw_id.split('#')[0].strip()
match = re.match("^([0-9a-z]{66})$", raw_id)
if match:
node_list.append(match.group(0))
else:
Expand All @@ -25,10 +25,10 @@ def read_nodelist(url):

def read_chanlist(url):
with open(url.replace("file://",""),'r') as idfile:
raw_ids = idfile.read().splitlines()
raw_ids = idfile.read().replace(',','\n').splitlines()
chan_list = []
for raw_id in raw_ids:
raw_id = raw_id.split('#')[0]
raw_id = raw_id.split('#')[0].strip()
try:
chan_id = fmt.parse_channel_id(raw_id)
chan_list.append(chan_id)
Expand Down

1 comment on commit 87891b5

@TrezorHannes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you

Please sign in to comment.