mirror of
https://github.com/guggero/chantools
synced 2024-11-11 01:10:42 +00:00
Add closed channels to dumpchannels command
This commit is contained in:
parent
3a8d95c4ba
commit
a95f475c6a
@ -46,7 +46,8 @@ func (c *chanBackupCommand) Execute(_ []string) error {
|
|||||||
return fmt.Errorf("channel DB is required")
|
return fmt.Errorf("channel DB is required")
|
||||||
}
|
}
|
||||||
db, err := channeldb.Open(
|
db, err := channeldb.Open(
|
||||||
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
|
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
|
||||||
|
channeldb.OptionSetSyncFreelist(true),
|
||||||
channeldb.OptionReadOnly(true),
|
channeldb.OptionReadOnly(true),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
type dumpChannelsCommand struct {
|
type dumpChannelsCommand struct {
|
||||||
ChannelDB string `long:"channeldb" description:"The lnd channel.db file to dump the channels from."`
|
ChannelDB string `long:"channeldb" description:"The lnd channel.db file to dump the channels from."`
|
||||||
|
Closed bool `long:"closed" description:"Dump all closed channels instead of all open channels."`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *dumpChannelsCommand) Execute(_ []string) error {
|
func (c *dumpChannelsCommand) Execute(_ []string) error {
|
||||||
@ -21,22 +22,27 @@ func (c *dumpChannelsCommand) Execute(_ []string) error {
|
|||||||
return fmt.Errorf("channel DB is required")
|
return fmt.Errorf("channel DB is required")
|
||||||
}
|
}
|
||||||
db, err := channeldb.Open(
|
db, err := channeldb.Open(
|
||||||
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
|
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
|
||||||
|
channeldb.OptionSetSyncFreelist(true),
|
||||||
channeldb.OptionReadOnly(true),
|
channeldb.OptionReadOnly(true),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error opening rescue DB: %v", err)
|
return fmt.Errorf("error opening rescue DB: %v", err)
|
||||||
}
|
}
|
||||||
return dumpChannelInfo(db)
|
|
||||||
|
if c.Closed {
|
||||||
|
return dumpClosedChannelInfo(db)
|
||||||
|
}
|
||||||
|
return dumpOpenChannelInfo(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpChannelInfo(chanDb *channeldb.DB) error {
|
func dumpOpenChannelInfo(chanDb *channeldb.DB) error {
|
||||||
channels, err := chanDb.FetchAllChannels()
|
channels, err := chanDb.FetchAllChannels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dumpChannels, err := dump.ChannelDump(channels, chainParams)
|
dumpChannels, err := dump.OpenChannelDump(channels, chainParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error converting to dump format: %v", err)
|
return fmt.Errorf("error converting to dump format: %v", err)
|
||||||
}
|
}
|
||||||
@ -44,3 +50,18 @@ func dumpChannelInfo(chanDb *channeldb.DB) error {
|
|||||||
spew.Dump(dumpChannels)
|
spew.Dump(dumpChannels)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dumpClosedChannelInfo(chanDb *channeldb.DB) error {
|
||||||
|
channels, err := chanDb.FetchClosedChannels(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dumpChannels, err := dump.ClosedChannelDump(channels, chainParams)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error converting to dump format: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
spew.Dump(dumpChannels)
|
||||||
|
return nil
|
||||||
|
}
|
@ -50,7 +50,8 @@ func (c *forceCloseCommand) Execute(_ []string) error {
|
|||||||
return fmt.Errorf("rescue DB is required")
|
return fmt.Errorf("rescue DB is required")
|
||||||
}
|
}
|
||||||
db, err := channeldb.Open(
|
db, err := channeldb.Open(
|
||||||
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
|
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
|
||||||
|
channeldb.OptionSetSyncFreelist(true),
|
||||||
channeldb.OptionReadOnly(true),
|
channeldb.OptionReadOnly(true),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defaultAPIURL = "https://blockstream.info/api"
|
defaultAPIURL = "https://blockstream.info/api"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -170,7 +170,7 @@ func parseInputType(cfg *config) ([]*dataformat.SummaryEntry, error) {
|
|||||||
|
|
||||||
case cfg.FromChannelDB != "":
|
case cfg.FromChannelDB != "":
|
||||||
db, err := channeldb.Open(
|
db, err := channeldb.Open(
|
||||||
path.Dir(cfg.FromChannelDB),
|
path.Dir(cfg.FromChannelDB), path.Base(cfg.FromChannelDB),
|
||||||
channeldb.OptionSetSyncFreelist(true),
|
channeldb.OptionSetSyncFreelist(true),
|
||||||
channeldb.OptionReadOnly(true),
|
channeldb.OptionReadOnly(true),
|
||||||
)
|
)
|
||||||
|
@ -61,7 +61,8 @@ func (c *rescueClosedCommand) Execute(_ []string) error {
|
|||||||
return fmt.Errorf("rescue DB is required")
|
return fmt.Errorf("rescue DB is required")
|
||||||
}
|
}
|
||||||
db, err := channeldb.Open(
|
db, err := channeldb.Open(
|
||||||
path.Dir(c.ChannelDB), channeldb.OptionSetSyncFreelist(true),
|
path.Dir(c.ChannelDB), path.Base(c.ChannelDB),
|
||||||
|
channeldb.OptionSetSyncFreelist(true),
|
||||||
channeldb.OptionReadOnly(true),
|
channeldb.OptionReadOnly(true),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
63
dump/dump.go
63
dump/dump.go
@ -73,6 +73,26 @@ type OpenChannel struct {
|
|||||||
RemoteShutdownScript lnwire.DeliveryAddress
|
RemoteShutdownScript lnwire.DeliveryAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClosedChannel is the information we want to dump from a closed channel in
|
||||||
|
// lnd's channel DB. See `channeldb.ChannelCloseSummary` for information about
|
||||||
|
// the fields.
|
||||||
|
type ClosedChannel struct {
|
||||||
|
ChanPoint string
|
||||||
|
ShortChanID lnwire.ShortChannelID
|
||||||
|
ChainHash chainhash.Hash
|
||||||
|
ClosingTXID string
|
||||||
|
RemotePub string
|
||||||
|
Capacity btcutil.Amount
|
||||||
|
CloseHeight uint32
|
||||||
|
SettledBalance btcutil.Amount
|
||||||
|
TimeLockedBalance btcutil.Amount
|
||||||
|
CloseType string
|
||||||
|
IsPending bool
|
||||||
|
RemoteCurrentRevocation string
|
||||||
|
RemoteNextRevocation string
|
||||||
|
LocalChanConfig ChannelConfig
|
||||||
|
}
|
||||||
|
|
||||||
// ChannelConfig is the information we want to dump from a channel
|
// ChannelConfig is the information we want to dump from a channel
|
||||||
// configuration. See `channeldb.ChannelConfig` for more information about the
|
// configuration. See `channeldb.ChannelConfig` for more information about the
|
||||||
// fields.
|
// fields.
|
||||||
@ -92,10 +112,10 @@ type KeyDescriptor struct {
|
|||||||
PubKey string
|
PubKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelDump converts the channels in the given channel DB into a dumpable
|
// OpenChannelDump converts the open channels in the given channel DB into a
|
||||||
// format.
|
// dumpable format.
|
||||||
func ChannelDump(channels []*channeldb.OpenChannel, params *chaincfg.Params) (
|
func OpenChannelDump(channels []*channeldb.OpenChannel,
|
||||||
[]OpenChannel, error) {
|
params *chaincfg.Params) ([]OpenChannel, error) {
|
||||||
|
|
||||||
dumpChannels := make([]OpenChannel, len(channels))
|
dumpChannels := make([]OpenChannel, len(channels))
|
||||||
for idx, channel := range channels {
|
for idx, channel := range channels {
|
||||||
@ -154,6 +174,41 @@ func ChannelDump(channels []*channeldb.OpenChannel, params *chaincfg.Params) (
|
|||||||
return dumpChannels, nil
|
return dumpChannels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClosedChannelDump converts the closed channels in the given channel DB into a
|
||||||
|
// dumpable format.
|
||||||
|
func ClosedChannelDump(channels []*channeldb.ChannelCloseSummary,
|
||||||
|
params *chaincfg.Params) ([]ClosedChannel, error) {
|
||||||
|
|
||||||
|
dumpChannels := make([]ClosedChannel, len(channels))
|
||||||
|
for idx, channel := range channels {
|
||||||
|
dumpChannels[idx] = ClosedChannel{
|
||||||
|
ChanPoint: channel.ChanPoint.String(),
|
||||||
|
ShortChanID: channel.ShortChanID,
|
||||||
|
ChainHash: channel.ChainHash,
|
||||||
|
ClosingTXID: channel.ClosingTXID.String(),
|
||||||
|
RemotePub: PubKeyToString(channel.RemotePub),
|
||||||
|
Capacity: channel.Capacity,
|
||||||
|
CloseHeight: channel.CloseHeight,
|
||||||
|
SettledBalance: channel.SettledBalance,
|
||||||
|
TimeLockedBalance: channel.TimeLockedBalance,
|
||||||
|
CloseType: fmt.Sprintf(
|
||||||
|
"%d", channel.CloseType,
|
||||||
|
),
|
||||||
|
IsPending: channel.IsPending,
|
||||||
|
RemoteCurrentRevocation: PubKeyToString(
|
||||||
|
channel.RemoteCurrentRevocation,
|
||||||
|
),
|
||||||
|
RemoteNextRevocation: PubKeyToString(
|
||||||
|
channel.RemoteNextRevocation,
|
||||||
|
),
|
||||||
|
LocalChanConfig: ToChannelConfig(
|
||||||
|
params, channel.LocalChanConfig,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dumpChannels, nil
|
||||||
|
}
|
||||||
|
|
||||||
// BackupDump converts the given multi backup into a dumpable format.
|
// BackupDump converts the given multi backup into a dumpable format.
|
||||||
func BackupDump(multi *chanbackup.Multi, params *chaincfg.Params) []BackupSingle {
|
func BackupDump(multi *chanbackup.Multi, params *chaincfg.Params) []BackupSingle {
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -21,6 +21,6 @@ require (
|
|||||||
gopkg.in/yaml.v2 v2.2.3 // indirect
|
gopkg.in/yaml.v2 v2.2.3 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/lightningnetwork/lnd => github.com/guggero/lnd v0.9.0-beta-rc1.0.20200307101759-2650bff06031
|
replace github.com/lightningnetwork/lnd => github.com/guggero/lnd v0.9.0-beta-rc4.0.20200826102054-8c9171307182
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
4
go.sum
4
go.sum
@ -97,8 +97,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
|
|||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.8.6 h1:XvND7+MPP7Jp+JpqSZ7naSl5nVZf6k0LbL1V3EKh0zc=
|
github.com/grpc-ecosystem/grpc-gateway v1.8.6 h1:XvND7+MPP7Jp+JpqSZ7naSl5nVZf6k0LbL1V3EKh0zc=
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.8.6/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
github.com/grpc-ecosystem/grpc-gateway v1.8.6/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||||
github.com/guggero/lnd v0.9.0-beta-rc1.0.20200307101759-2650bff06031 h1:G7UpjWLXdmFi1gYVidq6c/EJaH/eX0HixAOVxxAT/K0=
|
github.com/guggero/lnd v0.9.0-beta-rc4.0.20200826102054-8c9171307182 h1:VMQ3vCjVGhT1k1agfGMEDbtqtw6xpXGfgO3xaQ/TyLM=
|
||||||
github.com/guggero/lnd v0.9.0-beta-rc1.0.20200307101759-2650bff06031/go.mod h1:bMBXSbO0hwk9HmZSbI04SDTHxTK/iEOvzfzQkNSIJmU=
|
github.com/guggero/lnd v0.9.0-beta-rc4.0.20200826102054-8c9171307182/go.mod h1:bMBXSbO0hwk9HmZSbI04SDTHxTK/iEOvzfzQkNSIJmU=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
|
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
|
||||||
|
Loading…
Reference in New Issue
Block a user