Skip to content

Commit 668cd83

Browse files
gudnufdaywalker90
authored andcommitted
add clnrest object to plugin manifest
1 parent f77d4d7 commit 668cd83

File tree

15 files changed

+428
-131
lines changed

15 files changed

+428
-131
lines changed

.msggen.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,10 +1462,17 @@
14621462
},
14631463
"HelpHelp": {
14641464
"Help.help[].category": 2,
1465+
"Help.help[].clnrest": 5,
14651466
"Help.help[].command": 1,
14661467
"Help.help[].description": 3,
14671468
"Help.help[].verbose": 4
14681469
},
1470+
"HelpHelpClnrest": {
1471+
"Help.help[].clnrest.content_type": 3,
1472+
"Help.help[].clnrest.method": 2,
1473+
"Help.help[].clnrest.path": 1,
1474+
"Help.help[].clnrest.rune": 4
1475+
},
14691476
"HelpRequest": {
14701477
"Help.command": 1
14711478
},
@@ -6184,6 +6191,26 @@
61846191
"added": "pre-v0.10.1",
61856192
"deprecated": null
61866193
},
6194+
"Help.help[].clnrest": {
6195+
"added": "v24.08",
6196+
"deprecated": null
6197+
},
6198+
"Help.help[].clnrest.content_type": {
6199+
"added": "v24.08",
6200+
"deprecated": null
6201+
},
6202+
"Help.help[].clnrest.method": {
6203+
"added": "v24.08",
6204+
"deprecated": null
6205+
},
6206+
"Help.help[].clnrest.path": {
6207+
"added": "v24.08",
6208+
"deprecated": null
6209+
},
6210+
"Help.help[].clnrest.rune": {
6211+
"added": "v24.08",
6212+
"deprecated": null
6213+
},
61876214
"Help.help[].command": {
61886215
"added": "pre-v0.10.1",
61896216
"deprecated": null

cln-grpc/proto/node.proto

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/msggen/msggen/schema.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12779,6 +12779,34 @@
1277912779
"description": [
1278012780
"The command."
1278112781
]
12782+
},
12783+
"clnrest": {
12784+
"type": "object",
12785+
"additionalProperties": false,
12786+
"required": [],
12787+
"added": "v24.08",
12788+
"properties": {
12789+
"path": {
12790+
"type": "string",
12791+
"description": "the path to the HTTP endpoint for this command",
12792+
"added": "v24.08"
12793+
},
12794+
"method": {
12795+
"type": "string",
12796+
"description": "the HTTP method for this command",
12797+
"added": "v24.08"
12798+
},
12799+
"content_type": {
12800+
"type": "string",
12801+
"description": "http content-type that clnrest should return",
12802+
"added": "v24.08"
12803+
},
12804+
"rune": {
12805+
"type": "boolean",
12806+
"description": "whether or not this command requires a rune for authentication",
12807+
"added": "v24.08"
12808+
}
12809+
}
1278212810
}
1278312811
}
1278412812
}

contrib/pyln-client/pyln/client/plugin.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from dataclasses import dataclass
1313
from enum import Enum
1414
from threading import RLock
15-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
15+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, TypedDict
1616

1717
from .lightning import LightningRpc, Millisatoshi
1818

@@ -37,6 +37,11 @@ class RequestState(Enum):
3737
FINISHED = 'finished'
3838
FAILED = 'failed'
3939

40+
class CLNRestData(TypedDict):
41+
path: str
42+
method: str
43+
content_type: str
44+
rune: bool
4045

