2016-05-03 03:29:20 +02:00
|
|
|
#include "utils.h"
|
2017-09-28 05:40:57 +02:00
|
|
|
#include <ccan/list/list.h>
|
2016-05-03 03:29:20 +02:00
|
|
|
#include <ccan/str/hex/hex.h>
|
2017-09-28 05:40:57 +02:00
|
|
|
#include <ccan/tal/str/str.h>
|
2016-05-03 03:29:20 +02:00
|
|
|
|
2016-12-02 08:41:06 +01:00
|
|
|
secp256k1_context *secp256k1_ctx;
|
|
|
|
|
2016-05-03 03:29:20 +02:00
|
|
|
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;
|
|
|
|
}
|
2016-09-07 23:34:36 +02:00
|
|
|
|
2017-01-10 05:49:25 +01:00
|
|
|
char *tal_hex(const tal_t *ctx, const tal_t *data)
|
|
|
|
{
|
|
|
|
return tal_hexstr(ctx, data, tal_len(data));
|
|
|
|
}
|
|
|
|
|
2016-09-07 23:34:36 +02:00
|
|
|
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len)
|
|
|
|
{
|
|
|
|
u8 *data = tal_arr(ctx, u8, hex_data_size(len));
|
|
|
|
if (!hex_decode(str, len, data, hex_data_size(len)))
|
|
|
|
return NULL;
|
|
|
|
return data;
|
|
|
|
}
|
2017-09-28 05:40:57 +02:00
|
|
|
|
|
|
|
struct tmpctx {
|
|
|
|
struct list_node list;
|
|
|
|
const char *file;
|
|
|
|
unsigned int line;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list_head tmpctxs = LIST_HEAD_INIT(tmpctxs);
|
|
|
|
|
|
|
|
static void destroy_tmpctx(struct tmpctx *t)
|
|
|
|
{
|
|
|
|
list_del_from(&tmpctxs, &t->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
tal_t *tal_tmpctx_(const tal_t *ctx, const char *file, unsigned int line)
|
|
|
|
{
|
|
|
|
struct tmpctx *t = tal(ctx, struct tmpctx);
|
|
|
|
t->file = file;
|
|
|
|
t->line = line;
|
|
|
|
list_add_tail(&tmpctxs, &t->list);
|
|
|
|
tal_add_destructor(t, destroy_tmpctx);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *tmpctx_any(void)
|
|
|
|
{
|
|
|
|
struct tmpctx *t = list_top(&tmpctxs, struct tmpctx, list);
|
|
|
|
|
|
|
|
if (t)
|
|
|
|
return tal_fmt(t, "%s:%u", t->file, t->line);
|
|
|
|
return NULL;
|
|
|
|
}
|