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

Function json_add_blinded_paths

plugins/offers.c:767–839  ·  view source on GitHub ↗

Returns true if valid */

Source from the content-addressed store, hash-verified

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

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