| 2817 | }; |
| 2818 | |
| 2819 | static void validate_input_unspent(struct bitcoind *bitcoind, |
| 2820 | const struct bitcoin_tx_output *txout, |
| 2821 | void *arg) |
| 2822 | { |
| 2823 | struct psbt_validator *pv = arg; |
| 2824 | char *err; |
| 2825 | |
| 2826 | /* First time thru bitcoind will be NULL, otherwise is response */ |
| 2827 | if (bitcoind && !txout) { |
| 2828 | struct bitcoin_outpoint outpoint; |
| 2829 | |
| 2830 | assert(pv->next_index > 0); |
| 2831 | wally_psbt_input_get_outpoint(&pv->psbt->inputs[pv->next_index - 1], |
| 2832 | &outpoint); |
| 2833 | |
| 2834 | err = tal_fmt(pv, "Requested only confirmed" |
| 2835 | " inputs for this open." |
| 2836 | " Input %s is not confirmed.", |
| 2837 | fmt_bitcoin_outpoint(tmpctx, &outpoint)); |
| 2838 | pv->invalid_input(pv, err); |
| 2839 | return; |
| 2840 | } |
| 2841 | |
| 2842 | for (size_t i = pv->next_index; i < pv->psbt->num_inputs; i++) { |
| 2843 | struct bitcoin_outpoint outpoint; |
| 2844 | u64 serial; |
| 2845 | |
| 2846 | if (!psbt_get_serial_id(&pv->psbt->inputs[i].unknowns, &serial)) { |
| 2847 | err = tal_fmt(pv, "PSBT input at index %zu" |
| 2848 | " missing serial id", i); |
| 2849 | pv->invalid_input(pv, err); |
| 2850 | return; |
| 2851 | } |
| 2852 | /* Ignore any input that's not what we're looking for */ |
| 2853 | if (serial % 2 != pv->role_to_validate) |
| 2854 | continue; |
| 2855 | |
| 2856 | wally_psbt_input_get_outpoint(&pv->psbt->inputs[i], |
| 2857 | &outpoint); |
| 2858 | pv->next_index = i + 1; |
| 2859 | |
| 2860 | /* Confirm input is in a block */ |
| 2861 | bitcoind_getutxout(pv, pv->channel->owner->ld->topology->bitcoind, |
| 2862 | &outpoint, |
| 2863 | validate_input_unspent, |
| 2864 | pv); |
| 2865 | return; |
| 2866 | } |
| 2867 | |
| 2868 | pv->success(pv); |
| 2869 | } |
| 2870 | |
| 2871 | static void openchannel_update_valid_psbt(struct psbt_validator *pv) |
| 2872 | { |
no test coverage detected