def add_account(account, store=true, include_address=true, include_id=true)
      logger.info "adding account", account: account

      if account.uuid && @accounts.any? {|acct| acct.uuid == account.uuid }
        logger.error 'could not add account (UUID collision)', uuid: account.uuid
        raise ValueError, 'Could not add account (UUID collision)'
      end

      if store
        raise ValueError, 'Cannot store account without path' if account.path.nil?
        if File.exist?(account.path)
          logger.error 'File does already exist', path: account.path
          raise IOError, 'File does already exist'
        end

        raise AssertError if @accounts.any? {|acct| acct.path == account.path }

        begin
          directory = File.dirname account.path
          FileUtils.mkdir_p(directory) unless File.exist?(directory)

          File.open(account.path, 'w') do |f|
            f.write account.dump(include_address, include_id)
          end
        rescue IOError => e
          logger.error "Could not write to file", path: account.path, message: e.to_s
          raise e
        end
      end

      @accounts.push account
      @accounts.sort_by! {|acct| acct.path.to_s }
    end
def add_account(account, store=true, include_address=true, include_id=true)
      logger.info "adding account", account: account

      if account.uuid && @accounts.any? {|acct| acct.uuid == account.uuid }
        logger.error 'could not add account (UUID collision)', uuid: account.uuid
        raise ValueError, 'Could not add account (UUID collision)'
      end

      if store
        raise ValueError, 'Cannot store account without path' if account.path.nil?
        if File.exist?(account.path)
          logger.error 'File does already exist', path: account.path
          raise IOError, 'File does already exist'
        end

        raise AssertError if @accounts.any? {|acct| acct.path == account.path }

        begin
          directory = File.dirname account.path
          FileUtils.mkdir_p(directory) unless File.exist?(directory)

          File.open(account.path, 'w') do |f|
            f.write account.dump(include_address, include_id)
          end
        rescue IOError => e
          logger.error "Could not write to file", path: account.path, message: e.to_s
          raise e
        end
      end

      @accounts.push account
      @accounts.sort_by! {|acct| acct.path.to_s }
    end
Add an account.

 If `store` is true the account will be stored as a key file at the
 location given by `account.path`. If this is `nil` a `ValueError` is
 raised. `include_address` and `include_id` determine if address and id
 should be removed for storage or not.

 This method will raise a `ValueError` if the new account has the same
 UUID as an account already known to the service. Note that address
 collisions do not result in an exception as those may slip through
 anyway for locked accounts with hidden addresses.