Skip to content

Commit

Permalink
common/amount: new types struct amount_msat and struct amount_sat.
Browse files Browse the repository at this point in the history
They're generally used pass-by-copy (unusual for C structs, but
convenient they're basically u64) and all possibly problematic
operations return WARN_UNUSED_RESULT bool to make you handle the
over/underflow cases.

The new #include in json.h means we bolt11.c sees the amount.h definition
of MSAT_PER_BTC, so delete its local version.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 21, 2019
1 parent 269dbe5 commit 7fad7bc
Show file tree
Hide file tree
Showing 25 changed files with 780 additions and 5 deletions.
3 changes: 2 additions & 1 deletion channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ ALL_GEN_HEADERS += $(LIGHTNINGD_CHANNEL_HEADERS_GEN)

# Common source we use.
CHANNELD_COMMON_OBJS := \
common/amount.o \
common/base32.o \
common/bip32.o \
common/bip32.o \
common/channel_config.o \
common/crypto_state.o \
common/crypto_sync.o \
Expand Down
1 change: 1 addition & 0 deletions channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static bool print_superverbose;
#include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <ccan/str/hex/hex.h>
#include <common/amount.h>
#include <common/key_derive.h>
#include <common/status.h>

Expand Down
4 changes: 4 additions & 0 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
#include <bitcoin/pubkey.h>
#include <ccan/err/err.h>
#include <ccan/str/hex/hex.h>
#include <common/amount.h>
#include <common/sphinx.h>
#include <common/type_to_string.h>
#include <stdio.h>
#include <wally_core.h>

/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS END */

void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
{
va_list ap;
Expand Down
1 change: 1 addition & 0 deletions cli/test/run-large-input.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <common/amount.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down
1 change: 1 addition & 0 deletions closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $(LIGHTNINGD_CLOSING_OBJS): $(LIGHTNINGD_HEADERS)

# Common source we use.
CLOSINGD_COMMON_OBJS := \
common/amount.o \
common/base32.o \
common/bip32.o \
common/close_tx.o \
Expand Down
1 change: 1 addition & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
COMMON_SRC_NOGEN := \
common/amount.c \
common/base32.c \
common/bech32.c \
common/bech32_util.c \
Expand Down
Loading

0 comments on commit 7fad7bc

Please sign in to comment.