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

Function invoice_complete

lightningd/invoice.c:842–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

840}
841
842static struct command_result *
843invoice_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",

Callers 2

listincoming_doneFunction · 0.85
json_invoiceFunction · 0.85

Calls 12

invoice_secretFunction · 0.85
command_failFunction · 0.70
json_stream_successFunction · 0.70
notify_invoice_creationFunction · 0.70
command_successFunction · 0.70
wallet_invoice_createFunction · 0.50
wallet_invoice_detailsFunction · 0.50
json_add_sha256Function · 0.50
json_add_u64Function · 0.50
json_add_stringFunction · 0.50
json_add_secretFunction · 0.50

Tested by

no test coverage detected