diff --git a/close-channel.c b/close-channel.c index de488f7a8..877007999 100644 --- a/close-channel.c +++ b/close-channel.c @@ -1,5 +1,6 @@ /* My example: * ./close-channel A-anchor.tx A-open.pb B-open.pb cUBCjrdJu8tfvM7FT8So6aqs6G6bZS1Cax6Rc9rFzYL6nYG4XNEC > A-close.pb + * ./close-channel --complete A-anchor.tx B-open.pb A-open.pb cQXhbUnNRsFcdzTQwjbCrud5yVskHTEas7tZPUWoJYNk5htGQrpi > B-close-complete.pb */ #include #include @@ -29,7 +30,7 @@ int main(int argc, char *argv[]) struct pkt *pkt; struct signature sig; EC_KEY *privkey; - bool testnet; + bool testnet, complete = false; struct pubkey pubkey1, pubkey2; u8 *redeemscript, *p2sh; size_t i; @@ -37,6 +38,8 @@ int main(int argc, char *argv[]) err_set_progname(argv[0]); /* FIXME: Take update.pbs to adjust channel */ + opt_register_noarg("--complete", opt_set_bool, &complete, + "Create a close_transaction_complete msg instead"); opt_register_noarg("--help|-h", opt_usage_and_exit, " \n" "Create the signature needed for the close transaction", @@ -90,7 +93,10 @@ int main(int argc, char *argv[]) sign_tx_input(ctx, close_tx, 0, redeemscript, tal_count(redeemscript), privkey, &sig); - pkt = close_channel_pkt(ctx, &sig); + if (complete) + pkt = close_channel_complete_pkt(ctx, &sig); + else + pkt = close_channel_pkt(ctx, &sig); if (!write_all(STDOUT_FILENO, pkt, sizeof(pkt->len) + le32_to_cpu(pkt->len))) err(1, "Writing out packet"); diff --git a/pkt.c b/pkt.c index 3d5af43f9..023917d10 100644 --- a/pkt.c +++ b/pkt.c @@ -144,3 +144,11 @@ struct pkt *close_channel_pkt(const tal_t *ctx, const struct signature *sig) c.sig = signature_to_proto(ctx, sig); return to_pkt(ctx, PKT__PKT_CLOSE, &c); } + +struct pkt *close_channel_complete_pkt(const tal_t *ctx, + const struct signature *sig) +{ + CloseChannelComplete c = CLOSE_CHANNEL_COMPLETE__INIT; + c.sig = signature_to_proto(ctx, sig); + return to_pkt(ctx, PKT__PKT_CLOSE_COMPLETE, &c); +} diff --git a/pkt.h b/pkt.h index 726fa82ea..433f93949 100644 --- a/pkt.h +++ b/pkt.h @@ -73,6 +73,14 @@ struct pkt *open_commit_sig_pkt(const tal_t *ctx, const struct signature *sig); */ struct pkt *close_channel_pkt(const tal_t *ctx, const struct signature *sig); +/** + * close_channel_complete_pkt - create an close_channel_complete message + * @ctx: tal context to allocate off. + * @sig: the signature for the close transaction input. + */ +struct pkt *close_channel_complete_pkt(const tal_t *ctx, + const struct signature *sig); + /* Useful helper for allocating & populating a protobuf Sha256Hash */ Sha256Hash *sha256_to_proto(const tal_t *ctx, const struct sha256 *hash); void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash);