Find our inputs by the pubkey associated with the inputs, and * add a partial sig for each */
| 464 | /* Find our inputs by the pubkey associated with the inputs, and |
| 465 | * add a partial sig for each */ |
| 466 | static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) |
| 467 | { |
| 468 | for (size_t i = 0; i < tal_count(utxos); i++) { |
| 469 | struct utxo *utxo = utxos[i]; |
| 470 | for (size_t j = 0; j < psbt->num_inputs; j++) { |
| 471 | struct privkey privkey; |
| 472 | struct pubkey pubkey; |
| 473 | |
| 474 | if (!wally_tx_input_spends(&psbt->tx->inputs[j], |
| 475 | &utxo->outpoint)) |
| 476 | continue; |
| 477 | |
| 478 | hsm_key_for_utxo(&privkey, &pubkey, utxo); |
| 479 | |
| 480 | /* This line is basically the entire reason we have |
| 481 | * to iterate through to match the psbt input |
| 482 | * to the UTXO -- otherwise we would just |
| 483 | * call wally_psbt_sign for every utxo privkey |
| 484 | * and be done with it. We can't do that though |
| 485 | * because any UTXO that's derived from channel_info |
| 486 | * requires the HSM to find the pubkey, and we |
| 487 | * skip doing that until now as a bit of a reduction |
| 488 | * of complexity in the calling code */ |
| 489 | psbt_input_add_pubkey(psbt, j, &pubkey); |
| 490 | |
| 491 | /* It's actually a P2WSH in this case. */ |
| 492 | if (utxo->close_info && utxo->close_info->option_anchor_outputs) { |
| 493 | const u8 *wscript |
| 494 | = anchor_to_remote_redeem(tmpctx, |
| 495 | &pubkey, |
| 496 | utxo->close_info->csv); |
| 497 | psbt_input_set_witscript(psbt, j, wscript); |
| 498 | psbt_input_set_wit_utxo(psbt, j, |
| 499 | scriptpubkey_p2wsh(psbt, wscript), |
| 500 | utxo->amount); |
| 501 | } |
| 502 | tal_wally_start(); |
| 503 | if (wally_psbt_sign(psbt, privkey.secret.data, |
| 504 | sizeof(privkey.secret.data), |
| 505 | EC_FLAG_GRIND_R) != WALLY_OK) { |
| 506 | tal_wally_end(psbt); |
| 507 | hsmd_status_broken( |
| 508 | "Received wally_err attempting to " |
| 509 | "sign utxo with key %s. PSBT: %s", |
| 510 | type_to_string(tmpctx, struct pubkey, |
| 511 | &pubkey), |
| 512 | type_to_string(tmpctx, struct wally_psbt, |
| 513 | psbt)); |
| 514 | } |
| 515 | tal_wally_end(psbt); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /*~ This covers several cases where onchaind is creating a transaction which |
| 521 | * sends funds to our internal wallet. */ |
no test coverage detected