rpc: compute and display blocks left till channel open in PendingChannels

This commit is contained in:
Olaoluwa Osuntokun 2017-12-02 18:41:41 -08:00
parent c57eda4c6d
commit ad71a62b96
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1246,6 +1246,11 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
} }
} }
_, bestHeight, err := r.server.cc.chainIO.GetBestBlock()
if err != nil {
return nil, err
}
rpcsLog.Debugf("[pendingchannels]") rpcsLog.Debugf("[pendingchannels]")
resp := &lnrpc.PendingChannelResponse{} resp := &lnrpc.PendingChannelResponse{}
@ -1274,6 +1279,8 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
commitBaseWeight := blockchain.GetTransactionWeight(utx) commitBaseWeight := blockchain.GetTransactionWeight(utx)
commitWeight := commitBaseWeight + lnwallet.WitnessCommitmentTxWeight commitWeight := commitBaseWeight + lnwallet.WitnessCommitmentTxWeight
targetConfHeight := pendingChan.FundingBroadcastHeight + uint32(pendingChan.NumConfsRequired)
blocksTillOpen := int32(targetConfHeight) - bestHeight
resp.PendingOpenChannels[i] = &lnrpc.PendingChannelResponse_PendingOpenChannel{ resp.PendingOpenChannels[i] = &lnrpc.PendingChannelResponse_PendingOpenChannel{
Channel: &lnrpc.PendingChannelResponse_PendingChannel{ Channel: &lnrpc.PendingChannelResponse_PendingChannel{
RemoteNodePub: hex.EncodeToString(pub), RemoteNodePub: hex.EncodeToString(pub),
@ -1285,6 +1292,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
CommitWeight: commitWeight, CommitWeight: commitWeight,
CommitFee: int64(localCommitment.CommitFee), CommitFee: int64(localCommitment.CommitFee),
FeePerKw: int64(localCommitment.FeePerKw), FeePerKw: int64(localCommitment.FeePerKw),
BlocksTillOpen: blocksTillOpen,
// TODO(roasbeef): need to track confirmation height // TODO(roasbeef): need to track confirmation height
} }
} }