Wallet.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:Skynet2.0 作者: Skynet2-0 项目源码 文件源码
def _create_wallet(self):
        print('did not find an existing wallet, creating a new one')
        #ensure the daemon is stopped, as this causes path errors (mostly usefull for development)
        pexpect.run('electrum daemon stop')
        #build a new wallet if no wallet yet exists
        walletpair=str(subprocess.check_output('python addrgen/addrgen.py',shell=True))
        walletpair = re.split('\W+', walletpair)

        self.address = walletpair[1]
        self.privkey = walletpair[2]
        print('created a wallet with address \''+self.address+'\' and privatekey \''+self.privkey+'\'')
        child = pexpect.spawn('electrum', ['restore', self.privkey])
        #respectively: use default password, use default fee (0.002), use default gap limit and give seed
        self._answer_prompt(child, '')

        #check if wallet was created succesfulyl
        command = """electrum listaddresses"""
        output = pexpect.run(command)

        walletFinder = re.compile(r'\[\W*"([A-z0-9]+)"\W*\]')

        result = walletFinder.search(output)

        #This horrible feedback loop is here due to a quirk of electrum.
        #Needs refactoring, but do not refactor without extensive testing (i.e. multiple vps all from clean install)
        #Because electrum behaviour right after startup tends to differ from server to server (i suspect something to do wtih specs)
        try:
            print result.group(1)
            return result.group(1)
        except:
            return self._create_wallet()



    # def __del__(self):
    #     '''
    #     clear up the electrum service
    #     '''
    #     subprocess.call(['electrum', 'daemon', 'stop'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号