@@ -1423,6 +1423,7 @@ static const char *plugin_rpcmethod_clnrest_add(struct plugin *plugin,
14231423{
14241424 const jsmntok_t * clnresttok = json_get_member (buffer , tok , "clnrest" );
14251425
1426+ /** clnrest is an optional field*/
14261427 if (!clnresttok ) {
14271428 cmd -> clnrest = NULL ;
14281429 return NULL ;
@@ -1438,34 +1439,41 @@ static const char *plugin_rpcmethod_clnrest_add(struct plugin *plugin,
14381439 const jsmntok_t * contenttypetok =
14391440 json_get_member (buffer , clnresttok , "content_type" );
14401441 const jsmntok_t * runetok = json_get_member (buffer , clnresttok , "rune" );
1441- const jsmntok_t * pluginnametok = json_get_member (buffer , tok , "name" );
1442+ const jsmntok_t * cmdnametok = json_get_member (buffer , tok , "name" );
1443+
1444+ /** If clnrest is present, then all fields get populated */
1445+ const char * default_method = "POST" ;
1446+ const char * default_content_type = "application/json" ;
1447+ bool default_rune_value = true;
1448+ const char * cmd_name = json_strdup (tmpctx , buffer , cmdnametok );
1449+ const char * default_path = tal_fmt (plugin , "/v1/%s" , cmd_name );
14421450
14431451 if (pathtok ) {
14441452 clnrest -> path = json_strdup (clnrest , buffer , pathtok );
14451453 tal_free (default_path );
14461454 } else {
1447- clnrest -> path = json_strdup ( clnrest , buffer , pluginnametok ) ;
1455+ clnrest -> path = default_path ;
14481456 }
14491457
14501458 if (methodtok ) {
14511459 clnrest -> method = json_strdup (clnrest , buffer , methodtok );
14521460 } else {
1453- clnrest -> method = "GET" ;
1461+ clnrest -> method = default_method ;
14541462 }
14551463
14561464 if (contenttypetok ) {
14571465 clnrest -> content_type =
14581466 json_strdup (clnrest , buffer , contenttypetok );
14591467 } else {
1460- clnrest -> content_type = "application/json" ;
1468+ clnrest -> content_type = default_content_type ;
14611469 }
14621470
1471+ /** whether or not this route requires a rune for authentication */
14631472 if (runetok ) {
14641473 bool rune_value ;
14651474 json_to_bool (buffer , runetok , & rune_value );
14661475 clnrest -> rune = tal_dup (clnrest , bool , & rune_value );
14671476 } else {
1468- bool default_rune_value = true;
14691477 clnrest -> rune = tal_dup (clnrest , bool , & default_rune_value );
14701478 }
14711479
0 commit comments