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

Function invoice_complete

lightningd/invoice.c:836–927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834}
835
836static struct command_result *
837invoice_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);

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