Skip to content

Commit 02faadf

Browse files
committed
amount: make it work with gcc-4.8.
``` In file included from bitcoin/chainparams.h:7:0,from bitcoin/chainparams.c:1: ./common/amount.h:36:11: error: initializer element is not constant ((struct amount_sat){(constant) + AMOUNT_MUST_BE_CONST(constant)}) ^ bitcoin/chainparams.c:20:21: note: in expansion of macro ‘AMOUNT_SAT’ .max_funding = AMOUNT_SAT((1 << 24) - 1), ^ ./common/amount.h:36:11: error: (near initialization for ‘networks[0].max_funding’) ((struct amount_sat){(constant) + AMOUNT_MUST_BE_CONST(constant)}) ^ bitcoin/chainparams.c:20:21: note: in expansion of macro ‘AMOUNT_SAT’ .max_funding = AMOUNT_SAT((1 << 24) - 1), ``` Fixes: #2404 Signed-off-by: Rusty Russell <[email protected]>
1 parent a3bac88 commit 02faadf

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

bitcoin/chainparams.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const struct chainparams networks[] = {
1717
*...
1818
* - MUST set `funding_satoshis` to less than 2^24 satoshi.
1919
*/
20-
.max_funding = AMOUNT_SAT((1 << 24) - 1),
21-
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
20+
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
21+
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
2222
/* "Lightning Charge Powers Developers & Blockstream Store" */
2323
.when_lightning_became_cool = 504500,
2424
.testnet = false},
@@ -29,8 +29,8 @@ const struct chainparams networks[] = {
2929
.cli = "bitcoin-cli",
3030
.cli_args = "-regtest",
3131
.dust_limit = { 546 },
32-
.max_funding = AMOUNT_SAT((1 << 24) - 1),
33-
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
32+
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
33+
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
3434
.when_lightning_became_cool = 1,
3535
.testnet = true},
3636
{.network_name = "testnet",
@@ -40,8 +40,8 @@ const struct chainparams networks[] = {
4040
.cli = "bitcoin-cli",
4141
.cli_args = "-testnet",
4242
.dust_limit = { 546 },
43-
.max_funding = AMOUNT_SAT((1 << 24) - 1),
44-
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
43+
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
44+
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
4545
.testnet = true},
4646
{.network_name = "litecoin",
4747
.bip173_name = "ltc",
@@ -50,8 +50,8 @@ const struct chainparams networks[] = {
5050
.cli = "litecoin-cli",
5151
.cli_args = NULL,
5252
.dust_limit = { 100000 },
53-
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
54-
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
53+
.max_funding = AMOUNT_SAT_INIT(60 * ((1 << 24) - 1)),
54+
.max_payment = AMOUNT_MSAT_INIT(60 * 0xFFFFFFFFULL),
5555
.when_lightning_became_cool = 1320000,
5656
.testnet = false},
5757
{.network_name = "litecoin-testnet",
@@ -61,8 +61,8 @@ const struct chainparams networks[] = {
6161
.cli = "litecoin-cli",
6262
.cli_args = "-testnet",
6363
.dust_limit = { 100000 },
64-
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
65-
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
64+
.max_funding = AMOUNT_SAT_INIT(60 * ((1 << 24) - 1)),
65+
.max_payment = AMOUNT_MSAT_INIT(60 * 0xFFFFFFFFULL),
6666
.when_lightning_became_cool = 1,
6767
.testnet = true}
6868
};

common/amount.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ struct amount_msat {
2929
#define AMOUNT_MUST_BE_CONST(c) 0
3030
#endif
3131

32+
/* GCC 4.8.5 (Centos 7.6!) thinks struct casts are not constants, so we
33+
* need to not use a cast for static initializations. */
34+
#define AMOUNT_MSAT_INIT(msat) \
35+
{ .millisatoshis = (msat) }
36+
#define AMOUNT_SAT_INIT(sat) \
37+
{ .satoshis = (sat) }
38+
3239
#define AMOUNT_MSAT(constant) \
3340
((struct amount_msat){(constant) + AMOUNT_MUST_BE_CONST(constant)})
3441

onchaind/onchaind.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx,
156156
const struct bitcoin_signature *remotesig,
157157
const u8 *wscript)
158158
{
159-
static struct amount_sat fee = AMOUNT_SAT(UINT64_MAX);
159+
static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX);
160160

161161
/* BOLT #3:
162162
*
@@ -181,7 +181,7 @@ static void set_htlc_success_fee(struct bitcoin_tx *tx,
181181
const struct bitcoin_signature *remotesig,
182182
const u8 *wscript)
183183
{
184-
static struct amount_sat fee = AMOUNT_SAT(UINT64_MAX);
184+
static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX);
185185

186186
/* BOLT #3:
187187
*

0 commit comments

Comments
 (0)