rpcserver: include upfront shutdown script in ListChannels response

This field could be omitted from the response if we were unable to
calculate the channel's uptime.
This commit is contained in:
Wilmer Paulino 2020-04-10 18:26:31 -07:00
parent b947ed552a
commit 17ca1d78f0
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

View File

@ -3299,6 +3299,25 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
channel.PushAmountSat = uint64(localBalance.ToSatoshis())
}
if len(dbChannel.LocalShutdownScript) > 0 {
_, addresses, _, err := txscript.ExtractPkScriptAddrs(
dbChannel.LocalShutdownScript, activeNetParams.Params,
)
if err != nil {
return nil, err
}
// We only expect one upfront shutdown address for a channel. If
// LocalShutdownScript is non-zero, there should be one payout
// address set.
if len(addresses) != 1 {
return nil, fmt.Errorf("expected one upfront shutdown "+
"address, got: %v", len(addresses))
}
channel.CloseAddress = addresses[0].String()
}
outpoint := dbChannel.FundingOutpoint
// Get the lifespan observed by the channel event store. If the channel is
@ -3336,25 +3355,6 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
}
channel.Uptime = int64(uptime.Seconds())
if len(dbChannel.LocalShutdownScript) > 0 {
_, addresses, _, err := txscript.ExtractPkScriptAddrs(
dbChannel.LocalShutdownScript, activeNetParams.Params,
)
if err != nil {
return nil, err
}
// We only expect one upfront shutdown address for a channel. If
// LocalShutdownScript is non-zero, there should be one payout address
// set.
if len(addresses) != 1 {
return nil, fmt.Errorf("expected one upfront shutdown address, "+
"got: %v", len(addresses))
}
channel.CloseAddress = addresses[0].String()
}
return channel, nil
}