mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01: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:
parent
7fc6159f0a
commit
d545afa5fe
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
|
||||
|
Loading…
Reference in New Issue
Block a user