2
0
mirror of https://github.com/guggero/chantools synced 2024-11-11 01:10:42 +00:00
chantools/dump.go
2020-01-03 11:30:18 +01:00

58 lines
1.5 KiB
Go

package chantools
import (
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/keychain"
)
const (
lndInternalDerivationPath = "m/1017'/0'/%d'/0/%d"
)
// dumpChanCfg is the information we want to dump from a channel configuration.
// See `channeldb.ChannelConfig` for more information about the fields.
type dumpChanCfg struct {
channeldb.ChannelConstraints
MultiSigKey dumpDescriptor
RevocationBasePoint dumpDescriptor
PaymentBasePoint dumpDescriptor
DelayBasePoint dumpDescriptor
HtlcBasePoint dumpDescriptor
}
type dumpDescriptor struct {
Path string
Pubkey string
}
func toDumpChanCfg(cfg channeldb.ChannelConfig) dumpChanCfg {
return dumpChanCfg{
ChannelConstraints: cfg.ChannelConstraints,
MultiSigKey: toDumpDescriptor(cfg.MultiSigKey),
RevocationBasePoint: toDumpDescriptor(cfg.RevocationBasePoint),
PaymentBasePoint: toDumpDescriptor(cfg.PaymentBasePoint),
DelayBasePoint: toDumpDescriptor(cfg.DelayBasePoint),
HtlcBasePoint: toDumpDescriptor(cfg.HtlcBasePoint),
}
}
func toDumpDescriptor(desc keychain.KeyDescriptor) dumpDescriptor {
return dumpDescriptor{
Path: fmt.Sprintf(
lndInternalDerivationPath, desc.Family, desc.Index,
),
Pubkey: pubKeyToString(desc.PubKey),
}
}
func pubKeyToString(pubkey *btcec.PublicKey) string {
if pubkey == nil {
return "<nil>"
}
return hex.EncodeToString(pubkey.SerializeCompressed())
}