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

Function json_add_blinded_paths

plugins/offers.c:769–841  ·  view source on GitHub ↗

Returns true if valid */

Source from the content-addressed store, hash-verified

767
768/* Returns true if valid */
769static bool json_add_blinded_paths(struct command *cmd,
770 struct json_stream *js,
771 const char *fieldname,
772 struct blinded_path **paths,
773 struct blinded_payinfo **blindedpay)
774{
775 json_array_start(js, fieldname);
776 for (size_t i = 0; i < tal_count(paths); i++) {
777 json_object_start(js, NULL);
778 if (paths[i]->first_node_id.is_pubkey) {
779 json_add_pubkey(js, "first_node_id",
780 &paths[i]->first_node_id.pubkey);
781 } else {
782 json_add_short_channel_id(js, "first_scid",
783 paths[i]->first_node_id.scidd.scid);
784 json_add_u32(js, "first_scid_dir",
785 paths[i]->first_node_id.scidd.dir);
786 }
787
788 json_add_pubkey(js, "first_path_key", &paths[i]->first_path_key);
789
790 /* Don't crash if we're short a payinfo! */
791 if (i < tal_count(blindedpay)) {
792 json_object_start(js, "payinfo");
793 json_add_amount_msat(js, "fee_base_msat",
794 amount_msat(blindedpay[i]->fee_base_msat));
795 json_add_u32(js, "fee_proportional_millionths",
796 blindedpay[i]->fee_proportional_millionths);
797 json_add_u32(js, "cltv_expiry_delta",
798 blindedpay[i]->cltv_expiry_delta);
799 json_add_amount_msat(js, "htlc_minimum_msat",
800 blindedpay[i]->htlc_minimum_msat);
801 json_add_amount_msat(js, "htlc_maximum_msat",
802 blindedpay[i]->htlc_maximum_msat);
803 json_add_hex_talarr(js, "features", blindedpay[i]->features);
804 json_object_end(js);
805 }
806
807 json_array_start(js, "path");
808 for (size_t j = 0; j < tal_count(paths[i]->path); j++) {
809 json_add_onionmsg_path(js, NULL, paths[i]->path[j]);
810 }
811 json_array_end(js);
812 json_object_end(js);
813 }
814 json_array_end(js);
815
816 /* BOLT #12:
817 * - MUST reject the invoice if `invoice_blindedpay` does not contain
818 * exactly one `blinded_payinfo` per `invoice_paths`.`blinded_path`.
819 */
820 if (blindedpay && tal_count(blindedpay) != tal_count(paths)) {
821 json_add_str_fmt(js, "warning_invalid_invoice_blindedpay",
822 "invoice has %zu blinded_payinfo but %zu paths",
823 tal_count(blindedpay), tal_count(paths));
824 return false;
825 }
826

Callers 4

json_add_offer_fieldsFunction · 0.85
json_add_invreq_fieldsFunction · 0.85
json_add_invoice_fieldsFunction · 0.85
json_add_payer_proofFunction · 0.85

Calls 12

json_array_startFunction · 0.85
json_object_startFunction · 0.85
json_add_pubkeyFunction · 0.85
json_add_u32Function · 0.85
json_add_amount_msatFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_object_endFunction · 0.85
json_add_onionmsg_pathFunction · 0.85
json_array_endFunction · 0.85
json_add_str_fmtFunction · 0.85
amount_msatClass · 0.70

Tested by

no test coverage detected