mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
utils: tal_hexstr() helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6f2cb72c27
commit
9eabab78ab
2
Makefile
2
Makefile
@ -45,6 +45,7 @@ CORE_SRC := \
|
|||||||
permute_tx.c \
|
permute_tx.c \
|
||||||
protobuf_convert.c \
|
protobuf_convert.c \
|
||||||
remove_dust.c \
|
remove_dust.c \
|
||||||
|
utils.c \
|
||||||
version.c
|
version.c
|
||||||
CORE_OBJS := $(CORE_SRC:.c=.o)
|
CORE_OBJS := $(CORE_SRC:.c=.o)
|
||||||
|
|
||||||
@ -156,6 +157,7 @@ CORE_HEADERS := close_tx.h \
|
|||||||
remove_dust.h \
|
remove_dust.h \
|
||||||
state.h \
|
state.h \
|
||||||
state_types.h \
|
state_types.h \
|
||||||
|
utils.h \
|
||||||
version.h
|
version.h
|
||||||
|
|
||||||
GEN_HEADERS := gen_state_names.h \
|
GEN_HEADERS := gen_state_names.h \
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "bitcoin/tx.c"
|
#include "bitcoin/tx.c"
|
||||||
#include "bitcoin/shadouble.c"
|
#include "bitcoin/shadouble.c"
|
||||||
#include "bitcoin/varint.c"
|
#include "bitcoin/varint.c"
|
||||||
|
#include "utils.c"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ccan/str/hex/hex.h>
|
#include <ccan/str/hex/hex.h>
|
||||||
|
|
||||||
@ -8,8 +9,7 @@ const char extended_tx[] = "02000000000101b5bef485c41d0d1f58d1e8a561924ece5c476d
|
|||||||
|
|
||||||
static void hexeq(const void *p, size_t len, const char *hex)
|
static void hexeq(const void *p, size_t len, const char *hex)
|
||||||
{
|
{
|
||||||
char *tmphex = tal_arr(NULL, char, hex_str_size(len));
|
char *tmphex = tal_hexstr(NULL, p, len);
|
||||||
hex_encode(p, len, tmphex, tal_count(tmphex));
|
|
||||||
|
|
||||||
if (strcmp(hex, tmphex)) {
|
if (strcmp(hex, tmphex)) {
|
||||||
fprintf(stderr, "Expected '%s' got '%s'", hex, tmphex);
|
fprintf(stderr, "Expected '%s' got '%s'", hex, tmphex);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "json.h"
|
#include "json.h"
|
||||||
#include "lightningd.h"
|
#include "lightningd.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <ccan/cast/cast.h>
|
#include <ccan/cast/cast.h>
|
||||||
#include <ccan/io/io.h>
|
#include <ccan/io/io.h>
|
||||||
#include <ccan/pipecmd/pipecmd.h>
|
#include <ccan/pipecmd/pipecmd.h>
|
||||||
@ -240,9 +241,8 @@ void bitcoind_send_tx(struct lightningd_state *dstate,
|
|||||||
const struct bitcoin_tx *tx)
|
const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
u8 *raw = linearize_tx(dstate, tx);
|
u8 *raw = linearize_tx(dstate, tx);
|
||||||
char *hex = tal_arr(raw, char, hex_str_size(tal_count(raw)));
|
char *hex = tal_hexstr(raw, raw, tal_count(raw));
|
||||||
|
|
||||||
hex_encode(raw, tal_count(raw), hex, tal_count(hex));
|
|
||||||
start_bitcoin_cli(dstate, process_sendrawrx, NULL, NULL,
|
start_bitcoin_cli(dstate, process_sendrawrx, NULL, NULL,
|
||||||
"sendrawtransaction", hex, NULL);
|
"sendrawtransaction", hex, NULL);
|
||||||
tal_free(raw);
|
tal_free(raw);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "protobuf_convert.h"
|
#include "protobuf_convert.h"
|
||||||
#include "secrets.h"
|
#include "secrets.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <ccan/crypto/sha256/sha256.h>
|
#include <ccan/crypto/sha256/sha256.h>
|
||||||
#include <ccan/io/io.h>
|
#include <ccan/io/io.h>
|
||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
@ -22,23 +23,16 @@
|
|||||||
|
|
||||||
#define FIXME_STUB(peer) do { log_broken((peer)->dstate->base_log, "%s:%u: Implement %s!", __FILE__, __LINE__, __func__); abort(); } while(0)
|
#define FIXME_STUB(peer) do { log_broken((peer)->dstate->base_log, "%s:%u: Implement %s!", __FILE__, __LINE__, __func__); abort(); } while(0)
|
||||||
|
|
||||||
static char *hex_of(const tal_t *ctx, const void *p, size_t n)
|
|
||||||
{
|
|
||||||
char *hex = tal_arr(ctx, char, hex_str_size(n));
|
|
||||||
hex_encode(p, n, hex, hex_str_size(n));
|
|
||||||
return hex;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dump_tx(const char *str, const struct bitcoin_tx *tx)
|
static void dump_tx(const char *str, const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
u8 *linear = linearize_tx(NULL, tx);
|
u8 *linear = linearize_tx(NULL, tx);
|
||||||
printf("%s:%s\n", str, hex_of(linear, linear, tal_count(linear)));
|
printf("%s:%s\n", str, tal_hexstr(linear, linear, tal_count(linear)));
|
||||||
tal_free(linear);
|
tal_free(linear);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_key(const char *str, const struct pubkey *key)
|
static void dump_key(const char *str, const struct pubkey *key)
|
||||||
{
|
{
|
||||||
printf("%s:%s\n", str, hex_of(NULL, key->der, sizeof(key->der)));
|
printf("%s:%s\n", str, tal_hexstr(NULL, key->der, sizeof(key->der)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap (and own!) member inside Pkt */
|
/* Wrap (and own!) member inside Pkt */
|
||||||
|
9
utils.c
Normal file
9
utils.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "utils.h"
|
||||||
|
#include <ccan/str/hex/hex.h>
|
||||||
|
|
||||||
|
char *tal_hexstr(const tal_t *ctx, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
char *str = tal_arr(ctx, char, hex_str_size(len));
|
||||||
|
hex_encode(data, len, str, hex_str_size(len));
|
||||||
|
return str;
|
||||||
|
}
|
9
utils.h
Normal file
9
utils.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef LIGHTNING_UTILS_H
|
||||||
|
#define LIGHTNING_UTILS_H
|
||||||
|
#include "config.h"
|
||||||
|
#include <ccan/tal/tal.h>
|
||||||
|
|
||||||
|
/* Allocate and fill in a hex-encoded string of this data. */
|
||||||
|
char *tal_hexstr(const tal_t *ctx, const void *data, size_t len);
|
||||||
|
|
||||||
|
#endif /* LIGHTNING_UTILS_H */
|
Loading…
Reference in New Issue
Block a user