MCPcopy Create free account
hub / github.com/ElementsProject/lightning / onchaind_tx_unsigned

Function onchaind_tx_unsigned

lightningd/onchain_control.c:897–1026  ·  view source on GitHub ↗

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!"). */

Source from the content-addressed store, hash-verified

895 * (i.e. "don't wait up!").
896*/
897static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx,
898 struct channel *channel,
899 const struct onchain_signing_info *info,
900 struct amount_sat *fee,
901 bool *worthwhile)
902{
903 struct bitcoin_tx *tx;
904 struct amount_sat amt;
905 size_t weight;
906 struct pubkey final_key;
907 struct ext_key final_wallet_ext_key;
908 u64 block_target;
909 struct lightningd *ld = channel->peer->ld;
910 bool keypath_ok;
911
912 /* Use BIP86 derivation for P2TR if available, otherwise BIP32 */
913 if (ld->bip86_base) {
914 bip86_pubkey(ld, &final_key, channel->final_key_idx);
915 if (bip32_key_from_parent(ld->bip86_base,
916 channel->final_key_idx,
917 BIP32_FLAG_KEY_PUBLIC,
918 &final_wallet_ext_key) != WALLY_OK) {
919 channel_internal_error(channel,
920 "Could not derive final_wallet_ext_key (bip86) %"PRIu64,
921 channel->final_key_idx);
922 return NULL;
923 }
924 } else {
925 bip32_pubkey(ld, &final_key, channel->final_key_idx);
926 if (bip32_key_from_parent(ld->bip32_base,
927 channel->final_key_idx,
928 BIP32_FLAG_KEY_PUBLIC,
929 &final_wallet_ext_key) != WALLY_OK) {
930 channel_internal_error(channel,
931 "Could not derive final_wallet_ext_key %"PRIu64,
932 channel->final_key_idx);
933 return NULL;
934 }
935 }
936
937 tx = bitcoin_tx(ctx, chainparams, 1, 1, info->locktime);
938 bitcoin_tx_add_input(tx, &info->out, info->to_self_delay,
939 NULL, info->out_sats, NULL, info->wscript);
940
941 if (chainparams->is_elements) {
942 bitcoin_tx_add_output(
943 tx, scriptpubkey_p2wpkh(tmpctx, &final_key), NULL, info->out_sats);
944 keypath_ok = psbt_add_keypath_to_last_output(tx, channel->final_key_idx, &final_wallet_ext_key, false /* is_taproot */);
945 } else {
946 bitcoin_tx_add_output(
947 tx, scriptpubkey_p2tr(tmpctx, &final_key), NULL, info->out_sats);
948 keypath_ok = psbt_add_keypath_to_last_output(tx, channel->final_key_idx, &final_wallet_ext_key, true /* is_taproot */);
949 }
950 if (!keypath_ok) {
951 channel_internal_error(channel, "Could not add keypath?");
952 return tal_free(tx);
953 }
954 /* Worst-case sig is 73 bytes */

Callers 2

onchaind_txFunction · 0.85

Calls 15

bitcoin_tx_add_inputFunction · 0.85
bitcoin_tx_add_outputFunction · 0.85
scriptpubkey_p2wpkhFunction · 0.85
scriptpubkey_p2trFunction · 0.85
tal_freeFunction · 0.85
bitcoin_tx_weightFunction · 0.85
elements_tx_overheadFunction · 0.85
bitcoin_tx_finalizeFunction · 0.85
bip86_pubkeyFunction · 0.70
channel_internal_errorFunction · 0.70

Tested by

no test coverage detected