mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
bitcoin/tx: (optional) input amount.
We need this for signing segwitness txs. Unfortunately, we don't have it for transactions we received as hex, only ones we created; to make this safe we use a pointer which is NULL if we don't know, and those will crash if we try to sign or check their sigs. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ed70b13041
commit
58b14292ad
5 changed files with 8 additions and 0 deletions
|
@ -226,6 +226,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
|
|||
/* We assume NULL is a zero bitmap */
|
||||
assert(tx->input[i].script == NULL);
|
||||
tx->input[i].sequence_number = 0xFFFFFFFF;
|
||||
tx->input[i].amount = NULL;
|
||||
tx->input[i].witness = NULL;
|
||||
}
|
||||
tx->lock_time = 0;
|
||||
|
|
|
@ -31,6 +31,9 @@ struct bitcoin_tx_input {
|
|||
u8 *script;
|
||||
u32 sequence_number;
|
||||
|
||||
/* Value of the output we're spending (NULL if unknown). */
|
||||
u64 *amount;
|
||||
|
||||
/* Only if BIP141 used. */
|
||||
u8 **witness;
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@ struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
|||
/* Our input spends the anchor tx output. */
|
||||
tx->input[0].txid = *anchor_txid;
|
||||
tx->input[0].index = anchor_index;
|
||||
tx->input[0].amount = tal_dup(tx->input, u64, &anchor_satoshis);
|
||||
|
||||
/* One output is to us. */
|
||||
tx->output[0].amount = to_us;
|
||||
|
|
|
@ -56,6 +56,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
|||
/* Our input spends the anchor tx output. */
|
||||
tx->input[0].txid = *anchor_txid;
|
||||
tx->input[0].index = anchor_index;
|
||||
tx->input[0].amount = tal_dup(tx->input, u64, &anchor_satoshis);
|
||||
|
||||
/* First output is a P2SH to a complex redeem script (usu. for me) */
|
||||
redeemscript = bitcoin_redeem_secret_or_delay(tx, our_final,
|
||||
|
|
|
@ -1125,6 +1125,8 @@ const struct bitcoin_tx *bitcoin_spend_ours(struct peer *peer)
|
|||
p2sh_out = find_p2sh_out(commit, redeemscript);
|
||||
tx->input[0].index = p2sh_out;
|
||||
tx->input[0].sequence_number = bitcoin_nsequence(&peer->them.locktime);
|
||||
tx->input[0].amount = tal_dup(tx->input, u64,
|
||||
&commit->output[p2sh_out].amount);
|
||||
|
||||
tx->output[0].amount = commit->output[p2sh_out].amount;
|
||||
tx->output[0].script = scriptpubkey_p2sh(tx,
|
||||
|
|
Loading…
Add table
Reference in a new issue