forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup: create a common setup which will handle the wally-context
Since we now over-write the wally malloc/free functions, we need to do so for tests as well. Here we pull up all of the common setup/teardown logic into a separate place, and update the tests that use libwally to use the new common_setup core Changelog-None
- Loading branch information
1 parent
c5a0d8c
commit fbe50e0
Showing
26 changed files
with
111 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <ccan/ccan/err/err.h> | ||
#include <common/memleak.h> | ||
#include <common/setup.h> | ||
#include <common/utils.h> | ||
#include <sodium.h> | ||
#include <wally_core.h> | ||
|
||
static const tal_t *wally_tal_ctx; | ||
|
||
static void *wally_tal(size_t size) | ||
{ | ||
return tal_arr_label(wally_tal_ctx, u8, size, "wally_notleak"); | ||
} | ||
|
||
static void wally_free(void *ptr) | ||
{ | ||
tal_free(ptr); | ||
} | ||
|
||
static struct wally_operations wally_tal_ops = { | ||
.malloc_fn = wally_tal, | ||
.free_fn = wally_free, | ||
}; | ||
|
||
|
||
void common_setup(const char *argv0) | ||
{ | ||
setup_locale(); | ||
err_set_progname(argv0); | ||
|
||
/* We rely on libsodium for some of the crypto stuff, so we'd better | ||
* not start if it cannot do its job correctly. */ | ||
if (sodium_init() == -1) | ||
errx(1, "Could not initialize libsodium. Maybe not enough entropy" | ||
" available ?"); | ||
|
||
/* We set up Wally, the bitcoin wallet lib */ | ||
wally_tal_ctx = tal_label(NULL, char, "wally_ctx_notleak"); | ||
wally_init(0); | ||
wally_set_operations(&wally_tal_ops); | ||
secp256k1_ctx = wally_get_secp_context(); | ||
|
||
setup_tmpctx(); | ||
} | ||
|
||
void common_shutdown(void) | ||
{ | ||
tal_free(tmpctx); | ||
wally_cleanup(0); | ||
tal_free(wally_tal_ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef LIGHTNING_COMMON_SETUP_H | ||
#define LIGHTNING_COMMON_SETUP_H | ||
#include "config.h" | ||
|
||
void common_setup(const char *argv0); | ||
void common_shutdown(void); | ||
#endif /* LIGHTNING_COMMON_SETUP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.