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!"). */
| 872 | * (i.e. "don't wait up!"). |
| 873 | */ |
| 874 | static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx, |
| 875 | struct channel *channel, |
| 876 | const struct onchain_signing_info *info, |
| 877 | struct amount_sat *fee, |
| 878 | bool *worthwhile) |
| 879 | { |
| 880 | struct bitcoin_tx *tx; |
| 881 | struct amount_sat amt; |
| 882 | size_t weight; |
| 883 | struct pubkey final_key; |
| 884 | struct ext_key final_wallet_ext_key; |
| 885 | u64 block_target; |
| 886 | struct lightningd *ld = channel->peer->ld; |
| 887 | bool keypath_ok; |
| 888 | |
| 889 | /* Use BIP86 derivation for P2TR if available, otherwise BIP32 */ |
| 890 | if (ld->bip86_base) { |
| 891 | bip86_pubkey(ld, &final_key, channel->final_key_idx); |
| 892 | if (bip32_key_from_parent(ld->bip86_base, |
| 893 | channel->final_key_idx, |
| 894 | BIP32_FLAG_KEY_PUBLIC, |
| 895 | &final_wallet_ext_key) != WALLY_OK) { |
| 896 | channel_internal_error(channel, |
| 897 | "Could not derive final_wallet_ext_key (bip86) %"PRIu64, |
| 898 | channel->final_key_idx); |
| 899 | return NULL; |
| 900 | } |
| 901 | } else { |
| 902 | bip32_pubkey(ld, &final_key, channel->final_key_idx); |
| 903 | if (bip32_key_from_parent(ld->bip32_base, |
| 904 | channel->final_key_idx, |
| 905 | BIP32_FLAG_KEY_PUBLIC, |
| 906 | &final_wallet_ext_key) != WALLY_OK) { |
| 907 | channel_internal_error(channel, |
| 908 | "Could not derive final_wallet_ext_key %"PRIu64, |
| 909 | channel->final_key_idx); |
| 910 | return NULL; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | tx = bitcoin_tx(ctx, chainparams, 1, 1, info->locktime); |
| 915 | bitcoin_tx_add_input(tx, &info->out, info->to_self_delay, |
| 916 | NULL, info->out_sats, NULL, info->wscript); |
| 917 | |
| 918 | if (chainparams->is_elements) { |
| 919 | bitcoin_tx_add_output( |
| 920 | tx, scriptpubkey_p2wpkh(tmpctx, &final_key), NULL, info->out_sats); |
| 921 | keypath_ok = psbt_add_keypath_to_last_output(tx, channel->final_key_idx, &final_wallet_ext_key, false /* is_taproot */); |
| 922 | } else { |
| 923 | bitcoin_tx_add_output( |
| 924 | tx, scriptpubkey_p2tr(tmpctx, &final_key), NULL, info->out_sats); |
| 925 | keypath_ok = psbt_add_keypath_to_last_output(tx, channel->final_key_idx, &final_wallet_ext_key, true /* is_taproot */); |
| 926 | } |
| 927 | if (!keypath_ok) { |
| 928 | channel_internal_error(channel, "Could not add keypath?"); |
| 929 | return tal_free(tx); |
| 930 | } |
| 931 | /* Worst-case sig is 73 bytes */ |
no test coverage detected