Skip to content

Commit 0a5b2b3

Browse files
committed
add clnrest object to plugin manifest
1 parent 10acbff commit 0a5b2b3

File tree

15 files changed

+428
-132
lines changed

15 files changed

+428
-132
lines changed

.msggen.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,17 @@
14471447
},
14481448
"HelpHelp": {
14491449
"Help.help[].category": 2,
1450+
"Help.help[].clnrest": 5,
14501451
"Help.help[].command": 1,
14511452
"Help.help[].description": 3,
14521453
"Help.help[].verbose": 4
14531454
},
1455+
"HelpHelpClnrest": {
1456+
"Help.help[].clnrest.content_type": 3,
1457+
"Help.help[].clnrest.method": 2,
1458+
"Help.help[].clnrest.path": 1,
1459+
"Help.help[].clnrest.rune": 4
1460+
},
14541461
"HelpRequest": {
14551462
"Help.command": 1
14561463
},
@@ -6125,6 +6132,26 @@
61256132
"added": "pre-v0.10.1",
61266133
"deprecated": null
61276134
},
6135+
"Help.help[].clnrest": {
6136+
"added": "v24.08",
6137+
"deprecated": null
6138+
},
6139+
"Help.help[].clnrest.content_type": {
6140+
"added": "v24.08",
6141+
"deprecated": null
6142+
},
6143+
"Help.help[].clnrest.method": {
6144+
"added": "v24.08",
6145+
"deprecated": null
6146+
},
6147+
"Help.help[].clnrest.path": {
6148+
"added": "v24.08",
6149+
"deprecated": null
6150+
},
6151+
"Help.help[].clnrest.rune": {
6152+
"added": "v24.08",
6153+
"deprecated": null
6154+
},
61286155
"Help.help[].command": {
61296156
"added": "pre-v0.10.1",
61306157
"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
@@ -12587,6 +12587,34 @@
1258712587
"description": [
1258812588
"A full description of this command (including whether it's deprecated)."
1258912589
]
12590+
},
12591+
"clnrest": {
12592+
"type": "object",
12593+
"additionalProperties": false,
12594+
"required": [],
12595+
"added": "v24.08",
12596+
"properties": {
12597+
"path": {
12598+
"type": "string",
12599+
"description": "the path to the HTTP endpoint for this command",
12600+
"added": "v24.08"
12601+
},
12602+
"method": {
12603+
"type": "string",
12604+
"description": "the HTTP method for this command",
12605+
"added": "v24.08"
12606+
},
12607+
"content_type": {
12608+
"type": "string",
12609+
"description": "http content-type that clnrest should return",
12610+
"added": "v24.08"
12611+
},
12612+
"rune": {
12613+
"type": "boolean",
12614+
"description": "whether or not this command requires a rune for authentication",
12615+
"added": "v24.08"
12616+
}
12617+
}
1259012618
}
1259112619
}
1259212620
}

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: 111 additions & 109 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
@@ -2615,6 +2615,15 @@ def stop2py(m):
26152615
})
26162616

26172617

2618+
def help_help_clnrest2py(m):
2619+
return remove_default({
2620+
"content_type": m.content_type, # PrimitiveField in generate_composite
2621+
"method": m.method, # PrimitiveField in generate_composite
2622+
"path": m.path, # PrimitiveField in generate_composite
2623+
"rune": m.rune, # PrimitiveField in generate_composite
2624+
})
2625+
2626+
26182627
def help_help2py(m):
26192628
return remove_default({
26202629
"category": m.category, # 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
@@ -60,6 +60,34 @@
6060
"description": [
6161
"A full description of this command (including whether it's deprecated)."
6262
]
63+
},
64+
"clnrest": {
65+
"type": "object",
66+
"additionalProperties": false,
67+
"required": [],
68+
"added": "v24.08",
69+
"properties": {
70+
"path": {
71+
"type": "string",
72+
"description": "the path to the HTTP endpoint for this command",
73+
"added": "v24.08"
74+
},
75+
"method": {
76+
"type": "string",
77+
"description": "the HTTP method for this command",
78+
"added": "v24.08"
79+
},
80+
"content_type": {
81+
"type": "string",
82+
"description": "http content-type that clnrest should return",
83+
"added": "v24.08"
84+
},
85+
"rune": {
86+
"type": "boolean",
87+
"description": "whether or not this command requires a rune for authentication",
88+
"added": "v24.08"
89+
}
90+
}
6391
}
6492
}
6593
}

0 commit comments

Comments
 (0)