mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
fix: return offline channel balance in get_balance nwc call (#1217)
This commit is contained in:
parent
51df96704b
commit
ae87f3a36f
11 changed files with 28 additions and 27 deletions
|
|
@ -694,7 +694,7 @@ func (api *api) GetBalances(ctx context.Context) (*BalancesResponse, error) {
|
|||
if api.svc.GetLNClient() == nil {
|
||||
return nil, errors.New("LNClient not started")
|
||||
}
|
||||
balances, err := api.svc.GetLNClient().GetBalances(ctx)
|
||||
balances, err := api.svc.GetLNClient().GetBalances(ctx, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ func (cs *CashuService) UpdateChannel(ctx context.Context, updateChannelRequest
|
|||
return nil
|
||||
}
|
||||
|
||||
func (cs *CashuService) GetBalances(ctx context.Context) (*lnclient.BalancesResponse, error) {
|
||||
func (cs *CashuService) GetBalances(ctx context.Context, includeInactiveChannels bool) (*lnclient.BalancesResponse, error) {
|
||||
cashuBalance := cs.wallet.GetBalance()
|
||||
balance := int64(cashuBalance * 1000)
|
||||
|
||||
|
|
|
|||
|
|
@ -1624,7 +1624,7 @@ func (ls *LDKService) saveStaticChannelBackupToDisk(event *events.StaticChannels
|
|||
logger.Logger.WithField("backupPath", backupFilePath).Debug("Saved static channel backup to disk")
|
||||
}
|
||||
|
||||
func (ls *LDKService) GetBalances(ctx context.Context) (*lnclient.BalancesResponse, error) {
|
||||
func (ls *LDKService) GetBalances(ctx context.Context, includeInactiveChannels bool) (*lnclient.BalancesResponse, error) {
|
||||
onchainBalance, err := ls.GetOnchainBalance(ctx)
|
||||
if err != nil {
|
||||
logger.Logger.WithError(err).Error("Failed to retrieve onchain balance")
|
||||
|
|
@ -1639,7 +1639,7 @@ func (ls *LDKService) GetBalances(ctx context.Context) (*lnclient.BalancesRespon
|
|||
var nextMaxSpendableMPP int64 = 0
|
||||
channels := ls.node.ListChannels()
|
||||
for _, channel := range channels {
|
||||
if channel.IsUsable {
|
||||
if channel.IsUsable || includeInactiveChannels {
|
||||
// spending or receiving amount may be constrained by channel configuration (e.g. ACINQ does this)
|
||||
channelConstrainedSpendable := min(int64(channel.OutboundCapacityMsat), int64(*channel.CounterpartyOutboundHtlcMaximumMsat))
|
||||
channelConstrainedReceivable := min(int64(channel.InboundCapacityMsat), int64(*channel.InboundHtlcMaximumMsat))
|
||||
|
|
|
|||
|
|
@ -1083,7 +1083,7 @@ func (svc *LNDService) GetLogOutput(ctx context.Context, maxLen int) ([]byte, er
|
|||
return slicedBytes, nil
|
||||
}
|
||||
|
||||
func (svc *LNDService) GetBalances(ctx context.Context) (*lnclient.BalancesResponse, error) {
|
||||
func (svc *LNDService) GetBalances(ctx context.Context, includeInactiveChannels bool) (*lnclient.BalancesResponse, error) {
|
||||
onchainBalance, err := svc.GetOnchainBalance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -1104,7 +1104,7 @@ func (svc *LNDService) GetBalances(ctx context.Context) (*lnclient.BalancesRespo
|
|||
|
||||
for _, channel := range resp.Channels {
|
||||
// Unnecessary since ListChannels only returns active channels
|
||||
if channel.Active {
|
||||
if channel.Active || includeInactiveChannels {
|
||||
channelSpendable := max(channel.LocalBalance*1000-int64(channel.LocalConstraints.ChanReserveSat*1000), 0)
|
||||
channelReceivable := max(channel.RemoteBalance*1000-int64(channel.RemoteConstraints.ChanReserveSat*1000), 0)
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ type LNClient interface {
|
|||
GetNewOnchainAddress(ctx context.Context) (string, error)
|
||||
ResetRouter(key string) error
|
||||
GetOnchainBalance(ctx context.Context) (*OnchainBalanceResponse, error)
|
||||
GetBalances(ctx context.Context) (*BalancesResponse, error)
|
||||
GetBalances(ctx context.Context, includeInactiveChannels bool) (*BalancesResponse, error)
|
||||
RedeemOnchainFunds(ctx context.Context, toAddress string, amount uint64, sendAll bool) (txId string, err error)
|
||||
SendPaymentProbes(ctx context.Context, invoice string) error
|
||||
SendSpontaneousPaymentProbes(ctx context.Context, amountMsat uint64, nodeId string) error
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ func NewPhoenixService(address string, authorization string) (result lnclient.LN
|
|||
return phoenixService, nil
|
||||
}
|
||||
|
||||
func (svc *PhoenixService) GetBalances(ctx context.Context) (*lnclient.BalancesResponse, error) {
|
||||
func (svc *PhoenixService) GetBalances(ctx context.Context, includeInactiveChannels bool) (*lnclient.BalancesResponse, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, svc.Address+"/getbalance", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func (controller *nip47Controller) HandleGetBalanceEvent(ctx context.Context, ni
|
|||
if app.Isolated {
|
||||
balance = queries.GetIsolatedBalance(controller.db, app.ID)
|
||||
} else {
|
||||
balances, err := controller.lnClient.GetBalances(ctx)
|
||||
balances, err := controller.lnClient.GetBalances(ctx, true)
|
||||
balance = balances.Lightning.TotalSpendable
|
||||
if err != nil {
|
||||
logger.Logger.WithFields(logrus.Fields{
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ func (mln *MockLn) CloseChannel(ctx context.Context, closeChannelRequest *lnclie
|
|||
func (mln *MockLn) GetNewOnchainAddress(ctx context.Context) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
func (mln *MockLn) GetBalances(ctx context.Context) (*lnclient.BalancesResponse, error) {
|
||||
func (mln *MockLn) GetBalances(ctx context.Context, includeInactiveChannels bool) (*lnclient.BalancesResponse, error) {
|
||||
return &MockLNClientBalances, nil
|
||||
}
|
||||
func (mln *MockLn) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainBalanceResponse, error) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.52.1. DO NOT EDIT.
|
||||
// Code generated by mockery v2.53.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.52.1. DO NOT EDIT.
|
||||
// Code generated by mockery v2.53.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -234,9 +234,9 @@ func (_c *MockLNClient_ExecuteCustomNodeCommand_Call) RunAndReturn(run func(cont
|
|||
return _c
|
||||
}
|
||||
|
||||
// GetBalances provides a mock function with given fields: ctx
|
||||
func (_m *MockLNClient) GetBalances(ctx context.Context) (*lnclient.BalancesResponse, error) {
|
||||
ret := _m.Called(ctx)
|
||||
// GetBalances provides a mock function with given fields: ctx, includeInactiveChannels
|
||||
func (_m *MockLNClient) GetBalances(ctx context.Context, includeInactiveChannels bool) (*lnclient.BalancesResponse, error) {
|
||||
ret := _m.Called(ctx, includeInactiveChannels)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetBalances")
|
||||
|
|
@ -244,19 +244,19 @@ func (_m *MockLNClient) GetBalances(ctx context.Context) (*lnclient.BalancesResp
|
|||
|
||||
var r0 *lnclient.BalancesResponse
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context) (*lnclient.BalancesResponse, error)); ok {
|
||||
return rf(ctx)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, bool) (*lnclient.BalancesResponse, error)); ok {
|
||||
return rf(ctx, includeInactiveChannels)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context) *lnclient.BalancesResponse); ok {
|
||||
r0 = rf(ctx)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, bool) *lnclient.BalancesResponse); ok {
|
||||
r0 = rf(ctx, includeInactiveChannels)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*lnclient.BalancesResponse)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
|
||||
r1 = rf(ctx)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, bool) error); ok {
|
||||
r1 = rf(ctx, includeInactiveChannels)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
|
@ -271,13 +271,14 @@ type MockLNClient_GetBalances_Call struct {
|
|||
|
||||
// GetBalances is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
func (_e *MockLNClient_Expecter) GetBalances(ctx interface{}) *MockLNClient_GetBalances_Call {
|
||||
return &MockLNClient_GetBalances_Call{Call: _e.mock.On("GetBalances", ctx)}
|
||||
// - includeInactiveChannels bool
|
||||
func (_e *MockLNClient_Expecter) GetBalances(ctx interface{}, includeInactiveChannels interface{}) *MockLNClient_GetBalances_Call {
|
||||
return &MockLNClient_GetBalances_Call{Call: _e.mock.On("GetBalances", ctx, includeInactiveChannels)}
|
||||
}
|
||||
|
||||
func (_c *MockLNClient_GetBalances_Call) Run(run func(ctx context.Context)) *MockLNClient_GetBalances_Call {
|
||||
func (_c *MockLNClient_GetBalances_Call) Run(run func(ctx context.Context, includeInactiveChannels bool)) *MockLNClient_GetBalances_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context))
|
||||
run(args[0].(context.Context), args[1].(bool))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
|
@ -287,7 +288,7 @@ func (_c *MockLNClient_GetBalances_Call) Return(_a0 *lnclient.BalancesResponse,
|
|||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockLNClient_GetBalances_Call) RunAndReturn(run func(context.Context) (*lnclient.BalancesResponse, error)) *MockLNClient_GetBalances_Call {
|
||||
func (_c *MockLNClient_GetBalances_Call) RunAndReturn(run func(context.Context, bool) (*lnclient.BalancesResponse, error)) *MockLNClient_GetBalances_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.52.1. DO NOT EDIT.
|
||||
// Code generated by mockery v2.53.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue