Skip to content

Commit 7df9222

Browse files
committed
btc: add flag for testnet wallet import outputs
1 parent b5d3485 commit 7df9222

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

btc/bitcoind.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package btc
22

33
import (
44
"fmt"
5+
"github.com/btcsuite/btcd/wire"
56
"io"
67
"time"
78

@@ -135,8 +136,12 @@ func (c *Cli) Format(hdKey *hdkeychain.ExtendedKey, params *chaincfg.Params,
135136
if err != nil {
136137
return "", fmt.Errorf("could not encode WIF: %v", err)
137138
}
138-
return fmt.Sprintf("bitcoin-cli importprivkey %s \"%s/%d/%d/\" false",
139-
wif.String(), path, branch, index), nil
139+
flags := ""
140+
if params.Net == wire.TestNet || params.Net == wire.TestNet3 {
141+
flags = " -testnet"
142+
}
143+
return fmt.Sprintf("bitcoin-cli%s importprivkey %s \"%s/%d/%d/\" false",
144+
flags, wif.String(), path, branch, index), nil
140145
}
141146

142147
func (c *Cli) Trailer(birthdayBlock uint32) string {
@@ -149,15 +154,20 @@ func (c *CliWatchOnly) Header() string {
149154
return "# Paste the following lines into a command line window."
150155
}
151156

152-
func (c *CliWatchOnly) Format(hdKey *hdkeychain.ExtendedKey, _ *chaincfg.Params,
153-
path string, branch, index uint32) (string, error) {
157+
func (c *CliWatchOnly) Format(hdKey *hdkeychain.ExtendedKey,
158+
params *chaincfg.Params, path string, branch, index uint32) (string,
159+
error) {
154160

155161
pubKey, err := hdKey.ECPubKey()
156162
if err != nil {
157163
return "", fmt.Errorf("could not derive private key: %v", err)
158164
}
159-
return fmt.Sprintf("bitcoin-cli importpubkey %x \"%s/%d/%d/\" false",
160-
pubKey.SerializeCompressed(), path, branch, index), nil
165+
flags := ""
166+
if params.Net == wire.TestNet || params.Net == wire.TestNet3 {
167+
flags = " -testnet"
168+
}
169+
return fmt.Sprintf("bitcoin-cli%s importpubkey %x \"%s/%d/%d/\" false",
170+
flags, pubKey.SerializeCompressed(), path, branch, index), nil
161171
}
162172

163173
func (c *CliWatchOnly) Trailer(birthdayBlock uint32) string {

0 commit comments

Comments
 (0)