devtools/rune: simple decode tool.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-07-16 22:48:27 +09:30
parent 0d94530f13
commit cf4374c4ed
2 changed files with 84 additions and 1 deletions

View File

@ -1,4 +1,4 @@
DEVTOOLS := devtools/bolt11-cli devtools/decodemsg devtools/onion devtools/dump-gossipstore devtools/gossipwith devtools/create-gossipstore devtools/mkcommit devtools/mkfunding devtools/mkclose devtools/mkgossip devtools/mkencoded devtools/mkquery devtools/lightning-checkmessage devtools/topology devtools/route devtools/bolt12-cli devtools/encodeaddr devtools/features devtools/fp16
DEVTOOLS := devtools/bolt11-cli devtools/decodemsg devtools/onion devtools/dump-gossipstore devtools/gossipwith devtools/create-gossipstore devtools/mkcommit devtools/mkfunding devtools/mkclose devtools/mkgossip devtools/mkencoded devtools/mkquery devtools/lightning-checkmessage devtools/topology devtools/route devtools/bolt12-cli devtools/encodeaddr devtools/features devtools/fp16 devtools/rune
ifeq ($(HAVE_SQLITE3),1)
DEVTOOLS += devtools/checkchannels
endif
@ -48,6 +48,8 @@ DEVTOOLS_COMMON_OBJS := \
devtools/features: common/features.o common/utils.o wire/fromwire.o wire/towire.o devtools/features.o
devtools/rune: common/utils.o common/autodata.o common/setup.o common/version.o wire/fromwire.o wire/towire.o devtools/rune.o
devtools/fp16: common/fp16.o common/utils.o common/setup.o common/autodata.o devtools/fp16.o
devtools/bolt11-cli: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o devtools/bolt11-cli.o

81
devtools/rune.c Normal file
View File

@ -0,0 +1,81 @@
/* Decodes a rune. */
#include "config.h"
#include <ccan/err/err.h>
#include <ccan/opt/opt.h>
#include <ccan/rune/rune.h>
#include <common/configdir.h>
#include <common/setup.h>
#include <common/utils.h>
#include <common/version.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct rune *rune;
common_setup(argv[0]);
opt_register_noarg("--help|-h", opt_usage_and_exit,
"<rune>", "Show this message");
opt_register_version();
opt_early_parse(argc, argv, opt_log_stderr_exit);
opt_parse(&argc, argv, opt_log_stderr_exit);
if (argc != 2)
opt_usage_exit_fail("needs rune");
rune = rune_from_base64(NULL, argv[1]);
if (!rune)
opt_usage_exit_fail("invalid rune");
printf("string encoding: %s\n", rune_to_string(rune, rune));
for (size_t i = 0; i < tal_count(rune->restrs); i++) {
const struct rune_restr *restr = rune->restrs[i];
const char *sep = "- ";
for (size_t j = 0; j < tal_count(restr->alterns); j++) {
const struct rune_altern *alt = restr->alterns[j];
if (streq(alt->fieldname, "")) {
printf("Unique id is %s", alt->value);
} else {
printf("%s", sep);
switch (alt->condition) {
case RUNE_COND_IF_MISSING:
printf("%s is missing", alt->fieldname);
break;
case RUNE_COND_EQUAL:
printf("%s equal to %s", alt->fieldname, alt->value);
break;
case RUNE_COND_NOT_EQUAL:
printf("%s unequal to %s", alt->fieldname, alt->value);
break;
case RUNE_COND_BEGINS:
printf("%s starts with %s", alt->fieldname, alt->value);
break;
case RUNE_COND_ENDS:
printf("%s ends with %s", alt->fieldname, alt->value);
break;
case RUNE_COND_CONTAINS:
printf("%s contains %s", alt->fieldname, alt->value);
break;
case RUNE_COND_INT_LESS:
printf("%s < %s", alt->fieldname, alt->value);
break;
case RUNE_COND_INT_GREATER:
printf("%s > %s", alt->fieldname, alt->value);
break;
case RUNE_COND_LEXO_BEFORE:
printf("%s sorts before %s", alt->fieldname, alt->value);
break;
case RUNE_COND_LEXO_AFTER:
printf("%s sorts after %s", alt->fieldname, alt->value);
break;
case RUNE_COND_COMMENT:
printf("comment: %s%s", alt->fieldname, alt->value);
break;
}
sep = " OR ";
}
}
printf("\n");
}
common_shutdown();
}