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:
Olaoluwa Osuntokun
2016-11-11 15:48:15 -08:00
parent 7fc6159f0a
commit d545afa5fe

View File

@@ -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