| 1187 | } |
| 1188 | |
| 1189 | static struct command_result *json_sendpsbt(struct command *cmd, |
| 1190 | const char *buffer, |
| 1191 | const jsmntok_t *obj, |
| 1192 | const jsmntok_t *params) |
| 1193 | { |
| 1194 | struct command_result *res; |
| 1195 | struct sending_psbt *sending; |
| 1196 | struct wally_psbt *psbt; |
| 1197 | struct lightningd *ld = cmd->ld; |
| 1198 | u32 *reserve_blocks; |
| 1199 | struct peer *p; |
| 1200 | struct peer_node_id_map_iter it; |
| 1201 | |
| 1202 | if (!param_check(cmd, buffer, params, |
| 1203 | p_req("psbt", param_psbt, &psbt), |
| 1204 | p_opt_def("reserve", param_number, &reserve_blocks, 12 * 6), |
| 1205 | NULL)) |
| 1206 | return command_param_failed(); |
| 1207 | |
| 1208 | sending = tal(cmd, struct sending_psbt); |
| 1209 | sending->cmd = cmd; |
| 1210 | sending->reserve_blocks = *reserve_blocks; |
| 1211 | |
| 1212 | psbt_finalize(psbt); |
| 1213 | sending->wtx = psbt_final_tx(sending, psbt); |
| 1214 | |
| 1215 | /* psbt contains info about which outputs are to external, |
| 1216 | * and thus need a coin_move issued for them. We only |
| 1217 | * notify if the transaction broadcasts */ |
| 1218 | sending->psbt = tal_steal(sending, psbt); |
| 1219 | |
| 1220 | if (!sending->wtx) |
| 1221 | return command_fail(cmd, LIGHTNINGD, |
| 1222 | "PSBT not finalizeable %s", |
| 1223 | fmt_wally_psbt(tmpctx, psbt)); |
| 1224 | |
| 1225 | /* We have to find/locate the utxos that are ours on this PSBT, |
| 1226 | * so that we know who to mark as used. |
| 1227 | */ |
| 1228 | res = match_psbt_inputs_to_utxos(cmd, psbt, NULL, &sending->utxos); |
| 1229 | if (res) |
| 1230 | return res; |
| 1231 | |
| 1232 | if (command_check_only(cmd)) |
| 1233 | return command_check_done(cmd); |
| 1234 | |
| 1235 | /* If this corresponds to one or more channels' PSBT, upgrade |
| 1236 | * those to signed versions! */ |
| 1237 | for (p = peer_node_id_map_first(ld->peers, &it); |
| 1238 | p; |
| 1239 | p = peer_node_id_map_next(ld->peers, &it)) { |
| 1240 | struct channel *c; |
| 1241 | |
| 1242 | list_for_each(&p->channels, c, list) { |
| 1243 | bool was_withheld; |
| 1244 | |
| 1245 | if (!c->funding_psbt) |
| 1246 | continue; |
nothing calls this directly
no test coverage detected