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 // ParseFormat parses the given format name and returns its associated print
// function. // function.
func ParseFormat(format string) KeyExporter { func ParseFormat(format string) (KeyExporter, error) {
switch format { switch format {
default:
fallthrough
case FormatCli: case FormatCli:
return &Cli{} return &Cli{}, nil
case FormatCliWatchOnly: case FormatCliWatchOnly:
return &CliWatchOnly{} return &CliWatchOnly{}, nil
case FormatImportwallet: case FormatImportwallet:
return &ImportWallet{} return &ImportWallet{}, nil
case FormatElectrum: 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 { if err != nil {
return "", fmt.Errorf("could not derive private key: %w", err) 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 := "" flags := ""
if params.Net == wire.TestNet || params.Net == wire.TestNet3 { if params.Net == wire.TestNet || params.Net == wire.TestNet3 {
flags = " -testnet" flags = " -testnet"
} }
return fmt.Sprintf("bitcoin-cli%s importpubkey %x \"%s/%d/%d/\" false", return fmt.Sprintf("bitcoin-cli%s importpubkey %x \"%s/%d/%d/\" "+
flags, pubKey.SerializeCompressed(), path, branch, index), nil "false # addr=%s,%s,%s,%s", flags, pubKey.SerializeCompressed(),
path, branch, index, addrP2PKH, addrP2WKH, addrNP2WKH,
addrP2TR), nil
} }
func (c *CliWatchOnly) Trailer(birthdayBlock uint32) string { func (c *CliWatchOnly) Trailer(birthdayBlock uint32) string {

@ -124,6 +124,10 @@ func (c *genImportScriptCommand) Execute(_ *cobra.Command, _ []string) error {
c.DerivationPath = lnd.WalletDefaultDerivationPath c.DerivationPath = lnd.WalletDefaultDerivationPath
fallthrough fallthrough
case c.DerivationPath == "-":
strPaths = []string{""}
paths = [][]uint32{{}}
case c.DerivationPath != "": case c.DerivationPath != "":
derivationPath, err := lnd.ParsePath(c.DerivationPath) derivationPath, err := lnd.ParsePath(c.DerivationPath)
if err != nil { 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( err = btc.ExportKeys(
extendedKey, strPaths, paths, chainParams, c.RecoveryWindow, extendedKey, strPaths, paths, chainParams, c.RecoveryWindow,
c.RescanFrom, exporter, writer, c.RescanFrom, exporter, writer,

Loading…
Cancel
Save