4146
class Method(object):
4247
"""Description of methods that are registered with the plugin.
@@ -49,7 +54,8 @@ class Method(object):
4954
def __init__(self, name: str, func: Callable[..., JSONType],
5055
mtype: MethodType = MethodType.RPCMETHOD,
5156
category: str = None, desc: str = None,
52-
long_desc: str = None, deprecated: Union[bool, List[str]] = None):
57+
long_desc: str = None, deprecated: Union[bool, List[str]] = None,
58+
clnrest_data: CLNRestData = None):
5359
self.name = name
5460
self.func = func
5561
self.mtype = mtype
@@ -60,6 +66,7 @@ def __init__(self, name: str, func: Callable[..., JSONType],
6066
self.deprecated = deprecated
6167
self.before: List[str] = []
6268
self.after: List[str] = []
69+
self.clnrest = clnrest_data
6370

6471

6572
class RpcException(Exception):
@@ -330,7 +337,8 @@ def add_method(self, name: str, func: Callable[..., Any],
330337
category: Optional[str] = None,
331338
desc: Optional[str] = None,
332339
long_desc: Optional[str] = None,
333-
deprecated: Optional[Union[bool, List[str]]] = None) -> None:
340+
deprecated: Optional[Union[bool, List[str]]] = None,
341+
clnrest_data: CLNRestData = None) -> None:
334342
"""Add a plugin method to the dispatch table.
335343
336344
The function will be expected at call time (see `_dispatch`)
@@ -372,7 +380,7 @@ def add_method(self, name: str, func: Callable[..., Any],
372380
# Register the function with the name
373381
method = Method(
374382
name, func, MethodType.RPCMETHOD, category, desc, long_desc,
375-
deprecated
383+
deprecated, clnrest_data
376384
)
377385

378386
method.background = background
@@ -491,22 +499,24 @@ def get_option(self, name: str) -> Optional[Any]:
491499
def async_method(self, method_name: str, category: Optional[str] = None,
492500
desc: Optional[str] = None,
493501
long_desc: Optional[str] = None,
494-
deprecated: Optional[Union[bool, List[str]]] = None) -> NoneDecoratorType:
502+
deprecated: Optional[Union[bool, List[str]]] = None,
503+
clnrest_data: CLNRestData = None) -> NoneDecoratorType:
495504
"""Decorator to add an async plugin method to the dispatch table.
496505
497506
Internally uses add_method.
498507
"""
499508
def decorator(f: Callable[..., None]) -> Callable[..., None]:
500509
self.add_method(method_name, f, background=True, category=category,
501510
desc=desc, long_desc=long_desc,
502-
deprecated=deprecated)
511+
deprecated=deprecated, clnrest_data=clnrest_data)
503512
return f
504513
return decorator
505514

506515
def method(self, method_name: str, category: Optional[str] = None,
507516
desc: Optional[str] = None,
508517
long_desc: Optional[str] = None,
509-
deprecated: Union[bool, List[str]] = None) -> JsonDecoratorType:
518+
deprecated: Union[bool, List[str]] = None,
519+
clnrest_data: Optional[CLNRestData] = None) -> JsonDecoratorType:
510520
"""Decorator to add a plugin method to the dispatch table.
511521
512522
Internally uses add_method.
@@ -518,7 +528,8 @@ def decorator(f: Callable[..., JSONType]) -> Callable[..., JSONType]:
518528
category=category,
519529
desc=desc,
520530
long_desc=long_desc,
521-
deprecated=deprecated)
531+
deprecated=deprecated,
532+
clnrest_data=clnrest_data)
522533
return f
523534
return decorator
524535

@@ -964,6 +975,9 @@ def _getmanifest(self, **kwargs) -> JSONType:
964975
if method.long_desc:
965976
m = methods[len(methods) - 1]
966977
m["long_description"] = method.long_desc
978+
if method.clnrest:
979+
m = methods[len(methods) - 1]
980+
m["clnrest"] = method.clnrest
967981

968982
manifest = {
969983
'options': list(d.json() for d in self.options.values()),

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 110 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/pyln-testing/pyln/testing/grpc2py.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,15 @@ def stop2py(m):
26362636
})
26372637

26382638

2639+
def help_help_clnrest2py(m):
2640+
return remove_default({
2641+
"content_type": m.content_type, # PrimitiveField in generate_composite
2642+
"method": m.method, # PrimitiveField in generate_composite
2643+
"path": m.path, # PrimitiveField in generate_composite
2644+
"rune": m.rune, # PrimitiveField in generate_composite
2645+
})
2646+
2647+
26392648
def help_help2py(m):
26402649
return remove_default({
26412650
"command": m.command, # PrimitiveField in generate_composite

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Core Lightning Documentation
109109
lightning-sendcustommsg <lightning-sendcustommsg.7.md>
110110
lightning-sendinvoice <lightning-sendinvoice.7.md>
111111
lightning-sendonion <lightning-sendonion.7.md>
112+
lightning-sendonionmessage <lightning-sendonionmessage.7.md>
112113
lightning-sendpay <lightning-sendpay.7.md>
113114
lightning-sendpsbt <lightning-sendpsbt.7.md>
114115
lightning-setchannel <lightning-setchannel.7.md>

doc/schemas/lightning-help.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@
3939
"description": [
4040
"The command."
4141
]
42+
},
43+
"clnrest": {
44+
"type": "object",
45+
"additionalProperties": false,
46+
"required": [],
47+
"added": "v24.08",
48+
"properties": {
49+
"path": {
50+
"type": "string",
51+
"description": "the path to the HTTP endpoint for this command",
52+
"added": "v24.08"
53+
},
54+
"method": {
55+
"type": "string",
56+
"description": "the HTTP method for this command",
57+
"added": "v24.08"
58+
},
59+
"content_type": {
60+
"type": "string",
61+
"description": "http content-type that clnrest should return",
62+
"added": "v24.08"
63+
},
64+
"rune": {
65+
"type": "boolean",
66+
"description": "whether or not this command requires a rune for authentication",
67+
"added": "v24.08"
68+
}
69+
}
4270
}
4371
}
4472
}

0 commit comments

Comments
 (0)