def run_non_RPC(config): """Most commands should go through the daemon or RPC, especially commands that operate on wallets.""" cmdname = config.get('cmd') def get_wallet_path() -> str: wallet_path = config.get_cmdline_wallet_filepath() if wallet_path is None: sys.exit("error: no wallet path provided") final_path = WalletStorage.canonical_path(wallet_path) if WalletStorage.files_are_matched_by_path(wallet_path): sys.exit(f"error: wallet already exists: {final_path}") return final_path if cmdname in {'create_wallet', 'create_account'}: if not config.cmdline_options.get('nopasswordcheck'): password = prompt_password("Password:"******"error: wallet creation requires a password") if cmdname == 'create_wallet': wallet_path = get_wallet_path() storage = WalletStorage.create(wallet_path, password) storage.close() print(f"Wallet saved in '{wallet_path}'") sys.exit(0) elif cmdname == 'create_account': wallet_path = config.get_cmdline_wallet_filepath() storage = WalletStorage.create(wallet_path, password) parent_wallet = Wallet(storage) # create an account for the Wallet (only random new seeds supported - no importing) text_type = KeystoreTextType.EXTENDED_PRIVATE_KEY text_match = os.getenv("ELECTRUMSV_ACCOUNT_XPRV") if not text_match: # generate a random account seed data = urandom(64) coin = bitcoinx.BitcoinRegtest xprv = bitcoinx.BIP32PrivateKey._from_parts( data[:32], data[32:], coin) text_match = xprv.to_extended_key_string() keystore = instantiate_keystore_from_text(text_type, text_match, password, derivation_text=None, passphrase=None, watch_only=False) parent_wallet.create_account_from_keystore(keystore) print(f"New standard (bip32) account created for: '{wallet_path}'") sys.exit(0) else: sys.exit("error: unrecognised command")
async def create_new_wallet(self, request): """only for regtest for the moment...""" try: vars = await self.argparser( request, required_vars=[VNAME.PASSWORD, VNAME.WALLET_NAME], check_wallet_availability=False) create_filepath = str( Path(self.wallets_path).joinpath(vars[VNAME.WALLET_NAME])) self.check_if_wallet_exists(create_filepath) storage = WalletStorage.create(create_filepath, vars[VNAME.PASSWORD]) storage.close() parent_wallet = self.app_state.daemon.load_wallet(create_filepath) # create an account for the Wallet with the same password via an imported seed text_type = KeystoreTextType.EXTENDED_PRIVATE_KEY text_match = 'tprv8ZgxMBicQKsPd4wsdaJ11eH84eq4hHLX1K6Mx8EQQhJzq8jr25WH1m8hgGkCqnks' \ 'JDCZPZbDoMbQ6QtroyCyn5ZckCmsLeiHDb1MAxhNUHN' keystore = instantiate_keystore_from_text(text_type, text_match, vars[VNAME.PASSWORD], derivation_text=None, passphrase=None) parent_wallet.create_account_from_keystore(keystore) await self._load_wallet(vars[VNAME.WALLET_NAME]) response = {"new_wallet": create_filepath} return good_response(response) except Fault as e: return fault_to_http_response(e)
def run_non_RPC(config): """Most commands should go through the daemon or RPC, especially commands that operate on wallets.""" cmdname = config.get('cmd') def get_wallet_path() -> str: wallet_path = config.get_cmdline_wallet_filepath() if wallet_path is None: sys.exit("error: no wallet path provided") final_path = WalletStorage.canonical_path(wallet_path) if WalletStorage.files_are_matched_by_path(wallet_path): sys.exit(f"error: wallet already exists: {final_path}") return final_path if cmdname == 'create_wallet': wallet_path = get_wallet_path() password = prompt_password("Password:"******"error: wallet creation requires a password") storage = WalletStorage.create(wallet_path, password) storage.close() print(f"Wallet saved in '{wallet_path}'") sys.exit(0) else: sys.exit("error: unrecognised command")
def create_new_wallet(parent: QWidget, initial_dirpath: str) -> Optional[str]: create_filepath, __ = QFileDialog.getSaveFileName( parent, _("Enter a new wallet file name"), initial_dirpath) if not create_filepath: return None # QFileDialog.getSaveFileName uses forward slashes for "easier pathing".. correct this. create_filepath = os.path.normpath(create_filepath) if os.path.exists(create_filepath): MessageBox.show_error( _("Overwriting existing files not supported at this time.")) return None dirpath, filename = os.path.split(create_filepath) if not create_filepath.endswith(DATABASE_EXT): if os.path.exists(create_filepath + DATABASE_EXT): MessageBox.show_error( _("The file name '{}' is already in use.").format(filename)) return None if not dirpath or not os.path.isdir(dirpath) or not os.access( dirpath, os.R_OK | os.W_OK): MessageBox.show_error(_("The selected directory is not accessible.")) return None name_edit = QLabel(filename) fields = [ (QLabel(_("Wallet") + ":"), name_edit), ] from .password_dialog import ChangePasswordDialog, PasswordAction from .wallet_wizard import PASSWORD_NEW_TEXT d = ChangePasswordDialog(parent, PASSWORD_NEW_TEXT, _("Create New Wallet"), fields, kind=PasswordAction.NEW) success, _old_password, new_password = d.run() if not success or not new_password.strip(): return None from electrumsv.storage import WalletStorage storage = WalletStorage.create(create_filepath, new_password) storage.close() return create_filepath