diff --git a/closingd/closingd.c b/closingd/closingd.c index 7e65cb847..0fba76606 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -540,17 +540,16 @@ adjust_offer(struct per_peer_state *pps, const struct channel_id *channel_id, * one from our previous proposal. So, if the user requested a * step of 1 satoshi at a time we should just return our end of * the range from this function. */ - amount_msat_from_u64(&step_msat, - (fee_negotiation_step - 1) * MSAT_PER_SAT); + step_msat = amount_msat((fee_negotiation_step - 1) + * MSAT_PER_SAT); } else { /* fee_negotiation_step is e.g. 20 to designate 20% from * range_len (which is in satoshi), so: * range_len * fee_negotiation_step / 100 [sat] * is equivalent to: * range_len * fee_negotiation_step * 10 [msat] */ - amount_msat_from_u64(&step_msat, - range_len.satoshis /* Raw: % calc */ * - fee_negotiation_step * 10); + step_msat = amount_msat(range_len.satoshis /* Raw: % calc */ * + fee_negotiation_step * 10); } step_sat = amount_msat_to_sat_round_down(step_msat); diff --git a/common/amount.c b/common/amount.c index 6894c24bb..f00a02daa 100644 --- a/common/amount.c +++ b/common/amount.c @@ -401,22 +401,20 @@ bool amount_msat_to_u32(struct amount_msat msat, u32 *millisatoshis) return true; } -void amount_msat_from_u64(struct amount_msat *msat, u64 millisatoshis) +struct amount_msat amount_msat(u64 millisatoshis) { - msat->millisatoshis = millisatoshis; -} + struct amount_msat msat; -void amount_sat_from_u64(struct amount_sat *sat, u64 satoshis) -{ - sat->satoshis = satoshis; + msat.millisatoshis = millisatoshis; + return msat; } -WARN_UNUSED_RESULT bool amount_msat_from_sat_u64(struct amount_msat *msat, u64 satoshis) +struct amount_sat amount_sat(u64 satoshis) { - if (mul_overflows_u64(satoshis, MSAT_PER_SAT)) - return false; - msat->millisatoshis = satoshis * MSAT_PER_SAT; - return true; + struct amount_sat sat; + + sat.satoshis = satoshis; + return sat; } bool amount_msat_fee(struct amount_msat *fee, diff --git a/common/amount.h b/common/amount.h index b209881fb..38df4c60b 100644 --- a/common/amount.h +++ b/common/amount.h @@ -47,6 +47,10 @@ struct amount_asset { #define AMOUNT_SAT(constant) \ ((struct amount_sat){(constant) + AMOUNT_MUST_BE_CONST(constant)}) +/* We do sometimes need to import from raw types, eg. wally or wire fmt */ +struct amount_msat amount_msat(u64 millisatoshis); +struct amount_sat amount_sat(u64 satoshis); + /* You may not always be able to convert satoshis->millisatoshis. */ WARN_UNUSED_RESULT bool amount_sat_to_msat(struct amount_msat *msat, struct amount_sat sat); @@ -128,11 +132,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset); WARN_UNUSED_RESULT bool amount_msat_to_u32(struct amount_msat msat, u32 *millisatoshis); -/* Programatically initialize from various types */ -void amount_msat_from_u64(struct amount_msat *msat, u64 millisatoshis); -void amount_sat_from_u64(struct amount_sat *sat, u64 satoshis); -WARN_UNUSED_RESULT bool amount_msat_from_sat_u64(struct amount_msat *msat, u64 satoshis); - /* Common operation: what is the HTLC fee for given feerate? Can overflow! */ WARN_UNUSED_RESULT bool amount_msat_fee(struct amount_msat *fee, struct amount_msat amt, diff --git a/common/onion.c b/common/onion.c index f44bf75e3..8378e296a 100644 --- a/common/onion.c +++ b/common/onion.c @@ -326,7 +326,7 @@ struct onion_payload *onion_decode(const tal_t *ctx, if (!tlv->amt_to_forward || !tlv->outgoing_cltv_value) goto fail; - amount_msat_from_u64(&p->amt_to_forward, *tlv->amt_to_forward); + p->amt_to_forward = amount_msat(*tlv->amt_to_forward); p->outgoing_cltv = *tlv->outgoing_cltv_value; /* BOLT #4: diff --git a/common/test/run-sphinx.c b/common/test/run-sphinx.c index baea842a2..0e8fb0d4d 100644 --- a/common/test/run-sphinx.c +++ b/common/test/run-sphinx.c @@ -25,12 +25,12 @@ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) /* Generated stub for amount_asset_to_sat */ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED) { fprintf(stderr, "amount_asset_to_sat called!\n"); abort(); } +/* Generated stub for amount_msat */ +struct amount_msat amount_msat(u64 millisatoshis UNNEEDED) +{ fprintf(stderr, "amount_msat called!\n"); abort(); } /* Generated stub for amount_msat_eq */ bool amount_msat_eq(struct amount_msat a UNNEEDED, struct amount_msat b UNNEEDED) { fprintf(stderr, "amount_msat_eq called!\n"); abort(); } -/* Generated stub for amount_msat_from_u64 */ -void amount_msat_from_u64(struct amount_msat *msat UNNEEDED, u64 millisatoshis UNNEEDED) -{ fprintf(stderr, "amount_msat_from_u64 called!\n"); abort(); } /* Generated stub for amount_sat_add */ bool amount_sat_add(struct amount_sat *val UNNEEDED, struct amount_sat a UNNEEDED, diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 89c26b483..cf7c1acc1 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -82,9 +82,6 @@ bool nannounce_different(struct gossip_store *gs UNNEEDED, /* Generated stub for notleak_ */ void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } -/* Generated stub for onion_type_name */ -const char *onion_type_name(int e UNNEEDED) -{ fprintf(stderr, "onion_type_name called!\n"); abort(); } /* Generated stub for peer_supplied_good_gossip */ void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } diff --git a/gossipd/test/run-check_channel_announcement.c b/gossipd/test/run-check_channel_announcement.c index 509109f35..d49be28f7 100644 --- a/gossipd/test/run-check_channel_announcement.c +++ b/gossipd/test/run-check_channel_announcement.c @@ -118,9 +118,6 @@ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED, /* Generated stub for notleak_ */ void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } -/* Generated stub for onion_type_name */ -const char *onion_type_name(int e UNNEEDED) -{ fprintf(stderr, "onion_type_name called!\n"); abort(); } /* Generated stub for peer_supplied_good_gossip */ void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 3eaf9dd80..26cf9ef6d 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -69,9 +69,6 @@ bool nannounce_different(struct gossip_store *gs UNNEEDED, /* Generated stub for notleak_ */ void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } -/* Generated stub for onion_type_name */ -const char *onion_type_name(int e UNNEEDED) -{ fprintf(stderr, "onion_type_name called!\n"); abort(); } /* Generated stub for peer_supplied_good_gossip */ void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 513e42df3..7e8af7cba 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -69,9 +69,6 @@ bool nannounce_different(struct gossip_store *gs UNNEEDED, /* Generated stub for notleak_ */ void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } -/* Generated stub for onion_type_name */ -const char *onion_type_name(int e UNNEEDED) -{ fprintf(stderr, "onion_type_name called!\n"); abort(); } /* Generated stub for peer_supplied_good_gossip */ void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } diff --git a/gossipd/test/run-overlong.c b/gossipd/test/run-overlong.c index 262f70d9c..bd5eee9ac 100644 --- a/gossipd/test/run-overlong.c +++ b/gossipd/test/run-overlong.c @@ -69,9 +69,6 @@ bool nannounce_different(struct gossip_store *gs UNNEEDED, /* Generated stub for notleak_ */ void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } -/* Generated stub for onion_type_name */ -const char *onion_type_name(int e UNNEEDED) -{ fprintf(stderr, "onion_type_name called!\n"); abort(); } /* Generated stub for peer_supplied_good_gossip */ void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } diff --git a/gossipd/test/run-txout_failure.c b/gossipd/test/run-txout_failure.c index 8ff9712c9..864e4ef5f 100644 --- a/gossipd/test/run-txout_failure.c +++ b/gossipd/test/run-txout_failure.c @@ -79,9 +79,6 @@ bool nannounce_different(struct gossip_store *gs UNNEEDED, /* Generated stub for notleak_ */ void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } -/* Generated stub for onion_type_name */ -const char *onion_type_name(int e UNNEEDED) -{ fprintf(stderr, "onion_type_name called!\n"); abort(); } /* Generated stub for peer_supplied_good_gossip */ void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 8766459f8..86a2729ba 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -705,8 +705,8 @@ static void channel_config(struct lightningd *ld, *max_to_self_delay = ld->config.locktime_max; /* Take minimal effective capacity from config min_capacity_sat */ - if (!amount_msat_from_sat_u64(min_effective_htlc_capacity, - ld->config.min_capacity_sat)) + if (!amount_sat_to_msat(min_effective_htlc_capacity, + amount_sat(ld->config.min_capacity_sat))) fatal("amount_msat overflow for config.min_capacity_sat"); /* Substract 2 * dust_limit, so fundchannel with min value is possible */ if (!amount_sat_to_msat(&dust_limit, chainparams->dust_limit)) diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 1e9a73fe9..bff224de4 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -11,10 +11,6 @@ int unused_main(int argc, char *argv[]); /* Generated stub for activate_peers */ void activate_peers(struct lightningd *ld UNNEEDED) { fprintf(stderr, "activate_peers called!\n"); abort(); } -/* Generated stub for add_plugin_dir */ -char *add_plugin_dir(struct plugins *plugins UNNEEDED, const char *dir UNNEEDED, - bool error_ok UNNEEDED) -{ fprintf(stderr, "add_plugin_dir called!\n"); abort(); } /* Generated stub for begin_topology */ void begin_topology(struct chain_topology *topo UNNEEDED) { fprintf(stderr, "begin_topology called!\n"); abort(); } @@ -207,6 +203,7 @@ void plugins_init(struct plugins *plugins UNNEEDED) struct plugins *plugins_new(const tal_t *ctx UNNEEDED, struct log_book *log_book UNNEEDED, struct lightningd *ld UNNEEDED) { fprintf(stderr, "plugins_new called!\n"); abort(); } +/* Generated stub for plugins_set_builtin_plugins_dir */ void plugins_set_builtin_plugins_dir(struct plugins *plugins UNNEEDED, const char *dir UNNEEDED) { fprintf(stderr, "plugins_set_builtin_plugins_dir called!\n"); abort(); }