create_commit_tx: don't use protobufs in the API.

Hand anchor details and pubkeys directly; this is what we want
for the actual daemon which doesn't keep raw packets around.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-01-22 06:41:47 +10:30
parent 65cc6bbd50
commit d95d8a99c2
11 changed files with 74 additions and 40 deletions

View File

@@ -1,7 +1,9 @@
#include "bitcoin/address.h"
#include "bitcoin/locktime.h"
#include "bitcoin/pubkey.h"
#include "bitcoin/signature.h"
#include "bitcoin/tx.h"
#include "commit_tx.h"
#include "pkt.h"
#include "protobuf_convert.h"
#include <ccan/crypto/sha256/sha256.h>
@@ -224,3 +226,28 @@ struct pkt *update_complete_pkt(const tal_t *ctx,
uc.revocation_preimage = sha256_to_proto(ctx, revocation_preimage);
return to_pkt(ctx, PKT__PKT_UPDATE_COMPLETE, &uc);
}
struct bitcoin_tx *commit_tx_from_pkts(const tal_t *ctx,
OpenChannel *ours,
OpenChannel *theirs,
OpenAnchor *anchor,
const struct sha256 *rhash,
const struct channel_state *cstate)
{
struct pubkey ourkey, theirkey;
struct sha256_double txid;
struct rel_locktime locktime;
proto_to_sha256(anchor->txid, &txid.sha);
/* Output goes to our final pubkeys */
if (!proto_to_pubkey(ours->final_key, &ourkey))
return NULL;
if (!proto_to_pubkey(theirs->final_key, &theirkey))
return NULL;
if (!proto_to_rel_locktime(theirs->delay, &locktime))
return NULL;
return create_commit_tx(ctx, &ourkey, &theirkey, &locktime,
&txid, anchor->output_index, anchor->amount,
rhash, cstate);
}