MCPcopy Create free account
hub / github.com/ElementsProject/lightning / invoice_complete

Function invoice_complete

lightningd/invoice.c:837–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

listincoming_doneFunction · 0.85
json_invoiceFunction · 0.85

Calls 13

json_add_sha256Function · 0.85
json_add_u64Function · 0.85
invoice_secretFunction · 0.85
json_add_secretFunction · 0.85
command_failFunction · 0.70
json_stream_successFunction · 0.70
notify_invoice_creationFunction · 0.70
command_successFunction · 0.70
invoices_find_by_rhashFunction · 0.50
invoices_createFunction · 0.50
invoices_create_fallbackFunction · 0.50
invoices_get_detailsFunction · 0.50

Tested by

no test coverage detected