Skip to content

Commit

Permalink
reserve amount is divided from the total amount
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeShimizu committed Oct 2, 2023
1 parent b798f6a commit 6ab037a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 12 additions & 10 deletions clightning/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,29 +217,31 @@ 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()
}
}

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()
}
}

Expand Down
6 changes: 4 additions & 2 deletions lnd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6ab037a

Please sign in to comment.