def create(self, name, password, seed=None, passphrase="", bip39_derivation=None, master=None, addresses=None, privkeys=None): """Create or restore a new wallet""" path = self._wallet_path(name) if exists(path): raise FileExistsError(path) storage = WalletStorage(path) if addresses is not None: wallet = ImportedAddressWallet.from_text(storage, addresses) elif privkeys is not None: wallet = ImportedPrivkeyWallet.from_text(storage, privkeys) else: if bip39_derivation is not None: ks = keystore.from_seed(seed, passphrase, seed_type='bip39', derivation=bip39_derivation) elif master is not None: ks = keystore.from_master_key(master) else: if seed is None: seed = self.make_seed() print("Your wallet generation seed is:\n\"%s\"" % seed) ks = keystore.from_seed(seed, passphrase) storage.put('keystore', ks.dump()) wallet = Standard_Wallet(storage) wallet.update_password(None, password, True)
def create(self, name, password, seed=None, passphrase="", bip39_derivation=None, master=None, addresses=None, privkeys=None, multisig=False): """Create or restore a new wallet""" path = self._wallet_path(name) if exists(path): raise FileExistsError(path) storage = WalletStorage(path) if addresses is not None: wallet = ImportedAddressWallet.from_text(storage, addresses) elif privkeys is not None: wallet = ImportedPrivkeyWallet.from_text(storage, privkeys) else: if bip39_derivation is not None: ks = keystore.from_seed(seed, passphrase, seed_type='bip39', derivation=bip39_derivation) elif master is not None: ks = keystore.from_master_key(master) else: if seed is None: seed = self.make_seed() print("Your wallet generation seed is:\n\"%s\"" % seed) ks = keystore.from_seed(seed, passphrase) if not multisig: storage.put('keystore', ks.dump()) wallet = Standard_Wallet(storage) else: # For multisig wallets, we do not immediately create a wallet storage file. # Instead, we just get the keystore; create_multisig() handles wallet storage # later, once all cosigners are added. return ks.dump() wallet.update_password(None, password, encrypt=True)
def genContractWallet(self, nickname=None): path = os.path.join(self.topDir, 'wallets') if not os.path.isdir(path): os.mkdir(path) if nickname: for i, c in enumerate(self.contracts): if c["nickname"] == nickname: print_msg("{} contract exists.".format(nickname)) return self.getContractWallet(i), c #print(type(self.contracts)) #this next loop generates a wallet name that isn't in use yet. if self.contracts == []: walletFile = os.path.join(self.topDir, 'wallets', 'contract0.wallet') else: walletNames = [] for c in self.contracts: #print(c) walletNames.append(c['walletFile']) for i in range(len(walletNames) + 1): walletFile = os.path.join(self.topDir, 'wallets', 'contract' + str(i) + '.wallet') if walletFile not in walletNames: break storage = WalletStorage(walletFile) seed_type = 'standard' seed = Mnemonic('en').make_seed(seed_type) k = keystore.from_seed(seed, '', False) storage.put('keystore', k.dump()) storage.put('wallet_type', 'standard') wallet = Wallet(storage) wallet.set_schnorr_enabled(False) wallet.update_password(None, '', True) wallet.synchronize() print_msg("Your wallet generation seed is:\n\"%s\"" % seed) print_msg( "Please keep it in a safe place; if you lose it, you will not be able to restore your wallet." ) wallet.storage.write() print_msg("Wallet saved in '%s'" % wallet.storage.path) my_addr = wallet.get_unused_address() my_addr_index = wallet.receiving_addresses.index(my_addr) #my_addr_index is always going to be 0 if the wallet is unused, so maybe previous line unnecessary my_pubkey = wallet.derive_pubkeys(False, my_addr_index) my_x_pubkey = self.get_x_pubkey(my_addr_index, wallet) self.contracts.append({ 'walletFile': wallet.storage.path, "my_addr": my_addr.to_ui_string(), "my_pubkey": my_pubkey, "my_x_pubkey": my_x_pubkey, "nickname": nickname, "label": "" }) #print(self.contracts) self.updateContracts() self.multiWallets.append(None) return wallet, self.contracts[-1]
def run(self): network = Network.get_instance() if not network: self.notify_offline() return for i, p in enumerate(self.DERIVATION_PATHS): if self.aborting: return k = keystore.from_seed(self.seed, '', derivation=p, seed_type=self.seed_type) p_safe = p.replace('/', '_').replace("'", 'h') storage_path = os.path.join( tempfile.gettempdir(), p_safe + '_' + random.getrandbits(32).to_bytes(4, 'big').hex()[:8] + "_not_saved_") tmp_storage = WalletStorage(storage_path, in_memory_only=True) tmp_storage.put('seed_type', self.seed_type) tmp_storage.put('keystore', k.dump()) wallet = Standard_Wallet(tmp_storage) try: wallet.start_threads(network) wallet.synchronize() wallet.print_error("Scanning", p) synched = False for ctr in range(25): try: wallet.wait_until_synchronized(timeout=1.0) synched = True except TimeoutException: wallet.print_error(f'timeout try {ctr+1}/25') if self.aborting: return if not synched: wallet.print_error("Timeout on", p) self.notify_timedout(i) continue while network.is_connecting(): time.sleep(0.1) if self.aborting: return num_tx = len(wallet.get_history()) self.update_table_cb(i, str(num_tx)) finally: wallet.clear_history() wallet.stop_threads()
def create(self, name, password, seed=None, addresses=None, privkeys=None): """Create or restore a new wallet""" path = self._wallet_path(name) if exists(path): raise FileExistsError(path) storage = WalletStorage(path) if addresses: wallet = ImportedAddressWallet.from_text(storage, addresses) elif privkeys: wallet = ImportedPrivkeyWallet.from_text(storage, privkeys) else: if seed is None: seed = self.make_seed() print("Your wallet generation seed is:\n\"%s\"" % seed) storage.put('keystore', keystore.from_seed(seed, "", False).dump()) wallet = Standard_Wallet(storage) wallet.update_password(None, password, True)
def create(self, name, password=None, seed=None): """Create or restore a new wallet""" path = self._wallet_path(name) if exists(path): raise FileExistsError(path) storage = WalletStorage(path) if seed is None: seed = self.make_seed() print("Your wallet generation seed is:\n\"%s\"" % seed) storage.put('keystore', keystore.from_seed(seed, "", False).dump()) storage.put('wallet_type', 'standard') wallet = Wallet(storage) if password is None: password = main.prompt_password( "Password (hit return if you do not wish to encrypt your wallet):" ) wallet.update_password(None, password, True) storage.write()
def __init__(self, parent, plugin, wallet_name, password=None): QDialog.__init__(self, parent) self.main_window = parent self.password = password self.wallet = parent.wallet self.plugin = plugin self.network = parent.network self.wallet_name = wallet_name self.batch_label = "BitcoinBiletoj1" self.template_file = '' self.working_directory = self.wallet.storage.get("bileto_path") if self.working_directory: if not os.path.exists(self.working_directory): self.working_directory = None self.number = 0 self.times = 1 self.public_key = '' for x in range(10): name = 'tmp_wo_wallet' + ''.join( random.choices(string.ascii_letters + string.digits, k=10)) self.file = os.path.join(tempfile.gettempdir(), name) if not os.path.exists(self.file): break else: raise RuntimeError( 'Could not find a unique temp file in tmp directory', tempfile.gettempdir()) self.tmp_pass = ''.join( random.choices(string.ascii_uppercase + string.digits, k=10)) from electroncash import mnemonic seed = mnemonic.Mnemonic('en').make_seed('standard') self.keystore = keystore.from_seed(seed, self.tmp_pass, False) self.storage = WalletStorage(self.file) self.storage.set_password(self.tmp_pass, encrypt=True) self.storage.put('keystore', self.keystore.dump()) self.recipient_wallet = Standard_Wallet(self.storage) self.recipient_wallet.start_threads(self.network) Weak.finalize(self.recipient_wallet, self.delete_temp_wallet_file, self.file) vbox = QVBoxLayout() self.setLayout(vbox) hbox = QHBoxLayout() vbox.addLayout(hbox) l = QLabel("<b>%s</b>" % (_("Bitcoin Bileto"))) hbox.addStretch(1) hbox.addWidget(l) hbox.addStretch(1) vbox.addWidget(QLabel("Working directory:")) hbox = QHBoxLayout() vbox.addLayout(hbox) self.wd_label = QLabel(self.working_directory) hbox.addWidget(self.wd_label) b = QPushButton("Set") b.clicked.connect(lambda: self.plugin.settings_dialog( self, self.settings_updated_signal)) self.settings_updated_signal.connect(self.on_settings_updated) hbox.addWidget(b) data = "prywatny klucz do portfela" self.qrw_priv = QRCodeWidget(data) self.qrw_add = QRCodeWidget(data) self.batch_label_wid = QLineEdit() self.batch_label_wid.setPlaceholderText( _("Bitcoin biletoj batch label")) self.batch_label_wid.textEdited.connect(self.batch_info_changed) vbox.addWidget(self.batch_label_wid) grid = QGridLayout() vbox.addLayout(grid) self.number_wid = QLineEdit() self.number_wid.setPlaceholderText(_("Number of biletoj")) self.number_wid.textEdited.connect(self.batch_info_changed) self.times_wid = QLineEdit() self.times_wid.textEdited.connect(self.batch_info_changed) self.times_wid.setText("1") hbox = QHBoxLayout() vbox.addLayout(hbox) hbox.addWidget(self.number_wid) #hbox.addWidget(QLabel("x")) #hbox.addWidget(self.times_wid) hbox.addStretch(1) self.times_wid.setMaximumWidth(120) self.number_wid.setMaximumWidth(140) self.only_qrcodes_checkbox = QCheckBox("Only make QR codes.") self.only_qrcodes_checkbox.stateChanged.connect( self.batch_info_changed) self.encrypt_checkbox = QCheckBox("Encrypt Batch.") vbox.addWidget(self.encrypt_checkbox) vbox.addWidget(self.only_qrcodes_checkbox) #b = QPushButton(_("Load .tex template")) #b.clicked.connect(self.load_template) #b.setMaximumWidth(130) #grid.addWidget(b, 0, 0) #self.template_path_label_wid = QLabel('set path') #grid.addWidget(self.template_path_label_wid, 0, 1) self.public_key_wid = QLineEdit() self.public_key_wid.setPlaceholderText( _("Public Key") + _(" for encryption")) self.public_key_wid.textEdited.connect(self.batch_info_changed) #vbox.addWidget(self.public_key_wid) self.b = QPushButton(_("Generate biletoj")) self.b.clicked.connect(self.generate_biletoj) self.prog_bar = QProgressBar() self.prog_bar.setVisible(False) vbox.addWidget(self.b) vbox.addWidget(self.prog_bar) self.b.setDisabled(True) vbox.addStretch(1)