| 888 | } |
| 889 | |
| 890 | static struct command_result *json_getroutes(struct command *cmd, |
| 891 | const char *buffer, |
| 892 | const jsmntok_t *params) |
| 893 | { |
| 894 | /* BOLT #4: |
| 895 | * ## `max_htlc_cltv` Selection |
| 896 | * |
| 897 | * This ... value is defined as 2016 blocks, based on |
| 898 | * historical value deployed by Lightning implementations. |
| 899 | */ |
| 900 | /* FIXME: Typo in spec for CLTV in descripton! But it breaks our spelling check, so we omit it above */ |
| 901 | const u32 maxdelay_allowed = 2016; |
| 902 | struct askrene *askrene = get_askrene(cmd->plugin); |
| 903 | const u32 default_maxparts = 100; |
| 904 | struct getroutes_info *info = tal(cmd, struct getroutes_info); |
| 905 | /* param functions require pointers */ |
| 906 | struct node_id *source, *dest; |
| 907 | struct amount_msat *amount, *maxfee; |
| 908 | u32 *finalcltv, *maxdelay; |
| 909 | enum algorithm *dev_algo; |
| 910 | u32 *maxparts; |
| 911 | |
| 912 | if (!param_check(cmd, buffer, params, |
| 913 | p_req("source", param_node_id, &source), |
| 914 | p_req("destination", param_node_id, &dest), |
| 915 | p_req("amount_msat", param_msat, &amount), |
| 916 | p_req("layers", param_layer_names, &info->layers), |
| 917 | p_req("maxfee_msat", param_msat, &maxfee), |
| 918 | p_req("final_cltv", param_u32, &finalcltv), |
| 919 | p_opt_def("maxdelay", param_u32, &maxdelay, |
| 920 | maxdelay_allowed), |
| 921 | p_opt_def("maxparts", param_u32, &maxparts, |
| 922 | default_maxparts), |
| 923 | p_opt_dev("dev_algorithm", param_algorithm, |
| 924 | &dev_algo, ALGO_DEFAULT), |
| 925 | NULL)) |
| 926 | return command_param_failed(); |
| 927 | plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__, |
| 928 | json_tok_full_len(params), json_tok_full(buffer, params)); |
| 929 | |
| 930 | if (amount_msat_is_zero(*amount)) { |
| 931 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 932 | "amount must be non-zero"); |
| 933 | } |
| 934 | |
| 935 | if (maxparts == 0) { |
| 936 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 937 | "maxparts must be non-zero"); |
| 938 | } |
| 939 | |
| 940 | if (*maxdelay > maxdelay_allowed) { |
| 941 | return command_fail(cmd, PAY_USER_ERROR, |
| 942 | "maximum delay allowed is %d", |
| 943 | maxdelay_allowed); |
| 944 | } |
| 945 | |
| 946 | if (command_check_only(cmd)) |
| 947 | return command_check_done(cmd); |
nothing calls this directly
no test coverage detected