Use pubkey structures in bitcoin_script, rather than protobufs.

This ensures we do checking beforehand, and keeps abstractions clear.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2015-06-02 13:33:21 +09:30
parent bd38003db6
commit f911b2b6df
4 changed files with 50 additions and 42 deletions

View File

@@ -3,6 +3,7 @@
#include "bitcoin_tx.h"
#include "bitcoin_script.h"
#include "permute_tx.h"
#include "pubkey.h"
struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
OpenChannel *ours,
@@ -12,6 +13,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
{
struct bitcoin_tx *tx;
const u8 *redeemscript;
struct pubkey ourkey, theirkey;
/* Now create commitment tx: one input, two outputs. */
tx = bitcoin_tx(ctx, 1, 2);
@@ -20,10 +22,15 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
tx->input[0].txid = *anchor_txid;
tx->input[0].index = anchor_output;
if (!proto_to_pubkey(ours->anchor->pubkey, &ourkey))
return tal_free(tx);
if (!proto_to_pubkey(theirs->anchor->pubkey, &theirkey))
return tal_free(tx);
/* First output is a P2SH to a complex redeem script (usu. for me) */
redeemscript = bitcoin_redeem_revocable(tx, ours->anchor->pubkey,
redeemscript = bitcoin_redeem_revocable(tx, &ourkey,
ours->locktime_seconds,
theirs->anchor->pubkey,
&theirkey,
ours->revocation_hash);
tx->output[0].script = scriptpubkey_p2sh(tx, redeemscript);
tx->output[0].script_length = tal_count(tx->output[0].script);