| 840 | } |
| 841 | |
| 842 | static struct command_result * |
| 843 | invoice_complete(struct invoice_info *info, |
| 844 | bool warning_no_listincoming, |
| 845 | bool warning_mpp, |
| 846 | bool warning_capacity, |
| 847 | bool warning_deadends, |
| 848 | bool warning_offline, |
| 849 | bool warning_private_unused) |
| 850 | { |
| 851 | struct json_stream *response; |
| 852 | struct invoice invoice; |
| 853 | char *b11enc; |
| 854 | const struct invoice_details *details; |
| 855 | struct secret payment_secret; |
| 856 | struct wallet *wallet = info->cmd->ld->wallet; |
| 857 | |
| 858 | b11enc = bolt11_encode(info, info->b11, false, |
| 859 | hsm_sign_b11, info->cmd->ld); |
| 860 | |
| 861 | /* Check duplicate preimage (unlikely unless they specified it!) */ |
| 862 | if (wallet_invoice_find_by_rhash(wallet, |
| 863 | &invoice, &info->b11->payment_hash)) { |
| 864 | return command_fail(info->cmd, |
| 865 | INVOICE_PREIMAGE_ALREADY_EXISTS, |
| 866 | "preimage already used"); |
| 867 | } |
| 868 | |
| 869 | if (!wallet_invoice_create(wallet, |
| 870 | &invoice, |
| 871 | info->b11->msat, |
| 872 | info->label, |
| 873 | info->b11->expiry, |
| 874 | b11enc, |
| 875 | info->b11->description, |
| 876 | info->b11->features, |
| 877 | &info->payment_preimage, |
| 878 | &info->b11->payment_hash, |
| 879 | NULL)) { |
| 880 | return command_fail(info->cmd, INVOICE_LABEL_ALREADY_EXISTS, |
| 881 | "Duplicate label '%s'", |
| 882 | info->label->s); |
| 883 | } |
| 884 | |
| 885 | /* Get details */ |
| 886 | details = wallet_invoice_details(info, wallet, invoice); |
| 887 | |
| 888 | response = json_stream_success(info->cmd); |
| 889 | json_add_sha256(response, "payment_hash", &details->rhash); |
| 890 | json_add_u64(response, "expires_at", details->expiry_time); |
| 891 | json_add_string(response, "bolt11", details->invstring); |
| 892 | invoice_secret(&details->r, &payment_secret); |
| 893 | json_add_secret(response, "payment_secret", &payment_secret); |
| 894 | |
| 895 | notify_invoice_creation(info->cmd->ld, info->b11->msat, |
| 896 | info->payment_preimage, info->label); |
| 897 | |
| 898 | if (warning_no_listincoming) |
| 899 | json_add_string(response, "warning_listincoming", |
no test coverage detected