You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
#include "utils.h"
|
|
#include <ccan/list/list.h>
|
|
#include <ccan/str/hex/hex.h>
|
|
#include <ccan/tal/str/str.h>
|
|
#include <locale.h>
|
|
|
|
secp256k1_context *secp256k1_ctx;
|
|
const tal_t *tmpctx;
|
|
|
|
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;
|
|
}
|
|
|
|
char *tal_hex(const tal_t *ctx, const tal_t *data)
|
|
{
|
|
return tal_hexstr(ctx, data, tal_bytelen(data));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/* Use the POSIX C locale. */
|
|
void setup_locale(void)
|
|
{
|
|
setlocale(LC_ALL, "C");
|
|
putenv("LC_ALL=C"); /* For exec{l,lp,v,vp}(...) */
|
|
}
|
|
|
|
/* Initial creation of tmpctx. */
|
|
void setup_tmpctx(void)
|
|
{
|
|
tmpctx = tal_arr_label(NULL, char, 0, "tmpctx");
|
|
}
|
|
|
|
/* Free any children of tmpctx. */
|
|
void clean_tmpctx(void)
|
|
{
|
|
const tal_t *p;
|
|
|
|
/* Don't actually free tmpctx: we hand pointers to it around. */
|
|
while ((p = tal_first(tmpctx)) != NULL)
|
|
tal_free(p);
|
|
}
|
|
|