| 3276 | } |
| 3277 | |
| 3278 | static struct command_result *handle_rpc_command(struct command *cmd, |
| 3279 | const char *buf, |
| 3280 | const jsmntok_t *params) |
| 3281 | { |
| 3282 | struct xpay *xpay = xpay_of(cmd->plugin); |
| 3283 | const jsmntok_t *rpc_tok, *method_tok, *params_tok, *id_tok, |
| 3284 | *bolt11 = NULL, *amount_msat = NULL, |
| 3285 | *partial_msat = NULL, *retry_for = NULL, *maxdelay = NULL, *localinvreqid = NULL, *label = NULL; |
| 3286 | const char *maxfee = NULL; |
| 3287 | struct json_stream *response; |
| 3288 | |
| 3289 | /* pay extra params */ |
| 3290 | const jsmntok_t *maxfeepercent = NULL, *exemptfee = NULL; |
| 3291 | |
| 3292 | if (!xpay->take_over_pay) |
| 3293 | goto dont_redirect; |
| 3294 | |
| 3295 | rpc_tok = json_get_member(buf, params, "rpc_command"); |
| 3296 | method_tok = json_get_member(buf, rpc_tok, "method"); |
| 3297 | params_tok = json_get_member(buf, rpc_tok, "params"); |
| 3298 | id_tok = json_get_member(buf, rpc_tok, "id"); |
| 3299 | |
| 3300 | if (!json_tok_streq(buf, method_tok, "pay")) |
| 3301 | goto dont_redirect; |
| 3302 | |
| 3303 | plugin_log(cmd->plugin, LOG_DBG, "Got command %s", |
| 3304 | json_strdup(tmpctx, buf, method_tok)); |
| 3305 | |
| 3306 | /* Array params? Only handle up to two args (bolt11, msat) */ |
| 3307 | if (params_tok->type == JSMN_ARRAY) { |
| 3308 | if (params_tok->size != 1 && params_tok->size != 2) { |
| 3309 | plugin_log(cmd->plugin, LOG_INFORM, |
| 3310 | "Not redirecting pay (only handle 1 or 2 args): %.*s", |
| 3311 | json_tok_full_len(params), |
| 3312 | json_tok_full(buf, params)); |
| 3313 | goto dont_redirect; |
| 3314 | } |
| 3315 | |
| 3316 | bolt11 = params_tok + 1; |
| 3317 | if (params_tok->size == 2) |
| 3318 | amount_msat = json_next(bolt11); |
| 3319 | |
| 3320 | /* some arguments could have null values in the list */ |
| 3321 | if (bolt11 && json_tok_is_null(buf, bolt11)) |
| 3322 | bolt11 = NULL; |
| 3323 | if (amount_msat && json_tok_is_null(buf, amount_msat)) |
| 3324 | amount_msat = NULL; |
| 3325 | } else if (params_tok->type == JSMN_OBJECT) { |
| 3326 | const jsmntok_t *t; |
| 3327 | size_t i; |
| 3328 | |
| 3329 | json_for_each_obj(i, t, params_tok) { |
| 3330 | if (json_tok_streq(buf, t, "bolt11")) |
| 3331 | bolt11 = t + 1; |
| 3332 | else if (json_tok_streq(buf, t, "amount_msat")) |
| 3333 | amount_msat = t + 1; |
| 3334 | else if (json_tok_streq(buf, t, "retry_for")) |
| 3335 | retry_for = t + 1; |
nothing calls this directly
no test coverage detected