Esempio n. 1
0
def new_wallet_from_data(data, file_name):
    print("Creating new wallet file.")
    new_pw = cli_get_wallet_passphrase_check()
    if new_pw is False:
        return False

    storage = Storage(file_name, create=True, password=new_pw)
    wallet_cls = get_wallet_cls(wtype=get_configured_wallet_type(False))

    kwdata = {
        'entropy': data['entropy'],
        'timestamp': data.get('creation_time'),
        'max_mixdepth': get_max_mixdepth(data)
    }

    if 'entropy_ext' in data:
        kwdata['entropy_extension'] = data['entropy_ext']

    wallet_cls.initialize(storage, data['network'], **kwdata)
    wallet = wallet_cls(storage)

    if 'index_cache' in data:
        for md, indices in enumerate(data['index_cache']):
            wallet.set_next_index(md, BaseWallet.ADDRESS_TYPE_EXTERNAL,
                                  indices[0], force=True)
            wallet.set_next_index(md, BaseWallet.ADDRESS_TYPE_INTERNAL,
                                  indices[1], force=True)

    if 'imported' in data:
        for md in data['imported']:
            for privkey in data['imported'][md]:
                privkey += b'\x01'
                wif = BTCEngine.privkey_to_wif(privkey)
                wallet.import_private_key(md, wif)

    wallet.save()
    wallet.close()
    return True
def new_wallet_from_data(data, file_name):
    print("Creating new wallet file.")
    new_pw = cli_get_wallet_passphrase_check()
    if new_pw is False:
        return False

    storage = Storage(file_name, create=True, password=new_pw)
    wallet_cls = get_wallet_cls()

    kwdata = {
        'entropy': data['entropy'],
        'timestamp': data.get('creation_time'),
        'max_mixdepth': get_max_mixdepth(data)
    }

    if 'entropy_ext' in data:
        kwdata['entropy_extension'] = data['entropy_ext']

    wallet_cls.initialize(storage, data['network'], **kwdata)
    wallet = wallet_cls(storage)

    if 'index_cache' in data:
        for md, indices in enumerate(data['index_cache']):
            wallet.set_next_index(md, 0, indices[0], force=True)
            wallet.set_next_index(md, 1, indices[1], force=True)

    if 'imported' in data:
        for md in data['imported']:
            for privkey in data['imported'][md]:
                privkey += b'\x01'
                wif = wif_compressed_privkey(hexlify(privkey).decode('ascii'))
                wallet.import_private_key(md, wif)

    wallet.save()
    wallet.close()
    return True