| 834 | } |
| 835 | |
| 836 | static struct command_result * |
| 837 | invoice_complete(struct invoice_info *info, |
| 838 | bool warning_no_listincoming, |
| 839 | bool warning_mpp, |
| 840 | bool warning_capacity, |
| 841 | bool warning_deadends, |
| 842 | bool warning_offline, |
| 843 | bool warning_private_unused) |
| 844 | { |
| 845 | struct json_stream *response; |
| 846 | u64 inv_dbid; |
| 847 | char *b11enc; |
| 848 | const struct invoice_details *details; |
| 849 | struct secret payment_secret; |
| 850 | struct wallet *wallet = info->cmd->ld->wallet; |
| 851 | |
| 852 | b11enc = bolt11_encode(info, info->b11, false, |
| 853 | hsm_sign_b11, info->cmd->ld); |
| 854 | |
| 855 | /* Check duplicate preimage (unlikely unless they specified it!) */ |
| 856 | if (invoices_find_by_rhash(wallet->invoices, |
| 857 | &inv_dbid, &info->b11->payment_hash)) { |
| 858 | return command_fail(info->cmd, |
| 859 | INVOICE_PREIMAGE_ALREADY_EXISTS, |
| 860 | "preimage already used"); |
| 861 | } |
| 862 | |
| 863 | if (!invoices_create(wallet->invoices, |
| 864 | &inv_dbid, |
| 865 | info->b11->msat, |
| 866 | info->label, |
| 867 | info->b11->expiry, |
| 868 | b11enc, |
| 869 | info->b11->description, |
| 870 | info->b11->features, |
| 871 | &info->payment_preimage, |
| 872 | &info->b11->payment_hash, |
| 873 | NULL)) { |
| 874 | return command_fail(info->cmd, INVOICE_LABEL_ALREADY_EXISTS, |
| 875 | "Duplicate label '%s'", |
| 876 | info->label->s); |
| 877 | } |
| 878 | |
| 879 | if (info->cmd->ld->unified_invoices && info->b11->fallbacks && !info->custom_fallbacks) { |
| 880 | for (size_t i = 0; i < tal_count(info->b11->fallbacks); i++) { |
| 881 | const u8 *fallback_script = info->b11->fallbacks[i]; |
| 882 | invoices_create_fallback(wallet->invoices, inv_dbid, fallback_script); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | /* Get details */ |
| 887 | details = invoices_get_details(info, wallet->invoices, inv_dbid); |
| 888 | |
| 889 | response = json_stream_success(info->cmd); |
| 890 | json_add_sha256(response, "payment_hash", &details->rhash); |
| 891 | json_add_u64(response, "expires_at", details->expiry_time); |
| 892 | json_add_string(response, "bolt11", details->invstring); |
| 893 | invoice_secret(&details->r, &payment_secret); |
no test coverage detected