mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
test-cli/extract-revocation-preimage: helper to get preimage from message
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2e36affb77
commit
402cd67e10
2
Makefile
2
Makefile
@ -8,7 +8,7 @@ FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1
|
||||
# Bitcoin uses DER for signatures
|
||||
#FEATURES := -DSCRIPTS_USE_DER
|
||||
|
||||
PROGRAMS := test-cli/open-channel 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/create-anchor-tx test-cli/open-anchor-id test-cli/open-complete test-cli/check-open-complete test-cli/open-escape-sigs test-cli/create-escape-tx test-cli/get-revocation-secret
|
||||
PROGRAMS := test-cli/open-channel 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/create-anchor-tx test-cli/open-anchor-id test-cli/open-complete test-cli/check-open-complete test-cli/open-escape-sigs test-cli/create-escape-tx test-cli/get-revocation-secret test-cli/extract-revocation-preimage
|
||||
|
||||
BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o
|
||||
|
||||
|
57
test-cli/extract-revocation-preimage.c
Normal file
57
test-cli/extract-revocation-preimage.c
Normal file
@ -0,0 +1,57 @@
|
||||
#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 "protobuf_convert.h"
|
||||
#include "pkt.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const tal_t *ctx = tal_arr(NULL, char, 0);
|
||||
struct sha256 secret;
|
||||
Pkt *pkt;
|
||||
Sha256Hash *preimage;
|
||||
char hexstr[hex_str_size(sizeof(secret))];
|
||||
|
||||
err_set_progname(argv[0]);
|
||||
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<update-sig-or-update-complete>\n"
|
||||
"Extract revocation preimage from message",
|
||||
"Print this message.");
|
||||
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
|
||||
if (argc != 2)
|
||||
opt_usage_exit_fail("Expected 1 argument");
|
||||
|
||||
pkt = any_pkt_from_file(argv[1]);
|
||||
|
||||
switch (pkt->pkt_case) {
|
||||
case PKT__PKT_UPDATE_SIGNATURE:
|
||||
preimage = pkt->update_signature->revocation_preimage;
|
||||
break;
|
||||
case PKT__PKT_UPDATE_COMPLETE:
|
||||
preimage = pkt->update_complete->revocation_preimage;
|
||||
break;
|
||||
default:
|
||||
errx(1, "Unexpected packet type %u in %s",
|
||||
pkt->pkt_case, argv[1]);
|
||||
}
|
||||
proto_to_sha256(preimage, &secret);
|
||||
|
||||
if (!hex_encode(&secret, sizeof(secret), hexstr, sizeof(hexstr)))
|
||||
abort();
|
||||
|
||||
if (!write_all(STDOUT_FILENO, hexstr, strlen(hexstr)))
|
||||
err(1, "Writing out hexstr");
|
||||
|
||||
tal_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user