lnutil: (trivial) add ShortChannelID.from_str() method
for console use atm
This commit is contained in:
@@ -1265,6 +1265,18 @@ class ShortChannelID(bytes):
|
|||||||
oi = output_index.to_bytes(2, byteorder='big')
|
oi = output_index.to_bytes(2, byteorder='big')
|
||||||
return ShortChannelID(bh + tpos + oi)
|
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
|
@classmethod
|
||||||
def normalize(cls, data: Union[None, str, bytes, 'ShortChannelID']) -> Optional['ShortChannelID']:
|
def normalize(cls, data: Union[None, str, bytes, 'ShortChannelID']) -> Optional['ShortChannelID']:
|
||||||
if isinstance(data, ShortChannelID) or data is None:
|
if isinstance(data, ShortChannelID) or data is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user