genimportscript: add addresses to bitcoin-cli-watchonly

pull/51/head
Oliver Gugger 2 years ago
parent bfee0761b6
commit 6f6bf02e62
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -29,22 +29,22 @@ type KeyExporter interface {
// ParseFormat parses the given format name and returns its associated print
// function.
func ParseFormat(format string) KeyExporter {
func ParseFormat(format string) (KeyExporter, error) {
switch format {
default:
fallthrough
case FormatCli:
return &Cli{}
return &Cli{}, nil
case FormatCliWatchOnly:
return &CliWatchOnly{}
return &CliWatchOnly{}, nil
case FormatImportwallet:
return &ImportWallet{}
return &ImportWallet{}, nil
case FormatElectrum:
return &Electrum{}
return &Electrum{}, nil
default:
return nil, fmt.Errorf("invalid format: %s", format)
}
}
@ -166,12 +166,32 @@ func (c *CliWatchOnly) Format(hdKey *hdkeychain.ExtendedKey,
if err != nil {
return "", fmt.Errorf("could not derive private key: %w", err)
}
addrP2PKH, err := lnd.P2PKHAddr(pubKey, params)
if err != nil {
return "", fmt.Errorf("could not create address: %w", err)
}
addrP2WKH, err := lnd.P2WKHAddr(pubKey, params)
if err != nil {
return "", fmt.Errorf("could not create address: %w", err)
}
addrNP2WKH, err := lnd.NP2WKHAddr(pubKey, params)
if err != nil {
return "", fmt.Errorf("could not create address: %w", err)
}
addrP2TR, err := lnd.P2TRAddr(pubKey, params)
if err != nil {
return "", fmt.Errorf("could not create address: %w", err)
}
flags := ""
if params.Net == wire.TestNet || params.Net == wire.TestNet3 {
flags = " -testnet"
}
return fmt.Sprintf("bitcoin-cli%s importpubkey %x \"%s/%d/%d/\" false",
flags, pubKey.SerializeCompressed(), path, branch, index), nil
return fmt.Sprintf("bitcoin-cli%s importpubkey %x \"%s/%d/%d/\" "+
"false # addr=%s,%s,%s,%s", flags, pubKey.SerializeCompressed(),
path, branch, index, addrP2PKH, addrP2WKH, addrNP2WKH,
addrP2TR), nil
}
func (c *CliWatchOnly) Trailer(birthdayBlock uint32) string {

@ -124,6 +124,10 @@ func (c *genImportScriptCommand) Execute(_ *cobra.Command, _ []string) error {
c.DerivationPath = lnd.WalletDefaultDerivationPath
fallthrough
case c.DerivationPath == "-":
strPaths = []string{""}
paths = [][]uint32{{}}
case c.DerivationPath != "":
derivationPath, err := lnd.ParsePath(c.DerivationPath)
if err != nil {
@ -158,7 +162,11 @@ func (c *genImportScriptCommand) Execute(_ *cobra.Command, _ []string) error {
}
}
exporter := btc.ParseFormat(c.Format)
exporter, err := btc.ParseFormat(c.Format)
if err != nil {
return fmt.Errorf("error parsing format: %w", err)
}
err = btc.ExportKeys(
extendedKey, strPaths, paths, chainParams, c.RecoveryWindow,
c.RescanFrom, exporter, writer,

Loading…
Cancel
Save