def update_account(account, new_password, include_address=true, include_id=true)
      raise ValueError, "Account not managed by account service" unless @accounts.include?(account)
      raise ValueError, "Cannot update locked account" if account.locked?
      raise ValueError, 'Account not stored on disk' unless account.path

      logger.debug "creating new account"
      new_account = Account.create new_password, account.privkey, account.uuid, account.path

      backup_path = account.path + '~'
      i = 1
      while File.exist?(backup_path)
        backup_path = backup_path[0, backup_path.rindex('~')+1] + i.to_s
        i += 1
      end
      raise AssertError if File.exist?(backup_path)

      logger.info 'moving old keystore file to backup location', from: account.path, to: backup_path
      begin
        FileUtils.mv account.path, backup_path
      rescue
        logger.error "could not backup keystore, stopping account update", from: account.path, to: backup_path
        raise $!
      end
      raise AssertError unless File.exist?(backup_path)
      raise AssertError if File.exist?(new_account.path)
      account.path = backup_path

      @accounts.delete account
      begin
        add_account new_account, include_address, include_id
      rescue
        logger.error 'adding new account failed, recovering from backup'
        FileUtils.mv backup_path, new_account.path
        account.path = new_account.path
        @accounts.push account
        @accounts.sort_by! {|acct| acct.path.to_s }
        raise $!
      end
      raise AssertError unless File.exist?(new_account.path)

      logger.info "deleting backup of old keystore", path: backup_path
      begin
        FileUtils.rm backup_path
      rescue
        logger.error 'failed to delete no longer needed backup of old keystore', path: account.path
        raise $!
      end

      account.keystore = new_account.keystore
      account.path = new_account.path

      @accounts.push account
      @accounts.delete new_account
      @accounts.sort_by! {|acct| acct.path.to_s }

      logger.debug "account update successful"
    end
def update_account(account, new_password, include_address=true, include_id=true)
      raise ValueError, "Account not managed by account service" unless @accounts.include?(account)
      raise ValueError, "Cannot update locked account" if account.locked?
      raise ValueError, 'Account not stored on disk' unless account.path

      logger.debug "creating new account"
      new_account = Account.create new_password, account.privkey, account.uuid, account.path

      backup_path = account.path + '~'
      i = 1
      while File.exist?(backup_path)
        backup_path = backup_path[0, backup_path.rindex('~')+1] + i.to_s
        i += 1
      end
      raise AssertError if File.exist?(backup_path)

      logger.info 'moving old keystore file to backup location', from: account.path, to: backup_path
      begin
        FileUtils.mv account.path, backup_path
      rescue
        logger.error "could not backup keystore, stopping account update", from: account.path, to: backup_path
        raise $!
      end
      raise AssertError unless File.exist?(backup_path)
      raise AssertError if File.exist?(new_account.path)
      account.path = backup_path

      @accounts.delete account
      begin
        add_account new_account, include_address, include_id
      rescue
        logger.error 'adding new account failed, recovering from backup'
        FileUtils.mv backup_path, new_account.path
        account.path = new_account.path
        @accounts.push account
        @accounts.sort_by! {|acct| acct.path.to_s }
        raise $!
      end
      raise AssertError unless File.exist?(new_account.path)

      logger.info "deleting backup of old keystore", path: backup_path
      begin
        FileUtils.rm backup_path
      rescue
        logger.error 'failed to delete no longer needed backup of old keystore', path: account.path
        raise $!
      end

      account.keystore = new_account.keystore
      account.path = new_account.path

      @accounts.push account
      @accounts.delete new_account
      @accounts.sort_by! {|acct| acct.path.to_s }

      logger.debug "account update successful"
    end
Replace the password of an account.

 The update is carried out in three steps:

 1. the old keystore file is renamed
 2. the new keystore file is created at the previous location of the old
   keystore file
 3. the old keystore file is removed

 In this way, at least one of the keystore files exists on disk at any
 time and can be recovered if the process is interrupted.

 @param account [Account] which must be unlocked, stored on disk and
   included in `@accounts`
 @param include_address [Bool] forwarded to `add_account` during step 2
 @param include_id [Bool] forwarded to `add_account` during step 2

 @raise [ValueError] if the account is locked, if it is not added to the
   account manager, or if it is not stored