1 回答
TA贡献1872条经验 获得超3个赞
你打了privtopub(priv)两次电话。这将节省一个fast_multiply可能是整个程序中最慢的函数的调用。
我建议先做:
pub = privtopub(priv)
addr_u = pubtoaddr(pub)
addr_c = pubtoaddr(compress(pub))
然后我建议使用multiprocessing.Pool:
import argparse
from pybitcointools import *
def convert(line):
priv = sha256(line.rstrip())
wif_u = encode_privkey(priv, 'wif')
wif_c = encode_privkey(priv, 'wif_compressed')
pub = privtopub(priv)
addr_u = pubtoaddr(pub)
addr_c = pubtoaddr(compress(pub))
return (addr_u, wif_u, addr_c, addr_u)
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('filename')
args = parser.parse_args()
pool = multiprocessing.Pool()
with open(args.filename) as textfile:
for addr_u, wif_u, addr_c, addr_u in pool.imap(convert, textfile):
print("%s,%s" % (addr_u, wif_u))
print("%s,%s" % (addr_c, wif_c))
添加回答
举报