@@ -2,6 +2,7 @@ package btc
22
33import (
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
142147func (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
163173func (c * CliWatchOnly ) Trailer (birthdayBlock uint32 ) string {
0 commit comments