def create_account(self): """ Creates an account from provided form. Verify we can unlock it. Disables widgets during the process, so the user doesn't try to create another account during the process. """ # circular ref from pywallet.controller import Controller self.toggle_widgets(False) if not self.verify_fields(): Dialog.show_invalid_form_dialog() self.toggle_widgets(True) return pywalib = self.controller.pywalib password = self.new_password1 security_ratio = self.security_slider_value # dividing again by 10, because otherwise it's # too slow on smart devices security_ratio /= 10.0 Dialog.snackbar_message("Creating account...") account = pywalib.new_account(password=password, security_ratio=security_ratio) Dialog.snackbar_message("Created!") self.toggle_widgets(True) Controller.set_account_alias(account, self.alias) self.on_account_created(account) CreateNewAccount.try_unlock(account, password) self.show_redirect_dialog() self.controller.load_landing_page() return account
def update_password(self): """ Update account password with new password provided. """ if not self.verify_fields(): Dialog.show_invalid_form_dialog() return Dialog.snackbar_message("Verifying current password...") if not self.verify_current_password_field(): Dialog.snackbar_message("Wrong account password") return pywalib = self.controller.pywalib account = self.current_account new_password = self.new_password1 Dialog.snackbar_message("Updating account...") pywalib.update_account_password(account, new_password=new_password) Dialog.snackbar_message("Updated!")
def unlock_send_transaction(self): """ Unlocks the account with password in order to sign and publish the transaction. """ controller = App.get_running_app().controller pywalib = controller.pywalib address = to_checksum_address(self.send_to_address) amount_eth = round(self.send_amount, ROUND_DIGITS) amount_wei = int(amount_eth * pow(10, 18)) gas_price_gwei = Settings.get_stored_gas_price() gas_price_wei = int(gas_price_gwei * (10 ** 9)) # TODO: not the main account, but the current account account = controller.current_account Dialog.snackbar_message("Unlocking account...") try: account.unlock(self.password) except ValueError: Dialog.snackbar_message("Could not unlock account") return Dialog.snackbar_message("Unlocked! Sending transaction...") sender = account.address try: pywalib.transact( address, value=amount_wei, data='', sender=sender, gasprice=gas_price_wei) except InsufficientFundsException: Dialog.snackbar_message("Insufficient funds") return except UnknownEtherscanException: Dialog.snackbar_message("Unknown error") Logger.error('UnknownEtherscanException', exc_info=True) return # TODO: handle ConnectionError Dialog.snackbar_message("Sent!")