Browse Source

close-channel: add --complete option.

Code is identical, so don't create separate close-channel-complete binary.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 10 years ago
parent
commit
c6ed5926cb
  1. 8
      close-channel.c
  2. 8
      pkt.c
  3. 8
      pkt.h

8
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 <ccan/crypto/shachain/shachain.h>
#include <ccan/short_types/short_types.h>
@ -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,
"<anchor-tx> <open-channel-file1> <open-channel-file2> <commit-privkey>\n"
"Create the signature needed for the close transaction",
@ -90,6 +93,9 @@ int main(int argc, char *argv[])
sign_tx_input(ctx, close_tx, 0, redeemscript, tal_count(redeemscript),
privkey, &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)))

8
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);
}

8
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);

Loading…
Cancel
Save