| 3559 | } |
| 3560 | |
| 3561 | static struct command_result *handle_rpc_command(struct command *cmd, |
| 3562 | const char *buf, |
| 3563 | const jsmntok_t *params) |
| 3564 | { |
| 3565 | struct xpay *xpay = xpay_of(cmd->plugin); |
| 3566 | const jsmntok_t *rpc_tok, *method_tok, *params_tok, *id_tok, |
| 3567 | *bolt11 = NULL, *amount_msat = NULL, |
| 3568 | *partial_msat = NULL, *retry_for = NULL, *maxdelay = NULL, *localinvreqid = NULL, *label = NULL; |
| 3569 | const char *maxfee = NULL; |
| 3570 | struct json_stream *response; |
| 3571 | |
| 3572 | /* pay extra params */ |
| 3573 | const jsmntok_t *maxfeepercent = NULL, *exemptfee = NULL; |
| 3574 | |
| 3575 | if (!xpay->take_over_pay) |
| 3576 | goto dont_redirect; |
| 3577 | |
| 3578 | rpc_tok = json_get_member(buf, params, "rpc_command"); |
| 3579 | method_tok = json_get_member(buf, rpc_tok, "method"); |
| 3580 | params_tok = json_get_member(buf, rpc_tok, "params"); |
| 3581 | id_tok = json_get_member(buf, rpc_tok, "id"); |
| 3582 | |
| 3583 | if (!json_tok_streq(buf, method_tok, "pay")) |
| 3584 | goto dont_redirect; |
| 3585 | |
| 3586 | plugin_log(cmd->plugin, LOG_DBG, "Got command %s", |
| 3587 | json_strdup(tmpctx, buf, method_tok)); |
| 3588 | |
| 3589 | /* Array params? Only handle up to two args (bolt11, msat) */ |
| 3590 | if (params_tok->type == JSMN_ARRAY) { |
| 3591 | if (params_tok->size != 1 && params_tok->size != 2) { |
| 3592 | plugin_log(cmd->plugin, LOG_INFORM, |
| 3593 | "Not redirecting pay (only handle 1 or 2 args): %.*s", |
| 3594 | json_tok_full_len(params), |
| 3595 | json_tok_full(buf, params)); |
| 3596 | goto dont_redirect; |
| 3597 | } |
| 3598 | |
| 3599 | bolt11 = params_tok + 1; |
| 3600 | if (params_tok->size == 2) |
| 3601 | amount_msat = json_next(bolt11); |
| 3602 | |
| 3603 | /* some arguments could have null values in the list */ |
| 3604 | if (bolt11 && json_tok_is_null(buf, bolt11)) |
| 3605 | bolt11 = NULL; |
| 3606 | if (amount_msat && json_tok_is_null(buf, amount_msat)) |
| 3607 | amount_msat = NULL; |
| 3608 | } else if (params_tok->type == JSMN_OBJECT) { |
| 3609 | const jsmntok_t *t; |
| 3610 | size_t i; |
| 3611 | |
| 3612 | json_for_each_obj(i, t, params_tok) { |
| 3613 | if (json_tok_streq(buf, t, "bolt11")) |
| 3614 | bolt11 = t + 1; |
| 3615 | else if (json_tok_streq(buf, t, "amount_msat")) |
| 3616 | amount_msat = t + 1; |
| 3617 | else if (json_tok_streq(buf, t, "retry_for")) |
| 3618 | retry_for = t + 1; |
nothing calls this directly
no test coverage detected