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);
|
|
|
|
|
2019-01-15 04:51:27 +01:00
|
|
|
/* Note: p is never a complex expression, otherwise this multi-evaluates! */
|
|
|
|
#define tal_arr_expand(p, s) \
|
|
|
|
do { \
|
|
|
|
size_t n = tal_count(*(p)); \
|
|
|
|
tal_resize((p), n+1); \
|
|
|
|
(*(p))[n] = (s); \
|
|
|
|
} while(0)
|
2018-09-27 02:19:24 +02:00
|
|
|
|
2018-12-03 14:38:19 +01:00
|
|
|
/**
|
|
|
|
* Remove an element from an array
|
|
|
|
*
|
|
|
|
* This will shift the elements past the removed element, changing
|
|
|
|
* their position in memory, so only use this for arrays of pointers.
|
|
|
|
*/
|
|
|
|
#define tal_arr_remove(p, n) tal_arr_remove_((p), sizeof(**p), (n))
|
|
|
|
void tal_arr_remove_(void *p, size_t elemsize, size_t n);
|
|
|
|
|
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);
|
|
|
|
|
2019-08-01 03:33:54 +02:00
|
|
|
/* If gcc complains about 'may be uninitialized' even at -O3, and the code is
|
|
|
|
* clear, use this to suppress it. Argument should be gcc version it
|
|
|
|
* complained on, so we can re-test as gcc evolves. */
|
|
|
|
#define COMPILER_WANTS_INIT(compiler_versions) = 0
|
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_UTILS_H */
|