@@ -1392,6 +1392,7 @@ static const char *plugin_rpcmethod_clnrest_add(struct plugin *plugin,
13921392{
13931393 const jsmntok_t * clnresttok = json_get_member (buffer , tok , "clnrest" );
13941394
1395+ /** clnrest is an optional field*/
13951396 if (!clnresttok ) {
13961397 cmd -> clnrest = NULL ;
13971398 return NULL ;
@@ -1407,33 +1408,40 @@ static const char *plugin_rpcmethod_clnrest_add(struct plugin *plugin,
14071408 const jsmntok_t * contenttypetok =
14081409 json_get_member (buffer , clnresttok , "content_type" );
14091410 const jsmntok_t * runetok = json_get_member (buffer , clnresttok , "rune" );
1410- const jsmntok_t * pluginnametok = json_get_member (buffer , tok , "name" );
1411+ const jsmntok_t * cmdnametok = json_get_member (buffer , tok , "name" );
1412+
1413+ /** If clnrest is present, then all fields get populated */
1414+ const char * default_method = "POST" ;
1415+ const char * default_content_type = "application/json" ;
1416+ bool default_rune_value = true;
1417+ const char * cmd_name = json_strdup (tmpctx , buffer , cmdnametok );
1418+ const char * default_path = tal_fmt (plugin , "/v1/%s" , cmd_name );
14111419
14121420 if (pathtok ) {
14131421 clnrest -> path = json_strdup (clnrest , buffer , pathtok );
14141422 } else {
1415- clnrest -> path = json_strdup ( clnrest , buffer , pluginnametok ) ;
1423+ clnrest -> path = default_path ;
14161424 }
14171425
14181426 if (methodtok ) {
14191427 clnrest -> method = json_strdup (clnrest , buffer , methodtok );
14201428 } else {
1421- clnrest -> method = "GET" ;
1429+ clnrest -> method = default_method ;
14221430 }
14231431
14241432 if (contenttypetok ) {
14251433 clnrest -> content_type =
14261434 json_strdup (clnrest , buffer , contenttypetok );
14271435 } else {
1428- clnrest -> content_type = "application/json" ;
1436+ clnrest -> content_type = default_content_type ;
14291437 }
14301438
1439+ /** whether or not this route requires a rune for authentication */
14311440 if (runetok ) {
14321441 bool rune_value ;
14331442 json_to_bool (buffer , runetok , & rune_value );
14341443 clnrest -> rune = tal_dup (clnrest , bool , & rune_value );
14351444 } else {
1436- bool default_rune_value = true;
14371445 clnrest -> rune = tal_dup (clnrest , bool , & default_rune_value );
14381446 }
14391447
0 commit comments