From 0742e5356f6c3498dda5b6ec7d1af45726e8f112 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 5 Jun 2015 11:09:29 +0930 Subject: [PATCH] get-anchor-depth: simple helper to get min_confirms from OpenChannel packet Signed-off-by: Rusty Russell --- Makefile | 2 +- get-anchor-depth.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 get-anchor-depth.c diff --git a/Makefile b/Makefile index 7ec35e38c..42749b8d0 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # Needs to have oneof support: Ubuntu vivid's is too old :( PROTOCC:=protoc-c -PROGRAMS := open-channel open-anchor-scriptsigs leak-anchor-sigs open-commit-sig check-commit-sig check-anchor-scriptsigs +PROGRAMS := open-channel open-anchor-scriptsigs leak-anchor-sigs open-commit-sig check-commit-sig check-anchor-scriptsigs get-anchor-depth HELPER_OBJS := base58.o lightning.pb-c.o shadouble.o pkt.o bitcoin_script.o permute_tx.o signature.o bitcoin_tx.o bitcoin_address.o anchor.o commit_tx.o pubkey.o diff --git a/get-anchor-depth.c b/get-anchor-depth.c new file mode 100644 index 000000000..4173eafc3 --- /dev/null +++ b/get-anchor-depth.c @@ -0,0 +1,47 @@ +/* My example: + * while [ 0$(bitcoin-cli -testnet getrawtransaction $(cat anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $(./get-anchor-depth A-open.pb) ]; do sleep 60; done + * while [ 0$(bitcoin-cli -testnet getrawtransaction $(cat anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $(./get-anchor-depth B-open.pb) ]; do sleep 60; done + */ +#include +#include +#include +#include +#include +#include +#include +#include "lightning.pb-c.h" +#include "anchor.h" +#include "base58.h" +#include "pkt.h" +#include "bitcoin_script.h" +#include "permute_tx.h" +#include "signature.h" +#include "commit_tx.h" +#include "pubkey.h" +#include +#include + +int main(int argc, char *argv[]) +{ + const tal_t *ctx = tal_arr(NULL, char, 0); + OpenChannel *o; + + err_set_progname(argv[0]); + + opt_register_noarg("--help|-h", opt_usage_and_exit, + "\n" + "Prints anchor depth as contained in OpenChannel message", + "Print this message."); + + opt_parse(&argc, argv, opt_log_stderr_exit); + + if (argc != 2) + opt_usage_exit_fail("Expected one argument"); + + o = pkt_from_file(argv[1], PKT__PKT_OPEN)->open; + printf("%u\n", o->anchor->min_confirms); + + tal_free(ctx); + return 0; +} +