Add --label and --reserve options

This commit is contained in:
jackjack 2011-07-25 00:13:15 +02:00
parent ebcac3c888
commit 70d506ff00
2 changed files with 16 additions and 13 deletions

6
README
View File

@ -6,5 +6,9 @@ Options:
--dumpwallet dump wallet in json format
--importprivkey=KEY import private key from vanitygen
--datadir=DATADIR wallet directory (defaults to bitcoin default)
--wallet=WALLETFILE wallet filename (defaults to wallet.dat)
--label=LABEL label shown in the adress book (defaults to '')
--testnet use testnet subdirectory and address type
--wallet wallet filename (defaults to wallet.dat)
--reserve import as a reserve key, i.e. it won't show in the
adress book

View File

@ -3,15 +3,6 @@
# pywallet.py 1.1
# based on http://github.com/gavinandresen/bitcointools
#
# Usage: pywallet.py [options]
#
# Options:
# --version show program's version number and exit
# -h, --help show this help message and exit
# --dumpwallet dump wallet in json format
# --importprivkey=KEY import private key from vanitygen
# --datadir=DATADIR wallet directory (defaults to bitcoin default)
# --testnet use testnet subdirectory and address type
from bsddb.db import *
import os, sys, time
@ -782,7 +773,7 @@ def read_wallet(json_db, db_env, walletfile, print_wallet, print_wallet_transact
del(json_db['pool'])
del(json_db['names'])
def importprivkey(db, sec):
def importprivkey(db, sec, label, reserve):
pkey = regenerate_key(sec)
if not pkey:
return False
@ -796,7 +787,8 @@ def importprivkey(db, sec):
print "Privkey: %s" % SecretToASecret(secret)
update_wallet(db, 'key', { 'public_key' : public_key, 'private_key' : private_key })
update_wallet(db, 'name', { 'hash' : addr, 'name' : '' })
if not reserve:
update_wallet(db, 'name', { 'hash' : addr, 'name' : label })
return True
@ -821,9 +813,16 @@ def main():
help="wallet filename (defaults to wallet.dat)",
default="wallet.dat")
parser.add_option("--label", dest="label",
help="label shown in the adress book (defaults to '')",
default="")
parser.add_option("--testnet", dest="testnet", action="store_true",
help="use testnet subdirectory and address type")
parser.add_option("--reserve", dest="reserve", action="store_true",
help="import as a reserve key, i.e. it won't show in the adress book")
(options, args) = parser.parse_args()
if options.dump is None and options.key is None:
@ -854,7 +853,7 @@ def main():
else:
db = open_wallet(db_env, options.walletfile, writable=True)
if importprivkey(db, options.key):
if importprivkey(db, options.key, options.label, options.reserve):
print "Imported successfully"
else:
print "Bad private key"