| 1129 | } |
| 1130 | |
| 1131 | static struct command_result * |
| 1132 | send_payment(struct lightningd *ld, |
| 1133 | struct command *cmd, |
| 1134 | const struct sha256 *rhash, |
| 1135 | u64 partid, |
| 1136 | u64 group, |
| 1137 | const struct route_hop *route, |
| 1138 | struct amount_msat msat, |
| 1139 | struct amount_msat total_msat, |
| 1140 | const char *label TAKES, |
| 1141 | const char *invstring TAKES, |
| 1142 | const char *description TAKES, |
| 1143 | const struct sha256 *local_offer_id, |
| 1144 | const struct secret *payment_secret, |
| 1145 | const u8 *payment_metadata) |
| 1146 | { |
| 1147 | unsigned int base_expiry; |
| 1148 | struct onionpacket *packet; |
| 1149 | struct secret *path_secrets; |
| 1150 | size_t i, n_hops = tal_count(route); |
| 1151 | struct node_id *ids = tal_arr(tmpctx, struct node_id, n_hops); |
| 1152 | struct short_channel_id *channels; |
| 1153 | struct sphinx_path *path; |
| 1154 | struct pubkey pubkey; |
| 1155 | bool ret; |
| 1156 | u8 *onion; |
| 1157 | |
| 1158 | /* Expiry for HTLCs is absolute. And add one to give some margin. */ |
| 1159 | base_expiry = get_block_height(ld->topology) + 1; |
| 1160 | |
| 1161 | path = sphinx_path_new(tmpctx, rhash->u.u8); |
| 1162 | /* Extract IDs for each hop: create_onionpacket wants array. */ |
| 1163 | for (i = 0; i < n_hops; i++) |
| 1164 | ids[i] = route[i].node_id; |
| 1165 | |
| 1166 | /* Create sphinx path */ |
| 1167 | for (i = 0; i < n_hops - 1; i++) { |
| 1168 | ret = pubkey_from_node_id(&pubkey, &ids[i]); |
| 1169 | assert(ret); |
| 1170 | |
| 1171 | sphinx_add_hop_has_length(path, &pubkey, |
| 1172 | take(onion_nonfinal_hop(NULL, |
| 1173 | &route[i + 1].scid, |
| 1174 | route[i + 1].amount, |
| 1175 | base_expiry + route[i + 1].delay, |
| 1176 | route[i].blinding, |
| 1177 | route[i].enctlv))); |
| 1178 | } |
| 1179 | |
| 1180 | /* And finally set the final hop to the special values in |
| 1181 | * BOLT04 */ |
| 1182 | ret = pubkey_from_node_id(&pubkey, &ids[i]); |
| 1183 | assert(ret); |
| 1184 | |
| 1185 | /* BOLT #4: |
| 1186 | * - Unless `node_announcement`, `init` message or the |
| 1187 | * [BOLT #11](11-payment-encoding.md#tagged-fields) offers feature |
| 1188 | * `var_onion_optin`: |
no test coverage detected