From 6ab037a9bc4f15f60da4a624017b9318520163dc Mon Sep 17 00:00:00 2001 From: YusukeShimizu Date: Mon, 2 Oct 2023 14:44:09 +0900 Subject: [PATCH] reserve amount is divided from the total amount --- clightning/clightning.go | 22 ++++++++++++---------- lnd/client.go | 6 ++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/clightning/clightning.go b/clightning/clightning.go index 9c554c53..3358da73 100644 --- a/clightning/clightning.go +++ b/clightning/clightning.go @@ -217,21 +217,23 @@ type ListPeerChannelsResponse struct { } type PeerChannel struct { - PeerId string `json:"peer_id"` - PeerConnected bool `json:"peer_connected"` - State string `json:"state"` - ShortChannelId string `json:"short_channel_id,omitempty"` - TotalMsat glightning.Amount `json:"total_msat,omitempty"` - ToUsMsat glightning.Amount `json:"to_us_msat,omitempty"` - ReceivableMsat glightning.Amount `json:"receivable_msat,omitempty"` - SpendableMsat glightning.Amount `json:"spendable_msat,omitempty"` + PeerId string `json:"peer_id"` + PeerConnected bool `json:"peer_connected"` + State string `json:"state"` + ShortChannelId string `json:"short_channel_id,omitempty"` + TotalMsat glightning.Amount `json:"total_msat,omitempty"` + ToUsMsat glightning.Amount `json:"to_us_msat,omitempty"` + ReceivableMsat glightning.Amount `json:"receivable_msat,omitempty"` + SpendableMsat glightning.Amount `json:"spendable_msat,omitempty"` + TheirReserveMsat glightning.Amount `json:"their_reserve_msat,omitempty"` + OurReserveMsat glightning.Amount `json:"our_reserve_msat,omitempty"` } func (ch *PeerChannel) GetSpendableMsat() uint64 { if ch.SpendableMsat.MSat() > 0 { return ch.SpendableMsat.MSat() } else { - return ch.ToUsMsat.MSat() + return ch.ToUsMsat.MSat() - ch.OurReserveMsat.MSat() } } @@ -239,7 +241,7 @@ func (ch *PeerChannel) GetReceivableMsat() uint64 { if ch.ReceivableMsat.MSat() > 0 { return ch.ReceivableMsat.MSat() } else { - return ch.TotalMsat.MSat() - ch.ToUsMsat.MSat() + return ch.TotalMsat.MSat() - ch.ToUsMsat.MSat() - ch.TheirReserveMsat.MSat() } } diff --git a/lnd/client.go b/lnd/client.go index 9e0c5945..7a2bd29d 100644 --- a/lnd/client.go +++ b/lnd/client.go @@ -126,7 +126,8 @@ func (l *Client) SpendableMsat(scid string) (uint64, error) { if err != nil { return 0, err } - spendable := uint64(ch.LocalBalance * 1000) + spendable := (uint64(ch.GetLocalBalance()) - + ch.GetLocalConstraints().GetChanReserveSat()*1000) // since the max htlc limit is not always set reliably, // the check is skipped if it is not set. if maxHtlcAmtMsat == 0 { @@ -162,7 +163,8 @@ func (l *Client) ReceivableMsat(scid string) (uint64, error) { if err != nil { return 0, err } - receivable := uint64(ch.RemoteBalance * 1000) + receivable := (uint64(ch.GetRemoteBalance()) - + ch.GetRemoteConstraints().GetChanReserveSat()*1000) // since the max htlc limit is not always set reliably, // the check is skipped if it is not set. if maxHtlcAmtMsat == 0 {