2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_COMMON_UTILS_H
|
|
|
|
#define LIGHTNING_COMMON_UTILS_H
|
2016-05-03 03:29:20 +02:00
|
|
|
#include "config.h"
|
2018-07-04 07:30:02 +02:00
|
|
|
#include <ccan/crypto/ripemd160/ripemd160.h>
|
|
|
|
#include <ccan/crypto/sha256/sha256.h>
|
2016-09-07 23:34:36 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2018-07-04 07:30:02 +02:00
|
|
|
#include <ccan/structeq/structeq.h>
|
2016-05-03 03:29:20 +02:00
|
|
|
#include <ccan/tal/tal.h>
|
2016-12-02 08:41:06 +01:00
|
|
|
#include <secp256k1.h>
|
|
|
|
|
|
|
|
extern secp256k1_context *secp256k1_ctx;
|
2016-05-03 03:29:20 +02:00
|
|
|
|
|
|
|
/* Allocate and fill in a hex-encoded string of this data. */
|
|
|
|
char *tal_hexstr(const tal_t *ctx, const void *data, size_t len);
|
|
|
|
|
2017-01-10 05:49:25 +01:00
|
|
|
/* Allocate and fill a hex-encoding of this tal pointer. */
|
|
|
|
char *tal_hex(const tal_t *ctx, const tal_t *data);
|
|
|
|
|
2016-09-07 23:34:36 +02:00
|
|
|
/* Allocate and fill a buffer with the data of this hex string. */
|
|
|
|
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);
|
|
|
|
|
2018-09-27 02:19:24 +02:00
|
|
|
/* Helper macro to extend tal_arr and return pointer new last element. */
|
|
|
|
#if HAVE_STATEMENT_EXPR
|
|
|
|
/* More efficient version calls tal_count() once */
|
|
|
|
#define tal_arr_expand(p) \
|
|
|
|
({ size_t n = tal_count(*p); tal_resize((p), n+1); *(p) + n; })
|
|
|
|
#else
|
|
|
|
#define tal_arr_expand(p) \
|
|
|
|
(tal_resize((p), tal_count(*(p))+1), (*p) + tal_count(*(p))-1)
|
|
|
|
#endif
|
|
|
|
|
2018-04-25 12:55:34 +02:00
|
|
|
/* Use the POSIX C locale. */
|
|
|
|
void setup_locale(void);
|
|
|
|
|
2018-08-02 08:49:22 +02:00
|
|
|
/* Global temporary convenience context: children freed in io loop core. */
|
2018-03-15 05:30:37 +01:00
|
|
|
extern const tal_t *tmpctx;
|
|
|
|
|
|
|
|
/* Initial creation of tmpctx. */
|
|
|
|
void setup_tmpctx(void);
|
|
|
|
|
|
|
|
/* Free any children of tmpctx. */
|
|
|
|
void clean_tmpctx(void);
|
2016-11-01 12:04:27 +01:00
|
|
|
|
2018-07-04 07:30:02 +02:00
|
|
|
/* Define sha256_eq. */
|
|
|
|
STRUCTEQ_DEF(sha256, 0, u);
|
|
|
|
|
|
|
|
/* Define ripemd160_eq. */
|
|
|
|
STRUCTEQ_DEF(ripemd160, 0, u);
|
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_UTILS_H */
|