channel_state: encapsulate funding of channel in one place.

This shows where funds are going at any time (fees vs to each side).
funding.c is mainly rewritten, and should be clearer now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2015-08-07 12:45:30 +09:30
parent cf3433a0ad
commit a4dfe3ad72
16 changed files with 200 additions and 150 deletions

View File

@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
struct privkey privkey;
bool testnet;
struct sha256 rhash;
u64 our_amount, their_amount;
struct channel_state *cstate;
err_set_progname(argv[0]);
@@ -68,14 +68,13 @@ int main(int argc, char *argv[])
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
errx(1, "Invalid o2 commit_key");
if (!initial_funding(o1, o2, a, commit_fee(o1, o2),
&our_amount, &their_amount))
cstate = initial_funding(ctx, o1, o2, a, commit_fee(o1, o2));
if (!cstate)
errx(1, "Invalid open combination (need 1 anchor offer)");
/* Now create our commitment tx. */
proto_to_sha256(o1->revocation_hash, &rhash);
commit = create_commit_tx(ctx, o1, o2, a, &rhash,
our_amount, their_amount);
commit = create_commit_tx(ctx, o1, o2, a, &rhash, cstate);
/* Check signature. */
subscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);