mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
rpcserver: fetch balance for ChannelBalance from disk
This commit modifies the ChannelBalance RPC to fetch the balance from disk since channels are now able to efficiently retrieved from disk due to recent index that have been added. Previously this RPC would only return accurate information if we had an active connection to the counter party for each channel.
This commit is contained in:
11
rpcserver.go
11
rpcserver.go
@@ -479,11 +479,14 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
|
||||
func (r *rpcServer) ChannelBalance(ctx context.Context,
|
||||
in *lnrpc.ChannelBalanceRequest) (*lnrpc.ChannelBalanceResponse, error) {
|
||||
|
||||
channels, err := r.server.chanDB.FetchAllChannels()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var balance btcutil.Amount
|
||||
for _, peer := range r.server.Peers() {
|
||||
for _, snapshot := range peer.ChannelSnapshots() {
|
||||
balance += snapshot.LocalBalance
|
||||
}
|
||||
for _, channel := range channels {
|
||||
balance += channel.OurBalance
|
||||
}
|
||||
|
||||
return &lnrpc.ChannelBalanceResponse{Balance: int64(balance)}, nil
|
||||
|
Reference in New Issue
Block a user