amount: add 'is_zero' helper

convenience, mostly
This commit is contained in:
niftynei 2021-06-08 15:37:49 -05:00 committed by neil saitug
parent 3ae64efbe4
commit b1982f04be
5 changed files with 16 additions and 8 deletions

View File

@ -357,6 +357,11 @@ bool amount_sat_eq(struct amount_sat a, struct amount_sat b)
return a.satoshis == b.satoshis;
}
bool amount_sat_zero(struct amount_sat a)
{
return a.satoshis == 0;
}
bool amount_msat_eq(struct amount_msat a, struct amount_msat b)
{
return a.millisatoshis == b.millisatoshis;

View File

@ -94,6 +94,9 @@ struct amount_sat amount_sat_div(struct amount_sat sat, u64 div);
bool amount_sat_eq(struct amount_sat a, struct amount_sat b);
bool amount_msat_eq(struct amount_msat a, struct amount_msat b);
/* Is a zero? */
bool amount_sat_zero(struct amount_sat a);
/* Is a > b? */
bool amount_sat_greater(struct amount_sat a, struct amount_sat b);
bool amount_msat_greater(struct amount_msat a, struct amount_msat b);

View File

@ -619,11 +619,11 @@ rbf_channel_hook_deserialize(struct rbf_channel_payload *payload,
fatal("Plugin failed to supply our_funding_msat field");
if (payload->psbt
&& amount_sat_eq(payload->our_funding, AMOUNT_SAT(0)))
&& amount_sat_zero(payload->our_funding))
fatal("Plugin failed to supply our_funding_msat field");
if (!payload->psbt &&
!amount_sat_eq(payload->our_funding, AMOUNT_SAT(0))) {
!amount_sat_zero(payload->our_funding)) {
log_broken(channel->log, "`our_funding_msat` returned"
" but no `psbt` present. %.*s",
@ -777,11 +777,11 @@ openchannel2_hook_deserialize(struct openchannel2_payload *payload,
fatal("Plugin failed to supply our_funding_msat field");
if (payload->psbt
&& amount_sat_eq(payload->accepter_funding, AMOUNT_SAT(0)))
&& amount_sat_zero(payload->accepter_funding))
fatal("Plugin failed to supply our_funding_msat field");
if (!payload->psbt
&& !amount_sat_eq(payload->accepter_funding, AMOUNT_SAT(0))) {
&& !amount_sat_zero(payload->accepter_funding)) {
/* Gotta give a PSBT if you set the accepter_funding amount */
/* Let dualopend know we've failed */
payload->err_msg = "Client error. Unable to continue";

View File

@ -427,7 +427,7 @@ listfunds_success(struct command *cmd,
&info->our_funding),
funding_err ? funding_err : "");
if (amount_sat_eq(info->our_funding, AMOUNT_SAT(0)))
if (amount_sat_zero(info->our_funding))
return command_hook_success(cmd);
plugin_log(cmd->plugin, LOG_DBG,

View File

@ -220,7 +220,7 @@ calculate_our_funding(struct funder_policy *policy,
/* Figure out amount of actual headroom we have */
if (!amount_sat_sub(&avail_channel_space, channel_max, their_funding)
|| amount_sat_eq(avail_channel_space, AMOUNT_SAT(0))) {
|| amount_sat_zero(avail_channel_space)) {
*our_funding = AMOUNT_SAT(0);
return tal_fmt(tmpctx, "No space available in channel."
" channel_max %s, their_funding %s",
@ -234,7 +234,7 @@ calculate_our_funding(struct funder_policy *policy,
* 'reserve_tank' */
if (!amount_sat_sub(&net_available_funds, available_funds,
policy->reserve_tank)
|| amount_sat_eq(net_available_funds, AMOUNT_SAT(0))) {
|| amount_sat_zero(net_available_funds)) {
*our_funding = AMOUNT_SAT(0);
return tal_fmt(tmpctx, "Reserve tank too low."
" available_funds %s, reserve_tank requires %s",
@ -272,7 +272,7 @@ calculate_our_funding(struct funder_policy *policy,
*our_funding = apply_policy(policy, their_funding, available_funds);
/* Don't return an 'error' if we're already at 0 */
if (amount_sat_eq(*our_funding, AMOUNT_SAT(0)))
if (amount_sat_zero(*our_funding))
return NULL;
/* our_funding is probably sane, so let's fuzz this amount a bit */