| 644 | } |
| 645 | |
| 646 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 647 | { |
| 648 | struct amount_msat their_msat, receivable; |
| 649 | |
| 650 | /* Compute how much we can receive via this channel in one payment */ |
| 651 | if (!amount_sat_sub_msat(&their_msat, |
| 652 | channel->funding_sats, channel->our_msat)) |
| 653 | their_msat = AMOUNT_MSAT(0); |
| 654 | |
| 655 | if (!amount_msat_sub_sat(&receivable, |
| 656 | their_msat, |
| 657 | channel->our_config.channel_reserve)) |
| 658 | return AMOUNT_MSAT(0); |
| 659 | |
| 660 | /* Take away any currently-offered HTLCs. */ |
| 661 | subtract_received_htlcs(channel, &receivable); |
| 662 | |
| 663 | /* If they're opener, subtract txfees they'll need to spend this */ |
| 664 | if (channel->opener == REMOTE) { |
| 665 | if (!amount_msat_sub_sat(&receivable, receivable, |
| 666 | commit_txfee(channel, |
| 667 | receivable, REMOTE))) |
| 668 | return AMOUNT_MSAT(0); |
| 669 | } |
| 670 | |
| 671 | /* They can't offer an HTLC less than what we will accept. */ |
| 672 | if (amount_msat_less(receivable, channel->our_config.htlc_minimum)) |
| 673 | return AMOUNT_MSAT(0); |
| 674 | |
| 675 | /* They can't offer an HTLC over the max payment threshold either. */ |
| 676 | if (amount_msat_greater(receivable, chainparams->max_payment)) |
| 677 | receivable = chainparams->max_payment; |
| 678 | |
| 679 | return receivable; |
| 680 | } |
| 681 | |
| 682 | static void json_add_channel(struct lightningd *ld, |
| 683 | struct json_stream *response, const char *key, |
no test coverage detected