Add RPC to show current total available channel capacity #29 (#35)

This commit adds a new RPC command: `channelbalance` which returns the
sum of all available channel capacity across all open channels. The
total balance is currently returned in units of `satoshis`. Additionally
the `networkHarness` has been modified slightly to allow specifying the
additional "extra" command line parameters when creating the initial
seed nodes. Minor refactoring within the integration tests has been
undertaken in order to increase code re-use across tests.

Closes #29.
This commit is contained in:
andrew.shvv
2016-09-15 22:59:51 +04:00
committed by Olaoluwa Osuntokun
parent 4c01e42670
commit 2788dbeaa8
9 changed files with 415 additions and 239 deletions

View File

@ -385,6 +385,20 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
return &lnrpc.WalletBalanceResponse{balance.ToBTC()}, nil
}
func (r *rpcServer) ChannelBalance(ctx context.Context,
in *lnrpc.ChannelBalanceRequest) (*lnrpc.ChannelBalanceResponse, error) {
var balance btcutil.Amount
for _, peer := range r.server.Peers() {
for _, snapshot := range peer.ChannelSnapshots() {
balance += snapshot.LocalBalance
}
}
return &lnrpc.ChannelBalanceResponse{Balance: int64(balance)}, nil
}
// PendingChannels returns a list of all the channels that are currently
// considered "pending". A channel is pending if it has finished the funding
// workflow and is waiting for confirmations for the funding txn, or is in the