|
48 | 48 | from .lnworker import LN_P2P_NETWORK_TIMEOUT |
49 | 49 | from .logging import Logger |
50 | 50 | from .onion_message import create_blinded_path, send_onion_message_to |
51 | | -from .segwit_addr import bech32_encode, Encoding, convertbits |
| 51 | +from .segwit_addr import bech32_encode, Encoding, convertbits, INVALID_BECH32 |
52 | 52 | from .submarine_swaps import NostrTransport |
53 | 53 | from .util import ( |
54 | 54 | bfh, json_decode, json_normalize, is_hash256_str, is_hex_str, to_bytes, parse_max_spend, to_decimal, |
55 | | - UserFacingException, InvalidPassword |
| 55 | + UserFacingException, InvalidPassword, json_encode |
56 | 56 | ) |
57 | 57 | from . import bitcoin |
58 | 58 | from .bitcoin import is_address, hash_160, COIN |
@@ -2275,6 +2275,18 @@ async def get_blinded_path_via(self, node_id: str, dummy_hops: int = 0, wallet: |
2275 | 2275 |
|
2276 | 2276 | return encoded_blinded_path.hex() |
2277 | 2277 |
|
| 2278 | + @command('') |
| 2279 | + async def decode_bolt12(self, bech32: str): |
| 2280 | + dec = bolt12.bech32_decode(bech32, ignore_long_length=True, with_checksum=False) |
| 2281 | + if dec == INVALID_BECH32: |
| 2282 | + raise Exception('invalid bech32') |
| 2283 | + d = { |
| 2284 | + 'lni': bolt12.decode_invoice, |
| 2285 | + 'lno': bolt12.decode_offer, |
| 2286 | + 'lnr': bolt12.decode_invoice_request, |
| 2287 | + }[dec.hrp](bech32) |
| 2288 | + return json_encode(d) |
| 2289 | + |
2278 | 2290 |
|
2279 | 2291 | def plugin_command(s, plugin_name): |
2280 | 2292 | """Decorator to register a cli command inside a plugin. To be used within a commands.py file |
|
0 commit comments