mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
amount: add 'is_zero' helper
convenience, mostly
This commit is contained in:
@@ -357,6 +357,11 @@ bool amount_sat_eq(struct amount_sat a, struct amount_sat b)
|
|||||||
return a.satoshis == b.satoshis;
|
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)
|
bool amount_msat_eq(struct amount_msat a, struct amount_msat b)
|
||||||
{
|
{
|
||||||
return a.millisatoshis == b.millisatoshis;
|
return a.millisatoshis == b.millisatoshis;
|
||||||
|
|||||||
@@ -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_sat_eq(struct amount_sat a, struct amount_sat b);
|
||||||
bool amount_msat_eq(struct amount_msat a, struct amount_msat 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? */
|
/* Is a > b? */
|
||||||
bool amount_sat_greater(struct amount_sat a, struct amount_sat 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);
|
bool amount_msat_greater(struct amount_msat a, struct amount_msat b);
|
||||||
|
|||||||
@@ -619,11 +619,11 @@ rbf_channel_hook_deserialize(struct rbf_channel_payload *payload,
|
|||||||
fatal("Plugin failed to supply our_funding_msat field");
|
fatal("Plugin failed to supply our_funding_msat field");
|
||||||
|
|
||||||
if (payload->psbt
|
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");
|
fatal("Plugin failed to supply our_funding_msat field");
|
||||||
|
|
||||||
if (!payload->psbt &&
|
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"
|
log_broken(channel->log, "`our_funding_msat` returned"
|
||||||
" but no `psbt` present. %.*s",
|
" 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");
|
fatal("Plugin failed to supply our_funding_msat field");
|
||||||
|
|
||||||
if (payload->psbt
|
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");
|
fatal("Plugin failed to supply our_funding_msat field");
|
||||||
|
|
||||||
if (!payload->psbt
|
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 */
|
/* Gotta give a PSBT if you set the accepter_funding amount */
|
||||||
/* Let dualopend know we've failed */
|
/* Let dualopend know we've failed */
|
||||||
payload->err_msg = "Client error. Unable to continue";
|
payload->err_msg = "Client error. Unable to continue";
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ listfunds_success(struct command *cmd,
|
|||||||
&info->our_funding),
|
&info->our_funding),
|
||||||
funding_err ? funding_err : "");
|
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);
|
return command_hook_success(cmd);
|
||||||
|
|
||||||
plugin_log(cmd->plugin, LOG_DBG,
|
plugin_log(cmd->plugin, LOG_DBG,
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ calculate_our_funding(struct funder_policy *policy,
|
|||||||
|
|
||||||
/* Figure out amount of actual headroom we have */
|
/* Figure out amount of actual headroom we have */
|
||||||
if (!amount_sat_sub(&avail_channel_space, channel_max, their_funding)
|
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);
|
*our_funding = AMOUNT_SAT(0);
|
||||||
return tal_fmt(tmpctx, "No space available in channel."
|
return tal_fmt(tmpctx, "No space available in channel."
|
||||||
" channel_max %s, their_funding %s",
|
" channel_max %s, their_funding %s",
|
||||||
@@ -234,7 +234,7 @@ calculate_our_funding(struct funder_policy *policy,
|
|||||||
* 'reserve_tank' */
|
* 'reserve_tank' */
|
||||||
if (!amount_sat_sub(&net_available_funds, available_funds,
|
if (!amount_sat_sub(&net_available_funds, available_funds,
|
||||||
policy->reserve_tank)
|
policy->reserve_tank)
|
||||||
|| amount_sat_eq(net_available_funds, AMOUNT_SAT(0))) {
|
|| amount_sat_zero(net_available_funds)) {
|
||||||
*our_funding = AMOUNT_SAT(0);
|
*our_funding = AMOUNT_SAT(0);
|
||||||
return tal_fmt(tmpctx, "Reserve tank too low."
|
return tal_fmt(tmpctx, "Reserve tank too low."
|
||||||
" available_funds %s, reserve_tank requires %s",
|
" 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);
|
*our_funding = apply_policy(policy, their_funding, available_funds);
|
||||||
|
|
||||||
/* Don't return an 'error' if we're already at 0 */
|
/* 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;
|
return NULL;
|
||||||
|
|
||||||
/* our_funding is probably sane, so let's fuzz this amount a bit */
|
/* our_funding is probably sane, so let's fuzz this amount a bit */
|
||||||
|
|||||||
Reference in New Issue
Block a user