|
26 | 26 | 'option -u is chosen (so be careful about private keys). ' |
27 | 27 | '(showseed) Shows the wallet recovery seed ' |
28 | 28 | 'and hex seed. (importprivkey) Adds privkeys to this wallet, ' |
29 | | - 'privkeys are spaces or commas separated. (listwallets) Lists ' |
30 | | - 'all wallets with creator and timestamp. (history) Show all ' |
31 | | - 'historical transaction details. Requires Bitcoin Core.') |
| 29 | + 'privkeys are spaces or commas separated. (dumpprivkey) Export ' |
| 30 | + 'a single private key, specify an hd wallet path (listwallets) ' |
| 31 | + 'Lists all wallets with creator and timestamp. (history) Show ' |
| 32 | + 'all historical transaction details. Requires Bitcoin Core.') |
32 | 33 |
|
33 | 34 | parser = OptionParser(usage='usage: %prog [options] [wallet file] [method]', |
34 | 35 | description=description) |
|
69 | 70 | default=False, |
70 | 71 | help=('choose to do fast wallet sync, only for Core and ' |
71 | 72 | 'only for previously synced wallet')) |
| 73 | +parser.add_option('-H', |
| 74 | + '--hd', |
| 75 | + action='store', |
| 76 | + type='str', |
| 77 | + dest='hd_path', |
| 78 | + help='hd wallet path (e.g. m/0/0/0/000)') |
72 | 79 | (options, args) = parser.parse_args() |
73 | 80 |
|
74 | 81 | # if the index_cache stored in wallet.json is longer than the default |
|
82 | 89 | methods = ['display', 'displayall', 'summary', 'showseed', 'importprivkey', |
83 | 90 | 'history', 'showutxos'] |
84 | 91 | methods.extend(noseed_methods) |
85 | | -noscan_methods = ['showseed', 'importprivkey'] |
| 92 | +noscan_methods = ['showseed', 'importprivkey', 'dumpprivkey'] |
86 | 93 |
|
87 | 94 | if len(args) < 1: |
88 | 95 | parser.error('Needs a wallet file or method') |
@@ -252,6 +259,14 @@ def cus_print(s): |
252 | 259 | fd.write(json.dumps(wallet.walletdata)) |
253 | 260 | fd.close() |
254 | 261 | print('Private key(s) successfully imported') |
| 262 | +elif method == 'dumpprivkey': |
| 263 | + if options.hd_path.startswith('m/0/'): |
| 264 | + m, forchange, k = [int(y) for y in options.hd_path[4:].split('/')] |
| 265 | + key = wallet.get_key(m, forchange, k) |
| 266 | + wifkey = btc.wif_compressed_privkey(key, vbyte=get_p2pk_vbyte()) |
| 267 | + print(wifkey) |
| 268 | + else: |
| 269 | + print('%s is not a valid hd wallet path' % options.hd_path) |
255 | 270 | elif method == 'listwallets': |
256 | 271 | # Fetch list of wallets |
257 | 272 | possible_wallets = [] |
|
0 commit comments