<commit_before>defmodule Neoscan.ChainAssets do
  @moduledoc false
  import Ecto.Query, warn: false
  alias Neoscan.Repo
  alias Neoscan.ChainAssets.Asset
  alias Neoscan.Blocks
  alias NeoscanMonitor.Api
  alias NeoscanSync.HttpCalls
  alias NeoscanSync.Blockchain
  alias NeoscanSync.Notifications
  alias Neoscan.Addresses
  alias Neoscan.Stats


  require Logger

  @doc """
  Creates an asset.

  ## Examples

      iex> create_asset(%{field: value})
      {:ok, %Asset{}}

      iex> create_asset(%{field: bad_value})
      {:error, %Ecto.Changeset{}}

  """
  def create_asset(transaction_id, attrs) do
    Asset.changeset(transaction_id, attrs)
    |> Repo.insert!()
  end

  def add_token(%{"token" => token} = response) do
    new_token = %{
      "admin" => token["contract_address"],
      "name" => [%{"lang" => "en", "name" => token["name"]}],
      "owner" => token["contract_address"],
      "precision" => token["decimals"],
      "type" => "Token",
      "amount" => 0,
      "issued" => 0,
      "time" => Blocks.get_block_time(response["block"]),
      "contract" => String.slice(to_string(token["script_hash"]), -40..-1),
    }
    create_asset(String.slice(to_string(response["tx"]), -40..-1), new_token)
  end

  #Creates tokens.
  def create_tokens([]) do
    []
  end
  def create_tokens(tokens) do
    tokens
    |> Enum.filter(fn %{"token" => token} -> get_token_by_contract(String.slice(to_string(token["script_hash"]), -40..-1)) == nil end)
    |> Enum.each(fn token -> add_token(token) end)
    |> check_tokens_creation(tokens)
  end

  def check_tokens_creation(:ok, tokens) do
    tokens
  end<commit_msg>fix hash bug<commit_after>defmodule Neoscan.ChainAssets do
  @moduledoc false
  import Ecto.Query, warn: false
  alias Neoscan.Repo
  alias Neoscan.ChainAssets.Asset
  alias Neoscan.Blocks
  alias NeoscanMonitor.Api
  alias NeoscanSync.HttpCalls
  alias NeoscanSync.Blockchain
  alias NeoscanSync.Notifications
  alias Neoscan.Addresses
  alias Neoscan.Stats


  require Logger

  @doc """
  Creates an asset.

  ## Examples

      iex> create_asset(%{field: value})
      {:ok, %Asset{}}

      iex> create_asset(%{field: bad_value})
      {:error, %Ecto.Changeset{}}

  """
  def create_asset(transaction_id, attrs) do
    Asset.changeset(transaction_id, attrs)
    |> Repo.insert!()
  end

  def add_token(%{"token" => token} = response) do
    new_token = %{
      "admin" => token["contract_address"],
      "name" => [%{"lang" => "en", "name" => token["name"]}],
      "owner" => token["contract_address"],
      "precision" => token["decimals"],
      "type" => "Token",
      "amount" => 0,
      "issued" => 0,
      "time" => Blocks.get_block_time(response["block"]),
      "contract" => String.slice(to_string(token["script_hash"]), -40..-1),
    }
    create_asset(String.slice(to_string(response["tx"]), -64..-1), new_token)
  end

  #Creates tokens.
  def create_tokens([]) do
    []
  end
  def create_tokens(tokens) do
    tokens
    |> Enum.filter(fn %{"token" => token} -> get_token_by_contract(String.slice(to_string(token["script_hash"]), -40..-1)) == nil end)
    |> Enum.each(fn token -> add_token(token) end)
    |> check_tokens_creation(tokens)
  end

  def check_tokens_creation(:ok, tokens) do
    tokens
  end
{'fraction_non_alphanumeric': 0.15887564925145126, 'fraction_numerical': 0.006721662083715246, 'mean_word_length': 3.4910836762688615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '406634', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1140, 'n_words': 227}