| 1411 | } |
| 1412 | |
| 1413 | static struct command_result *json_sendpay(struct command *cmd, |
| 1414 | const char *buffer, |
| 1415 | const jsmntok_t *obj UNNEEDED, |
| 1416 | const jsmntok_t *params) |
| 1417 | { |
| 1418 | struct sha256 *rhash; |
| 1419 | struct route_hop *route; |
| 1420 | struct amount_msat *msat; |
| 1421 | const char *invstring, *label, *description; |
| 1422 | u64 *partid, *group; |
| 1423 | struct secret *payment_secret; |
| 1424 | struct sha256 *local_offer_id; |
| 1425 | u8 *payment_metadata; |
| 1426 | |
| 1427 | /* For generating help, give new-style. */ |
| 1428 | if (!param(cmd, buffer, params, |
| 1429 | p_req("route", param_route_hops, &route), |
| 1430 | p_req("payment_hash", param_sha256, &rhash), |
| 1431 | p_opt("label", param_escaped_string, &label), |
| 1432 | p_opt("amount_msat|msatoshi", param_msat, &msat), |
| 1433 | /* FIXME: parameter should be invstring now */ |
| 1434 | p_opt("bolt11", param_string, &invstring), |
| 1435 | p_opt("payment_secret", param_secret, &payment_secret), |
| 1436 | p_opt_def("partid", param_u64, &partid, 0), |
| 1437 | p_opt("localofferid", param_sha256, &local_offer_id), |
| 1438 | p_opt("groupid", param_u64, &group), |
| 1439 | p_opt("payment_metadata", param_bin_from_hex, &payment_metadata), |
| 1440 | p_opt("description", param_string, &description), |
| 1441 | NULL)) |
| 1442 | return command_param_failed(); |
| 1443 | |
| 1444 | if (*partid && !msat) |
| 1445 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1446 | "Must specify msatoshi with partid"); |
| 1447 | |
| 1448 | const struct amount_msat final_amount = route[tal_count(route)-1].amount; |
| 1449 | |
| 1450 | /* If groupid was not provided default to incrementing from the previous one. */ |
| 1451 | if (group == NULL) { |
| 1452 | group = tal(tmpctx, u64); |
| 1453 | *group = wallet_payment_get_groupid(cmd->ld->wallet, rhash) + 1; |
| 1454 | } |
| 1455 | |
| 1456 | if (msat && !*partid && !amount_msat_eq(*msat, final_amount)) |
| 1457 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1458 | "Do not specify msatoshi (%s) without" |
| 1459 | " partid: if you do, it must be exactly" |
| 1460 | " the final amount (%s)", |
| 1461 | type_to_string(tmpctx, struct amount_msat, |
| 1462 | msat), |
| 1463 | type_to_string(tmpctx, struct amount_msat, |
| 1464 | &final_amount)); |
| 1465 | |
| 1466 | /* For MPP, the total we send must *exactly* equal the amount |
| 1467 | * we promise to send (msatoshi). So no single payment can be |
| 1468 | * > than that. */ |
| 1469 | if (*partid) { |
| 1470 | if (amount_msat_greater(final_amount, *msat)) |
nothing calls this directly
no test coverage detected