| 611 | } |
| 612 | |
| 613 | struct amount_msat channel_amount_spendable(const struct channel *channel) |
| 614 | { |
| 615 | struct amount_msat spendable; |
| 616 | |
| 617 | /* Compute how much we can send via this channel in one payment. */ |
| 618 | if (!amount_msat_sub_sat(&spendable, |
| 619 | channel->our_msat, |
| 620 | channel->channel_info.their_config.channel_reserve)) |
| 621 | return AMOUNT_MSAT(0); |
| 622 | |
| 623 | /* Take away any currently-offered HTLCs. */ |
| 624 | subtract_offered_htlcs(channel, &spendable); |
| 625 | |
| 626 | /* If we're opener, subtract txfees we'll need to spend this */ |
| 627 | if (channel->opener == LOCAL) { |
| 628 | if (!amount_msat_sub_sat(&spendable, spendable, |
| 629 | commit_txfee(channel, spendable, |
| 630 | LOCAL))) |
| 631 | return AMOUNT_MSAT(0); |
| 632 | } |
| 633 | |
| 634 | /* We can't offer an HTLC less than the other side will accept. */ |
| 635 | if (amount_msat_less(spendable, |
| 636 | channel->channel_info.their_config.htlc_minimum)) |
| 637 | return AMOUNT_MSAT(0); |
| 638 | |
| 639 | /* We can't offer an HTLC over the max payment threshold either. */ |
| 640 | if (amount_msat_greater(spendable, chainparams->max_payment)) |
| 641 | spendable = chainparams->max_payment; |
| 642 | |
| 643 | return spendable; |
| 644 | } |
| 645 | |
| 646 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 647 | { |
no test coverage detected