def generate_addrs(seed, addrnums, source="addrgen"): from util import make_chksum_8 seed_id = make_chksum_8(seed) # Must do this before seed gets clobbered if 'a' in opt.gen_what: if opt.no_keyconv or test_for_keyconv() == False: msg("Using (slow) internal ECDSA library for address generation") from mmgen.bitcoin import privnum2addr keyconv = False else: from subprocess import check_output keyconv = "keyconv" addrnums = sorted(set(addrnums)) # don't trust the calling function t_addrs,num,pos,out = len(addrnums),0,0,[] w = { 'ka': ('key/address pair','s'), 'k': ('key','s'), 'a': ('address','es') }[opt.gen_what] from mmgen.addr import AddrInfoEntry,AddrInfo while pos != t_addrs: seed = sha512(seed).digest() num += 1 # round if num != addrnums[pos]: continue pos += 1 qmsg_r("\rGenerating %s #%s (%s of %s)" % (w[0],num,pos,t_addrs)) e = AddrInfoEntry() e.idx = num # Secret key is double sha256 of seed hash round /num/ sec = sha256(sha256(seed).digest()).hexdigest() wif = numtowif(int(sec,16)) if 'a' in opt.gen_what: if keyconv: e.addr = check_output([keyconv, wif]).split()[1] else: e.addr = privnum2addr(int(sec,16)) if 'k' in opt.gen_what: e.wif = wif if opt.b16: e.sec = sec out.append(e) m = w[0] if t_addrs == 1 else w[0]+w[1] qmsg("\r%s: %s %s generated%s" % (seed_id,t_addrs,m," "*15)) a = AddrInfo(has_keys='k' in opt.gen_what, source=source) a.initialize(seed_id,out) return a
""", 'notes': """\n This command can also be used to update the comment fields of addresses already in the tracking wallet. """ } cmd_args = opt.opts.init(opts_data) if len(cmd_args) == 1: infile = cmd_args[0] check_infile(infile) if opt.addrlist: lines = get_lines_from_file( infile,"non-{pnm} addresses".format(pnm=g.proj_name),trim_comments=True) ai,adata = AddrInfo(),[] for btcaddr in lines: a = AddrInfoEntry() a.idx,a.addr,a.comment = None,btcaddr,None adata.append(a) ai.initialize(None,adata) else: ai = AddrInfo(infile,has_keys=opt.keyaddr_file) else: msg(""" You must specify an {pnm} address file (or a list of non-{pnm} addresses with the '--addrlist' option) """.strip().format(pnm=g.proj_name)) sys.exit(1) from mmgen.bitcoin import verify_addr