Browse Source

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>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
58b14292ad
  1. 1
      bitcoin/tx.c
  2. 3
      bitcoin/tx.h
  3. 1
      close_tx.c
  4. 1
      commit_tx.c
  5. 2
      daemon/peer.c

1
bitcoin/tx.c

@ -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;

3
bitcoin/tx.h

@ -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;
};

1
close_tx.c

@ -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;

1
commit_tx.c

@ -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,

2
daemon/peer.c

@ -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…
Cancel
Save