lnrpc: extract rpcCommitmentType

This commit is contained in:
Joost Jager 2020-03-30 20:35:24 +02:00
parent f996203883
commit 41573004a3
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

View File

@ -3220,6 +3220,23 @@ func (r *rpcServer) ListChannels(ctx context.Context,
return resp, nil
}
// rpcCommitmentType takes the channel type and converts it to an rpc commitment
// type value.
func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
// Extract the commitment type from the channel type flags. We must
// first check whether it has anchors, since in that case it would also
// be tweakless.
if chanType.HasAnchors() {
return lnrpc.CommitmentType_ANCHORS
}
if chanType.IsTweakless() {
return lnrpc.CommitmentType_STATIC_REMOTE_KEY
}
return lnrpc.CommitmentType_LEGACY
}
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
dbChannel *channeldb.OpenChannel, isActive bool) (*lnrpc.Channel, error) {
@ -3257,15 +3274,8 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
}
externalCommitFee := dbChannel.Capacity - sumOutputs
// Extract the commitment type from the channel type flags. We must
// first check whether it has anchors, since in that case it would also
// be tweakless.
commitmentType := lnrpc.CommitmentType_LEGACY
if dbChannel.ChanType.HasAnchors() {
commitmentType = lnrpc.CommitmentType_ANCHORS
} else if dbChannel.ChanType.IsTweakless() {
commitmentType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
}
// Extract the commitment type from the channel type flags.
commitmentType := rpcCommitmentType(dbChannel.ChanType)
channel := &lnrpc.Channel{
Active: isActive,