Browse Source

test-cli/update-channel-htlc-complete: new util.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 10 years ago
parent
commit
9b0ed51f2b
  1. 2
      Makefile
  2. 12
      pkt.c
  3. 10
      pkt.h
  4. 1
      test-cli/.gitignore
  5. 59
      test-cli/update-channel-htlc-complete.c

2
Makefile

@ -8,7 +8,7 @@ FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1 -DHAS_CLTV=1
# Bitcoin uses DER for signatures
#FEATURES := -DSCRIPTS_USE_DER
PROGRAMS := test-cli/open-channel test-cli/create-anchor-tx test-cli/open-commit-sig test-cli/check-commit-sig test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx test-cli/txid-of test-cli/open-anchor test-cli/update-channel-htlc
PROGRAMS := test-cli/open-channel test-cli/create-anchor-tx test-cli/open-commit-sig test-cli/check-commit-sig test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx test-cli/txid-of test-cli/open-anchor test-cli/update-channel-htlc test-cli/update-channel-htlc-complete
BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o

12
pkt.c

@ -159,6 +159,18 @@ struct pkt *update_htlc_add_pkt(const tal_t *ctx,
return to_pkt(ctx, PKT__PKT_UPDATE_ADD_HTLC, &u);
}
struct pkt *update_htlc_complete_pkt(const tal_t *ctx,
const struct sha256 *revocation_hash,
const struct sha256 *rval)
{
UpdateCompleteHtlc u = UPDATE_COMPLETE_HTLC__INIT;
u.revocation_hash = sha256_to_proto(ctx, revocation_hash);
u.r = sha256_to_proto(ctx, rval);
return to_pkt(ctx, PKT__PKT_UPDATE_COMPLETE_HTLC, &u);
}
struct pkt *update_accept_pkt(const tal_t *ctx,
struct signature *sig,
const struct sha256 *revocation_hash)

10
pkt.h

@ -104,6 +104,16 @@ struct pkt *update_htlc_add_pkt(const tal_t *ctx,
const struct sha256 *htlc_rhash,
u32 abs_locktime_seconds);
/**
* update_htlc_complete_pkt - create an update message completing a HTLC
* @ctx: tal context to allocate off.
* @revocation_hash: the revocation hash for the next commitment tx.
* @rval: the r value for the HTLC
*/
struct pkt *update_htlc_complete_pkt(const tal_t *ctx,
const struct sha256 *revocation_hash,
const struct sha256 *rval);
/**
* update_accept_pkt - create an update_accept message
* @ctx: tal context to allocate off.

1
test-cli/.gitignore

@ -18,3 +18,4 @@ open-anchor
txid-of
create-anchor-tx
update-channel-htlc
update-channel-htlc-complete

59
test-cli/update-channel-htlc-complete.c

@ -0,0 +1,59 @@
#include <ccan/crypto/shachain/shachain.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <ccan/opt/opt.h>
#include <ccan/str/hex/hex.h>
#include <ccan/err/err.h>
#include <ccan/read_write_all/read_write_all.h>
#include "lightning.pb-c.h"
#include "bitcoin/base58.h"
#include "pkt.h"
#include "bitcoin/script.h"
#include "permute_tx.h"
#include "bitcoin/signature.h"
#include "commit_tx.h"
#include "bitcoin/pubkey.h"
#include "find_p2sh_out.h"
#include <unistd.h>
int main(int argc, char *argv[])
{
const tal_t *ctx = tal_arr(NULL, char, 0);
struct sha256 seed, revocation_hash, rval;
struct pkt *pkt;
unsigned update_num;
err_set_progname(argv[0]);
opt_register_noarg("--help|-h", opt_usage_and_exit,
"<seed> <update-number> <r-value>\n"
"Create a new HTLC complete message",
"Print this message.");
opt_parse(&argc, argv, opt_log_stderr_exit);
if (argc != 4)
opt_usage_exit_fail("Expected 3 arguments");
if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]);
update_num = atoi(argv[2]);
if (!update_num)
errx(1, "Update number %s invalid", argv[2]);
if (!hex_decode(argv[3], strlen(argv[3]), &rval, sizeof(rval)))
errx(1, "Invalid rvalue '%s' - need 256 hex bits", argv[3]);
/* Get next revocation hash. */
shachain_from_seed(&seed, update_num, &revocation_hash);
sha256(&revocation_hash,
revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
pkt = update_htlc_complete_pkt(ctx, &revocation_hash, &rval);
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
err(1, "Writing out packet");
tal_free(ctx);
return 0;
}
Loading…
Cancel
Save