Browse Source

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 <rusty@rustcorp.com.au>
pr-2391
Rusty Russell 6 years ago
parent
commit
02faadfb93
  1. 20
      bitcoin/chainparams.c
  2. 7
      common/amount.h
  3. 4
      onchaind/onchaind.c

20
bitcoin/chainparams.c

@ -17,8 +17,8 @@ const struct chainparams networks[] = {
*...
* - MUST set `funding_satoshis` to less than 2^24 satoshi.
*/
.max_funding = AMOUNT_SAT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
/* "Lightning Charge Powers Developers & Blockstream Store" */
.when_lightning_became_cool = 504500,
.testnet = false},
@ -29,8 +29,8 @@ const struct chainparams networks[] = {
.cli = "bitcoin-cli",
.cli_args = "-regtest",
.dust_limit = { 546 },
.max_funding = AMOUNT_SAT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
.when_lightning_became_cool = 1,
.testnet = true},
{.network_name = "testnet",
@ -40,8 +40,8 @@ const struct chainparams networks[] = {
.cli = "bitcoin-cli",
.cli_args = "-testnet",
.dust_limit = { 546 },
.max_funding = AMOUNT_SAT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
.testnet = true},
{.network_name = "litecoin",
.bip173_name = "ltc",
@ -50,8 +50,8 @@ const struct chainparams networks[] = {
.cli = "litecoin-cli",
.cli_args = NULL,
.dust_limit = { 100000 },
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT_INIT(60 * 0xFFFFFFFFULL),
.when_lightning_became_cool = 1320000,
.testnet = false},
{.network_name = "litecoin-testnet",
@ -61,8 +61,8 @@ const struct chainparams networks[] = {
.cli = "litecoin-cli",
.cli_args = "-testnet",
.dust_limit = { 100000 },
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT_INIT(60 * 0xFFFFFFFFULL),
.when_lightning_became_cool = 1,
.testnet = true}
};

7
common/amount.h

@ -29,6 +29,13 @@ struct amount_msat {
#define AMOUNT_MUST_BE_CONST(c) 0
#endif
/* GCC 4.8.5 (Centos 7.6!) thinks struct casts are not constants, so we
* need to not use a cast for static initializations. */
#define AMOUNT_MSAT_INIT(msat) \
{ .millisatoshis = (msat) }
#define AMOUNT_SAT_INIT(sat) \
{ .satoshis = (sat) }
#define AMOUNT_MSAT(constant) \
((struct amount_msat){(constant) + AMOUNT_MUST_BE_CONST(constant)})

4
onchaind/onchaind.c

@ -156,7 +156,7 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx,
const struct bitcoin_signature *remotesig,
const u8 *wscript)
{
static struct amount_sat fee = AMOUNT_SAT(UINT64_MAX);
static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX);
/* BOLT #3:
*
@ -181,7 +181,7 @@ static void set_htlc_success_fee(struct bitcoin_tx *tx,
const struct bitcoin_signature *remotesig,
const u8 *wscript)
{
static struct amount_sat fee = AMOUNT_SAT(UINT64_MAX);
static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX);
/* BOLT #3:
*

Loading…
Cancel
Save