Browse Source

Make an explicit bitcoin_txid() call.

Neater than open-coding it.  We still need the raw version for
signatures though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 10 years ago
parent
commit
393400fa39
  1. 5
      anchor.c
  2. 8
      bitcoin_tx.c
  3. 9
      bitcoin_tx.h

5
anchor.c

@ -97,7 +97,6 @@ void anchor_txid(struct bitcoin_tx *anchor,
Pkt *p1, *p2; Pkt *p1, *p2;
LeakAnchorSigsAndPretendWeDidnt *leak1, *leak2; LeakAnchorSigsAndPretendWeDidnt *leak1, *leak2;
size_t i; size_t i;
struct sha256_ctx shactx;
p1 = pkt_from_file(leakfile1, PKT__PKT_OMG_FAIL); p1 = pkt_from_file(leakfile1, PKT__PKT_OMG_FAIL);
p2 = pkt_from_file(leakfile2, PKT__PKT_OMG_FAIL); p2 = pkt_from_file(leakfile2, PKT__PKT_OMG_FAIL);
@ -121,9 +120,7 @@ void anchor_txid(struct bitcoin_tx *anchor,
= leak2->sigs->script[i].len; = leak2->sigs->script[i].len;
} }
sha256_init(&shactx); bitcoin_txid(anchor, txid);
sha256_tx(&shactx, anchor);
sha256_double_done(&shactx, txid);
pkt__free_unpacked(p1, NULL); pkt__free_unpacked(p1, NULL);
pkt__free_unpacked(p2, NULL); pkt__free_unpacked(p2, NULL);

8
bitcoin_tx.c

@ -64,6 +64,14 @@ void sha256_tx(struct sha256_ctx *ctx, const struct bitcoin_tx *tx)
sha256_le32(ctx, tx->lock_time); sha256_le32(ctx, tx->lock_time);
} }
void bitcoin_txid(const struct bitcoin_tx *tx, struct sha256_double *txid)
{
struct sha256_ctx ctx = SHA256_INIT;
sha256_tx(&ctx, tx);
sha256_double_done(&ctx, txid);
}
struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count, struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
varint_t output_count) varint_t output_count)
{ {

9
bitcoin_tx.h

@ -32,9 +32,12 @@ struct bitcoin_tx_input {
u32 sequence_number; u32 sequence_number;
}; };
/* Linearize the tx. This is good for deriving the txid, as well as the
* signature. */ /* SHA256^2 the tx: simpler than sha256_tx */
void sha256_tx(struct sha256_ctx *shactx, const struct bitcoin_tx *tx); void bitcoin_txid(const struct bitcoin_tx *tx, struct sha256_double *txid);
/* Useful for signature code. */
void sha256_tx(struct sha256_ctx *ctx, const struct bitcoin_tx *tx);
/* Allocate a tx: you just need to fill in inputs and outputs (they're /* Allocate a tx: you just need to fill in inputs and outputs (they're
* zeroed with inputs' sequence_number set to FFFFFFFF) */ * zeroed with inputs' sequence_number set to FFFFFFFF) */

Loading…
Cancel
Save