<commit_before>class TransactionsController < ApplicationController
  
  before_filter :authenticate_user!

  def index
    @limit = (params[:limit] || 10).to_i
    @transactions = BITCOIN.listtransactions(current_user.email, @limit).reverse
    @page_title = t('transactions.index.title')
  end

  def show
    @transaction = BITCOIN.gettransaction(params[:id])
    unless @transaction["details"].map{|d| d["account"]}.include?(current_user.email)
      return redirect_to destroy_user_session_path
    end
    @from = Address.get(@transaction["details"].find{|d| d["category"] == "send" }["address"]) rescue nil
    @to = Address.get(@transaction["details"].find{|d| d["category"] == "receive" }["address"]) rescue nil
    @page_title = t('transactions.show.title')
  end

  def create
    address = params[:transaction][:address]
    @address = Address.get(address)
    amount = params[:transaction][:amount].to_f
    if BITCOIN.getbalance(current_user.email) >= amount && @address
      redirect_to check_transaction_path(:transaction => params[:transaction])
    else
      flash[:alert] = t('transactions.create.alert_insufficient_funds')
      return redirect_to account_path
    end
  rescue
    flash[:alert] = $!.message
    return redirect_to account_path
  end

  def check
    @address = Address.get(params[:transaction][:address])
    @transaction = params[:transaction]
    @transaction[:address] = @address
    @page_title = t('transactions.check.title')
  end

  def commit
    begin
      unit = params[:unit]
      factor = User::UNITS[unit]
      amount = params[:transaction][:amount].to_f / factor
      address = params[:transaction][:address]
      txid = BITCOIN.sendfrom(current_user.email, address, amount)
      flash[:notice] = t('transactions.commit.notice', :amount => amount, :address => address)
      redirect_to transaction_path(txid)
    rescue RuntimeError => e
      flash[:alert] = t('transactions.commit.alert', :error => e.message)
      redirect_to account_path
    end
  end

  def autocomplete_address
    respond_to do |format|
      format.js { render :json => Address.remote(current_user).where("label LIKE ?", "%#{params[:term]}%").map(&:label)}
    end
    
  end

end
<commit_msg>calculate unit factor also in preliminary transaction checks<commit_after>class TransactionsController < ApplicationController
  
  before_filter :authenticate_user!

  def index
    @limit = (params[:limit] || 10).to_i
    @transactions = BITCOIN.listtransactions(current_user.email, @limit).reverse
    @page_title = t('transactions.index.title')
  end

  def show
    @transaction = BITCOIN.gettransaction(params[:id])
    unless @transaction["details"].map{|d| d["account"]}.include?(current_user.email)
      return redirect_to destroy_user_session_path
    end
    @from = Address.get(@transaction["details"].find{|d| d["category"] == "send" }["address"]) rescue nil
    @to = Address.get(@transaction["details"].find{|d| d["category"] == "receive" }["address"]) rescue nil
    @page_title = t('transactions.show.title')
  end

  def create
    address = params[:transaction][:address]
    @address = Address.get(address)
    amount = params[:transaction][:amount].to_f
    factor = User::UNITS[current_user.setting(:units)]
    if BITCOIN.getbalance(current_user.email) >= (amount / factor) && @address
      redirect_to check_transaction_path(:transaction => params[:transaction])
    else
      flash[:alert] = t('transactions.create.alert_insufficient_funds')
      return redirect_to account_path
    end
  rescue
    flash[:alert] = $!.message
    return redirect_to account_path
  end

  def check
    @address = Address.get(params[:transaction][:address])
    @transaction = params[:transaction]
    @transaction[:address] = @address
    @page_title = t('transactions.check.title')
  end

  def commit
    begin
      factor = User::UNITS[current_user.setting(:units)]
      amount = params[:transaction][:amount].to_f / factor
      address = params[:transaction][:address]
      txid = BITCOIN.sendfrom(current_user.email, address, amount)
      flash[:notice] = t('transactions.commit.notice', :amount => amount, :address => address)
      redirect_to transaction_path(txid)
    rescue RuntimeError => e
      flash[:alert] = t('transactions.commit.alert', :error => e.message)
      redirect_to account_path
    end
  end

  def autocomplete_address
    respond_to do |format|
      format.js { render :json => Address.remote(current_user).where("label LIKE ?", "%#{params[:term]}%").map(&:label)}
    end
    
  end

end

{'fraction_non_alphanumeric': 0.137417943107221, 'fraction_numerical': 0.00087527352297593, 'mean_word_length': 4.118701007838745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4614952', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1343, 'n_words': 274}