Make normal 1-input-1-output tx to us, but don't sign it yet. * * If worthwhile is not NULL, we set it to true normally, or false if * we had to lower fees so much it's unlikely to get mined * (i.e. "don't wait up!"). */
| 982 | * (i.e. "don't wait up!"). |
| 983 | */ |
| 984 | static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx, |
| 985 | struct channel *channel, |
| 986 | const struct onchain_signing_info *info, |
| 987 | struct amount_sat *fee, |
| 988 | bool *worthwhile) |
| 989 | { |
| 990 | struct bitcoin_tx *tx; |
| 991 | struct amount_sat amt; |
| 992 | size_t weight; |
| 993 | struct pubkey final_key; |
| 994 | struct ext_key final_wallet_ext_key; |
| 995 | u64 block_target; |
| 996 | struct lightningd *ld = channel->peer->ld; |
| 997 | bool keypath_ok; |
| 998 | |
| 999 | /* Use BIP86 derivation for P2TR if available, otherwise BIP32 */ |
| 1000 | if (ld->bip86_base) { |
| 1001 | bip86_pubkey(ld, &final_key, channel->final_key_idx); |
| 1002 | if (bip32_key_from_parent(ld->bip86_base, |
| 1003 | channel->final_key_idx, |
| 1004 | BIP32_FLAG_KEY_PUBLIC, |
| 1005 | &final_wallet_ext_key) != WALLY_OK) { |
| 1006 | channel_internal_error(channel, |
| 1007 | "Could not derive final_wallet_ext_key (bip86) %"PRIu64, |
| 1008 | channel->final_key_idx); |
| 1009 | return NULL; |
| 1010 | } |
| 1011 | } else { |
| 1012 | bip32_pubkey(ld, &final_key, channel->final_key_idx); |
| 1013 | if (bip32_key_from_parent(ld->bip32_base, |
| 1014 | channel->final_key_idx, |
| 1015 | BIP32_FLAG_KEY_PUBLIC, |
| 1016 | &final_wallet_ext_key) != WALLY_OK) { |
| 1017 | channel_internal_error(channel, |
| 1018 | "Could not derive final_wallet_ext_key %"PRIu64, |
| 1019 | channel->final_key_idx); |
| 1020 | return NULL; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | tx = bitcoin_tx(ctx, chainparams, 1, 1, info->locktime); |
| 1025 | bitcoin_tx_add_input(tx, &info->out, info->to_self_delay, |
| 1026 | NULL, info->out_sats, NULL, info->wscript); |
| 1027 | |
| 1028 | if (chainparams->is_elements) { |
| 1029 | bitcoin_tx_add_output( |
| 1030 | tx, scriptpubkey_p2wpkh(tmpctx, &final_key), NULL, info->out_sats); |
| 1031 | keypath_ok = psbt_add_keypath_to_last_output(tx, channel->final_key_idx, &final_wallet_ext_key, false /* is_taproot */); |
| 1032 | } else { |
| 1033 | bitcoin_tx_add_output( |
| 1034 | tx, scriptpubkey_p2tr(tmpctx, &final_key), NULL, info->out_sats); |
| 1035 | keypath_ok = psbt_add_keypath_to_last_output(tx, channel->final_key_idx, &final_wallet_ext_key, true /* is_taproot */); |
| 1036 | } |
| 1037 | if (!keypath_ok) { |
| 1038 | channel_internal_error(channel, "Could not add keypath?"); |
| 1039 | return tal_free(tx); |
| 1040 | } |
| 1041 | /* Worst-case sig is 73 bytes */ |
no test coverage detected