electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 785fe6aeeacef8b88cb2b8adb19df6d1612b9a1a
parent 738411e32bacbb6d2859cbbc782634e3d5dff7d2
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu,  4 Mar 2021 12:14:47 +0100

lnutil: (trivial) add ShortChannelID.from_str() method

for console use atm

Diffstat:
Melectrum/lnutil.py | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -1266,6 +1266,18 @@ class ShortChannelID(bytes): return ShortChannelID(bh + tpos + oi) @classmethod + def from_str(cls, scid: str) -> 'ShortChannelID': + """Parses a formatted scid str, e.g. '643920x356x0'.""" + components = scid.split("x") + if len(components) != 3: + raise ValueError(f"failed to parse ShortChannelID: {scid!r}") + try: + components = [int(x) for x in components] + except ValueError: + raise ValueError(f"failed to parse ShortChannelID: {scid!r}") from None + return ShortChannelID.from_components(*components) + + @classmethod def normalize(cls, data: Union[None, str, bytes, 'ShortChannelID']) -> Optional['ShortChannelID']: if isinstance(data, ShortChannelID) or data is None: return data