56
56
type walletInfoCommand struct {
57
57
WalletDB string
58
58
WithRootKey bool
59
+ DumpAddrs bool
59
60
60
61
cmd * cobra.Command
61
62
}
@@ -85,6 +86,10 @@ in the wallet.db.`,
85
86
& cc .WithRootKey , "withrootkey" , false , "print BIP32 HD root " +
86
87
"key of wallet to standard out" ,
87
88
)
89
+ cc .cmd .Flags ().BoolVar (
90
+ & cc .DumpAddrs , "dumpaddrs" , false , "print all addresses, " +
91
+ "including private keys" ,
92
+ )
88
93
89
94
return cc .cmd
90
95
}
@@ -161,7 +166,7 @@ func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error {
161
166
}
162
167
163
168
// Print the wallet info and if requested the root key.
164
- identityKey , scopeInfo , err := walletInfo (w )
169
+ identityKey , scopeInfo , err := walletInfo (w , c . DumpAddrs )
165
170
if err != nil {
166
171
return err
167
172
}
@@ -187,7 +192,9 @@ func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error {
187
192
return nil
188
193
}
189
194
190
- func walletInfo (w * wallet.Wallet ) (* btcec.PublicKey , string , error ) {
195
+ func walletInfo (w * wallet.Wallet , dumpAddrs bool ) (* btcec.PublicKey , string ,
196
+ error ) {
197
+
191
198
keyRing := keychain .NewBtcWalletKeyRing (w , chainParams .HDCoinType )
192
199
idPrivKey , err := keyRing .DerivePrivKey (keychain.KeyDescriptor {
193
200
KeyLocator : keychain.KeyLocator {
@@ -218,7 +225,38 @@ func walletInfo(w *wallet.Wallet) (*btcec.PublicKey, string, error) {
218
225
return nil , "" , err
219
226
}
220
227
221
- return idPrivKey .PubKey (), scopeNp2wkh + scopeP2wkh , nil
228
+ scopeAddrs := "\n "
229
+ if dumpAddrs {
230
+ printAddr := func (a waddrmgr.ManagedAddress ) error {
231
+ pka := a .(waddrmgr.ManagedPubKeyAddress )
232
+ scope , path , _ := pka .DerivationInfo ()
233
+ scopeAddrs += fmt .Sprintf (
234
+ "path=m/%d'/%d'/%d'/%d/%d, pubkey=%x, " +
235
+ "addr=%s, hash160=%x\n " ,
236
+ scope .Purpose , scope .Coin , path .InternalAccount ,
237
+ path .Branch , path .Index ,
238
+ pka .PubKey ().SerializeCompressed (),
239
+ pka .Address ().String (), a .AddrHash (),
240
+ )
241
+ return nil
242
+ }
243
+ for _ , mgr := range w .Manager .ActiveScopedKeyManagers () {
244
+ err = walletdb .View (
245
+ w .Database (), func (tx walletdb.ReadTx ) error {
246
+
247
+ waddrmgrNs := tx .ReadBucket (
248
+ waddrmgrNamespaceKey ,
249
+ )
250
+
251
+ return mgr .ForEachAccountAddress (
252
+ waddrmgrNs , 0 , printAddr ,
253
+ )
254
+ },
255
+ )
256
+ }
257
+ }
258
+
259
+ return idPrivKey .PubKey (), scopeNp2wkh + scopeP2wkh + scopeAddrs , nil
222
260
}
223
261
224
262
func printScopeInfo (name string , w * wallet.Wallet ,
0 commit comments