Skip to content

Commit

Permalink
bitcoin/tx: (optional) input amount.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed Apr 11, 2016
1 parent ed70b13 commit 58b1429
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions close_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions daemon/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 58b1429

Please sign in to comment.