From 03fd6f954080be1fa4abaaeb0a3073d29936fb7f Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 21 May 2019 15:21:00 +0300 Subject: [PATCH 01/53] create staking_pool schema --- .../lib/explorer/chain/staking_pool.ex | 73 +++++++++++++++++++ .../20190521104412_create_staking_pools.exs | 28 +++++++ .../test/explorer/chain/staking_pool_test.exs | 18 +++++ apps/explorer/test/support/factory.ex | 37 +++++----- 4 files changed, 139 insertions(+), 17 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/staking_pool.ex create mode 100644 apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs create mode 100644 apps/explorer/test/explorer/chain/staking_pool_test.exs diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex new file mode 100644 index 0000000000..59bffdd43e --- /dev/null +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -0,0 +1,73 @@ +defmodule Explorer.Chain.StakingPool do + @moduledoc """ + The representation of staking pool from POSDAO network. + Staking pools might be candidate or validator. + """ + use Ecto.Schema + import Ecto.Changeset + + alias Explorer.Chain.{ + Wei, + Address, + Hash + } + + @attrs ~w( + is_active delegators_count staked_amount self_staked_amount is_validator + was_validator_count is_banned was_banned_count banned_until likelihood + staked_ratio min_delegators_stake min_candidate_stake + staking_address_hash mining_address_hash + )a + + schema "staking_pools" do + field(:banned_until, :integer) + field(:delegators_count, :integer) + field(:is_active, :boolean, default: false) + field(:is_banned, :boolean, default: false) + field(:is_validator, :boolean, default: false) + field(:likelihood, :decimal) + field(:staked_ratio, :decimal) + field(:min_candidate_stake, Wei) + field(:min_delegators_stake, Wei) + field(:self_staked_amount, Wei) + field(:staked_amount, Wei) + field(:was_banned_count, :integer) + field(:was_validator_count, :integer) + + belongs_to( + :staking_address, + Address, + foreign_key: :staking_address_hash, + references: :hash, + type: Hash.Address + ) + + belongs_to( + :mining_address, + Address, + foreign_key: :mining_address_hash, + references: :hash, + type: Hash.Address + ) + + timestamps() + end + + @doc false + def changeset(staking_pool, attrs) do + staking_pool + |> cast(attrs, @attrs) + |> validate_required(@attrs) + |> validate_staked_amount() + end + + defp validate_staked_amount(%{valid?: false} = c), do: c + + defp validate_staked_amount(changeset) do + if get_field(changeset, :staked_amount) < get_field(changeset, :self_staked_amount) do + add_error(changeset, :staked_amount, "must be greater than self_staked_amount") + else + changeset + end + end +end diff --git a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs new file mode 100644 index 0000000000..2499641eda --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs @@ -0,0 +1,28 @@ +defmodule Explorer.Repo.Migrations.CreateStakingPools do + use Ecto.Migration + + def change do + create table(:staking_pools) do + add(:is_active, :boolean, default: false, null: false) + add(:delegators_count, :integer) + add(:staked_amount, :numeric, precision: 100) + add(:self_staked_amount, :numeric, precision: 100) + add(:is_validator, :boolean, default: false, null: false) + add(:was_validator_count, :integer) + add(:is_banned, :boolean, default: false, null: false) + add(:was_banned_count, :integer) + add(:banned_until, :bigint) + add(:likelihood, :decimal) + add(:staked_ratio, :decimal) + add(:min_delegators_stake, :numeric, precision: 100) + add(:min_candidate_stake, :numeric, precision: 100) + add(:staking_address_hash, references(:addresses, on_delete: :nothing, column: :hash, type: :bytea)) + add(:mining_address_hash, references(:addresses, on_delete: :nothing, column: :hash, type: :bytea)) + + timestamps() + end + + create(index(:staking_pools, [:staking_address_hash])) + create(index(:staking_pools, [:mining_address_hash])) + end +end diff --git a/apps/explorer/test/explorer/chain/staking_pool_test.exs b/apps/explorer/test/explorer/chain/staking_pool_test.exs new file mode 100644 index 0000000000..78d01a0f19 --- /dev/null +++ b/apps/explorer/test/explorer/chain/staking_pool_test.exs @@ -0,0 +1,18 @@ +defmodule Explorer.Chain.StakingPoolTest do + use Explorer.DataCase + + alias Explorer.Chain.StakingPool + + describe "changeset/2" do + test "with valid attributes" do + params = params_for(:staking_pool) + changeset = StakingPool.changeset(%StakingPool{}, params) |> IO.inspect() + assert changeset.valid? + end + + test "with invalid attributes" do + changeset = StakingPool.changeset(%StakingPool{}, %{staking_address_hash: 0}) + refute changeset.valid? + end + end +end diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 115b07e066..6a08c2df8b 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -26,7 +26,8 @@ defmodule Explorer.Factory do SmartContract, Token, TokenTransfer, - Transaction + Transaction, + StakingPool } alias Explorer.Market.MarketHistory @@ -611,22 +612,24 @@ defmodule Explorer.Factory do end def staking_pool_factory do - %{ - address_hash: address_hash(), - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: address_hash(), - retries_count: 1, - staked_amount: 25, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true + wei_per_ether = 1_000_000_000_000_000_000 + + %StakingPool{ + staking_address_hash: address_hash(), + mining_address_hash: address_hash(), + banned_until: 0, + delegators_count: 0, + is_active: true, + is_banned: false, + is_validator: true, + staked_amount: wei_per_ether * 500, + self_staked_amount: wei_per_ether * 300, + was_banned_count: 0, + was_validator_count: 1, + min_delegators_stake: wei_per_ether * 100, + min_candidate_stake: wei_per_ether * 200, + staked_ratio: 0, + likelihood: 0, } end end From 85401da1d0ff3ab2196a0f12ab482f6e61538c9c Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 11:33:47 +0300 Subject: [PATCH 02/53] add cast! and dump! to Wei module --- apps/explorer/lib/explorer/chain/wei.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/explorer/lib/explorer/chain/wei.ex b/apps/explorer/lib/explorer/chain/wei.ex index 4b12d3deb0..0739885cf8 100644 --- a/apps/explorer/lib/explorer/chain/wei.ex +++ b/apps/explorer/lib/explorer/chain/wei.ex @@ -68,6 +68,11 @@ defmodule Explorer.Chain.Wei do @impl Ecto.Type def cast(_), do: :error + def cast!(arg) do + {:ok, wei} = cast(arg) + wei + end + @impl Ecto.Type def dump(%__MODULE__{value: %Decimal{} = decimal}) do {:ok, decimal} @@ -76,6 +81,11 @@ defmodule Explorer.Chain.Wei do @impl Ecto.Type def dump(_), do: :error + def dump!(arg) do + {:ok, decimal} = dump(arg) + decimal + end + @impl Ecto.Type def load(%Decimal{} = decimal) do {:ok, %__MODULE__{value: decimal}} From d2740b0056750bb619d7916c73dc0bc0de66dda0 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 11:43:33 +0300 Subject: [PATCH 03/53] add convert wei to integer --- apps/explorer/lib/explorer/chain/staking_pool.ex | 8 +++++--- apps/explorer/lib/explorer/chain/wei.ex | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index 59bffdd43e..7b69acefbf 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -15,7 +15,7 @@ defmodule Explorer.Chain.StakingPool do @attrs ~w( is_active delegators_count staked_amount self_staked_amount is_validator was_validator_count is_banned was_banned_count banned_until likelihood - staked_ratio min_delegators_stake min_candidate_stake + staked_ratio min_delegator_stake min_candidate_stake staking_address_hash mining_address_hash )a @@ -28,11 +28,12 @@ defmodule Explorer.Chain.StakingPool do field(:likelihood, :decimal) field(:staked_ratio, :decimal) field(:min_candidate_stake, Wei) - field(:min_delegators_stake, Wei) + field(:min_delegator_stake, Wei) field(:self_staked_amount, Wei) field(:staked_amount, Wei) field(:was_banned_count, :integer) field(:was_validator_count, :integer) + field(:is_deleted, :boolean, default: false) belongs_to( :staking_address, @@ -50,7 +51,7 @@ defmodule Explorer.Chain.StakingPool do type: Hash.Address ) - timestamps() + timestamps(null: false, type: :utc_datetime_usec) end @doc false @@ -59,6 +60,7 @@ defmodule Explorer.Chain.StakingPool do |> cast(attrs, @attrs) |> validate_required(@attrs) |> validate_staked_amount() + |> unique_constraint(:staking_address_hash) end defp validate_staked_amount(%{valid?: false} = c), do: c diff --git a/apps/explorer/lib/explorer/chain/wei.ex b/apps/explorer/lib/explorer/chain/wei.ex index 0739885cf8..8b557b4ed5 100644 --- a/apps/explorer/lib/explorer/chain/wei.ex +++ b/apps/explorer/lib/explorer/chain/wei.ex @@ -248,6 +248,11 @@ defmodule Explorer.Chain.Wei do @spec to(t(), :wei) :: wei() def to(%__MODULE__{value: wei}, :wei), do: wei + + @spec to(t(), :integer) :: integer() + def to(%__MODULE__{value: wei}, :integer) do + Decimal.to_integer(wei) + end end defimpl Inspect, for: Explorer.Chain.Wei do From 16393b289073e22267a8a349673dd6d0846b883d Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 11:56:58 +0300 Subject: [PATCH 04/53] add typespec to staking_pool schema --- .../lib/explorer/chain/staking_pool.ex | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index 7b69acefbf..10e678df25 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -7,9 +7,28 @@ defmodule Explorer.Chain.StakingPool do import Ecto.Changeset alias Explorer.Chain.{ - Wei, Address, - Hash + Hash, + Wei + } + + @type t :: %__MODULE__{ + staking_address_hash: Hash.Address.t(), + mining_address_hash: Hash.Address.t(), + banned_until: boolean, + delegators_count: integer, + is_active: boolean, + is_banned: boolean, + is_validator: boolean, + likelihood: integer, + staked_ratio: Decimal.t(), + min_candidate_stake: Wei.t(), + min_delegator_stake: Wei.t(), + self_staked_amount: Wei.t(), + staked_amount: Wei.t(), + was_banned_count: integer, + was_validator_count: integer, + is_deleted: boolean } @attrs ~w( From f4c25a38de58ae7942e843af88ae3449f64ea2a4 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 11:57:19 +0300 Subject: [PATCH 05/53] update migration --- .../20190521104412_create_staking_pools.exs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs index 2499641eda..aabef14d1a 100644 --- a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs +++ b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs @@ -4,6 +4,7 @@ defmodule Explorer.Repo.Migrations.CreateStakingPools do def change do create table(:staking_pools) do add(:is_active, :boolean, default: false, null: false) + add(:is_deleted, :boolean, default: false, null: false) add(:delegators_count, :integer) add(:staked_amount, :numeric, precision: 100) add(:self_staked_amount, :numeric, precision: 100) @@ -14,15 +15,15 @@ defmodule Explorer.Repo.Migrations.CreateStakingPools do add(:banned_until, :bigint) add(:likelihood, :decimal) add(:staked_ratio, :decimal) - add(:min_delegators_stake, :numeric, precision: 100) + add(:min_delegator_stake, :numeric, precision: 100) add(:min_candidate_stake, :numeric, precision: 100) - add(:staking_address_hash, references(:addresses, on_delete: :nothing, column: :hash, type: :bytea)) - add(:mining_address_hash, references(:addresses, on_delete: :nothing, column: :hash, type: :bytea)) + add(:staking_address_hash, :bytea) + add(:mining_address_hash, :bytea) - timestamps() + timestamps(null: false, type: :utc_datetime_usec) end - create(index(:staking_pools, [:staking_address_hash])) + create(index(:staking_pools, [:staking_address_hash], unique: true)) create(index(:staking_pools, [:mining_address_hash])) end end From b13019f4e865a21f1e11466de9ca473907483ec3 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 11:57:53 +0300 Subject: [PATCH 06/53] update staking pools import runner --- .../chain/import/runner/staking_pools.ex | 55 +++++++++++-------- .../import/runner/staking_pools_test.exs | 19 ++++--- .../test/explorer/chain/staking_pool_test.exs | 2 +- apps/explorer/test/support/factory.ex | 4 +- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index b21c0c4441..b5024f30cd 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -1,12 +1,12 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do @moduledoc """ - Bulk imports staking pools to Address.Name tabe. + Bulk imports staking pools to StakingPool tabe. """ require Ecto.Query alias Ecto.{Changeset, Multi, Repo} - alias Explorer.Chain.{Address, Import} + alias Explorer.Chain.{Import, StakingPool, Wei} import Ecto.Query, only: [from: 2] @@ -15,10 +15,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do # milliseconds @timeout 60_000 - @type imported :: [Address.Name.t()] + @type imported :: [StakingPool.t()] @impl Import.Runner - def ecto_schema_module, do: Address.Name + def ecto_schema_module, do: StakingPool @impl Import.Runner def option_key, do: :staking_pools @@ -53,17 +53,15 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do def timeout, do: @timeout defp mark_as_deleted(repo, changes_list, %{timeout: timeout}) when is_list(changes_list) do - addresses = Enum.map(changes_list, & &1.address_hash) + addresses = Enum.map(changes_list, & &1.staking_address_hash) query = from( - address_name in Address.Name, - where: - address_name.address_hash not in ^addresses and - fragment("(?->>'is_pool')::boolean = true", address_name.metadata), + pool in StakingPool, + where: pool.staking_address_hash not in ^addresses, update: [ set: [ - metadata: fragment("? || '{\"deleted\": true}'::jsonb", address_name.metadata) + is_deleted: true ] ] ) @@ -83,7 +81,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do required(:timeout) => timeout, required(:timestamps) => Import.timestamps() }) :: - {:ok, [Address.Name.t()]} + {:ok, [StakingPool.t()]} | {:error, [Changeset.t()]} defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0) @@ -92,10 +90,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do Import.insert_changes_list( repo, stakes_ratio(changes_list), - conflict_target: {:unsafe_fragment, "(address_hash) where \"primary\" = true"}, + conflict_target: :staking_address_hash, on_conflict: on_conflict, - for: Address.Name, - returning: [:address_hash], + for: StakingPool, + returning: [:staking_address_hash], timeout: timeout, timestamps: timestamps ) @@ -103,11 +101,23 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do defp default_on_conflict do from( - name in Address.Name, + name in StakingPool, update: [ set: [ - name: fragment("EXCLUDED.name"), - metadata: fragment("EXCLUDED.metadata"), + mining_address_hash: fragment("EXCLUDED.mining_address_hash"), + delegators_count: fragment("EXCLUDED.delegators_count"), + is_active: fragment("EXCLUDED.is_active"), + is_banned: fragment("EXCLUDED.is_banned"), + is_validator: fragment("EXCLUDED.is_validator"), + likelihood: fragment("EXCLUDED.likelihood"), + staked_ratio: fragment("EXCLUDED.staked_ratio"), + min_candidate_stake: fragment("EXCLUDED.min_candidate_stake"), + min_delegator_stake: fragment("EXCLUDED.min_delegator_stake"), + self_staked_amount: fragment("EXCLUDED.self_staked_amount"), + staked_amount: fragment("EXCLUDED.staked_amount"), + was_banned_count: fragment("EXCLUDED.was_banned_count"), + was_validator_count: fragment("EXCLUDED.was_validator_count"), + is_deleted: fragment("EXCLUDED.is_deleted"), inserted_at: fragment("LEAST(?, EXCLUDED.inserted_at)", name.inserted_at), updated_at: fragment("GREATEST(?, EXCLUDED.updated_at)", name.updated_at) ] @@ -117,17 +127,18 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do # Calculates staked ratio for each pool defp stakes_ratio(pools) do - active_pools = Enum.filter(pools, & &1.metadata[:is_active]) + active_pools = Enum.filter(pools, & &1.is_active) stakes_total = - Enum.reduce(pools, 0, fn pool, acc -> - acc + pool.metadata[:staked_amount] + pools + |> Enum.reduce(0, fn pool, acc -> + acc + Wei.to(pool.staked_amount, :integer) end) Enum.map(active_pools, fn pool -> - staked_ratio = if stakes_total > 0, do: pool.metadata[:staked_amount] / stakes_total, else: 0 + staked_ratio = if stakes_total > 0, do: Wei.to(pool.staked_amount, :integer) / stakes_total, else: 0 - put_in(pool, [:metadata, :staked_ratio], staked_ratio) + Map.put(pool, :staked_ratio, staked_ratio) end) end end diff --git a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs index af25368679..138d7f3854 100644 --- a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs @@ -5,25 +5,30 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do alias Ecto.Multi alias Explorer.Chain.Import.Runner.StakingPools + alias Explorer.Chain.StakingPool describe "run/1" do test "insert new pools list" do - pools = [pool1, pool2, pool3, pool4] = build_list(4, :staking_pool) + pools = + [pool1, pool2] = + [params_for(:staking_pool), params_for(:staking_pool)] + |> Enum.map(fn param -> + changeset = StakingPool.changeset(%StakingPool{}, param) + changeset.changes + end) assert {:ok, %{insert_staking_pools: list}} = run_changes(pools) assert Enum.count(list) == Enum.count(pools) saved_list = - Explorer.Chain.Address.Name + Explorer.Chain.StakingPool |> Repo.all() |> Enum.reduce(%{}, fn pool, acc -> - Map.put(acc, pool.address_hash, pool) + Map.put(acc, pool.staking_address_hash, pool) end) - assert saved_list[pool1.address_hash].metadata["staked_ratio"] == 0.25 - assert saved_list[pool2.address_hash].metadata["staked_ratio"] == 0.25 - assert saved_list[pool3.address_hash].metadata["staked_ratio"] == 0.25 - assert saved_list[pool4.address_hash].metadata["staked_ratio"] == 0.25 + assert saved_list[pool1.staking_address_hash].staked_ratio == Decimal.from_float(0.5) + assert saved_list[pool2.staking_address_hash].staked_ratio == Decimal.from_float(0.5) end end diff --git a/apps/explorer/test/explorer/chain/staking_pool_test.exs b/apps/explorer/test/explorer/chain/staking_pool_test.exs index 78d01a0f19..22450071a5 100644 --- a/apps/explorer/test/explorer/chain/staking_pool_test.exs +++ b/apps/explorer/test/explorer/chain/staking_pool_test.exs @@ -6,7 +6,7 @@ defmodule Explorer.Chain.StakingPoolTest do describe "changeset/2" do test "with valid attributes" do params = params_for(:staking_pool) - changeset = StakingPool.changeset(%StakingPool{}, params) |> IO.inspect() + changeset = StakingPool.changeset(%StakingPool{}, params) assert changeset.valid? end diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 6a08c2df8b..45bf3f0b54 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -626,10 +626,10 @@ defmodule Explorer.Factory do self_staked_amount: wei_per_ether * 300, was_banned_count: 0, was_validator_count: 1, - min_delegators_stake: wei_per_ether * 100, + min_delegator_stake: wei_per_ether * 100, min_candidate_stake: wei_per_ether * 200, staked_ratio: 0, - likelihood: 0, + likelihood: 0 } end end From e3c3d4be03e15dc7ce51aa0a192339b6fbcd55c3 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 13:48:41 +0300 Subject: [PATCH 07/53] calculating stakes ratio and likelihood after insert --- .../chain/import/runner/staking_pools.ex | 58 +++++++++++++------ .../lib/explorer/chain/staking_pool.ex | 41 +++++++------ .../20190521104412_create_staking_pools.exs | 4 +- .../import/runner/staking_pools_test.exs | 4 +- apps/explorer/test/support/factory.ex | 4 +- 5 files changed, 68 insertions(+), 43 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index b5024f30cd..3a698ad9f5 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -6,7 +6,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do require Ecto.Query alias Ecto.{Changeset, Multi, Repo} - alias Explorer.Chain.{Import, StakingPool, Wei} + alias Explorer.Chain.{Import, StakingPool} import Ecto.Query, only: [from: 2] @@ -47,6 +47,9 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do |> Multi.run(:insert_staking_pools, fn repo, _ -> insert(repo, changes_list, insert_options) end) + |> Multi.run(:calculate_stakes_ratio, fn repo, _ -> + calculate_stakes_ratio(repo, insert_options) + end) end @impl Import.Runner @@ -61,7 +64,8 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do where: pool.staking_address_hash not in ^addresses, update: [ set: [ - is_deleted: true + is_deleted: true, + is_active: false ] ] ) @@ -89,7 +93,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do {:ok, _} = Import.insert_changes_list( repo, - stakes_ratio(changes_list), + changes_list, conflict_target: :staking_address_hash, on_conflict: on_conflict, for: StakingPool, @@ -125,20 +129,38 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do ) end - # Calculates staked ratio for each pool - defp stakes_ratio(pools) do - active_pools = Enum.filter(pools, & &1.is_active) - - stakes_total = - pools - |> Enum.reduce(0, fn pool, acc -> - acc + Wei.to(pool.staked_amount, :integer) - end) - - Enum.map(active_pools, fn pool -> - staked_ratio = if stakes_total > 0, do: Wei.to(pool.staked_amount, :integer) / stakes_total, else: 0 - - Map.put(pool, :staked_ratio, staked_ratio) - end) + defp calculate_stakes_ratio(repo, %{timeout: timeout}) do + try do + total_query = + from( + pool in StakingPool, + where: pool.is_active == true, + select: sum(pool.staked_amount) + ) + + total = repo.one!(total_query) + + if total > 0 do + query = + from( + p in StakingPool, + where: p.is_active == true, + update: [ + set: [ + staked_ratio: p.staked_amount / ^total * 100, + likelihood: p.staked_amount / ^total * 100 + ] + ] + ) + + {count, _} = repo.update_all(query, [], timeout: timeout) + {:ok, count} + else + {:ok, 0} + end + rescue + postgrex_error in Postgrex.Error -> + {:error, %{exception: postgrex_error}} + end end end diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index 10e678df25..e04e5bd19f 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -13,23 +13,23 @@ defmodule Explorer.Chain.StakingPool do } @type t :: %__MODULE__{ - staking_address_hash: Hash.Address.t(), - mining_address_hash: Hash.Address.t(), - banned_until: boolean, - delegators_count: integer, - is_active: boolean, - is_banned: boolean, - is_validator: boolean, - likelihood: integer, - staked_ratio: Decimal.t(), - min_candidate_stake: Wei.t(), - min_delegator_stake: Wei.t(), - self_staked_amount: Wei.t(), - staked_amount: Wei.t(), - was_banned_count: integer, - was_validator_count: integer, - is_deleted: boolean - } + staking_address_hash: Hash.Address.t(), + mining_address_hash: Hash.Address.t(), + banned_until: boolean, + delegators_count: integer, + is_active: boolean, + is_banned: boolean, + is_validator: boolean, + likelihood: integer, + staked_ratio: Decimal.t(), + min_candidate_stake: Wei.t(), + min_delegator_stake: Wei.t(), + self_staked_amount: Wei.t(), + staked_amount: Wei.t(), + was_banned_count: integer, + was_validator_count: integer, + is_deleted: boolean + } @attrs ~w( is_active delegators_count staked_amount self_staked_amount is_validator @@ -37,6 +37,11 @@ defmodule Explorer.Chain.StakingPool do staked_ratio min_delegator_stake min_candidate_stake staking_address_hash mining_address_hash )a + @req_attrs ~w( + is_active delegators_count staked_amount self_staked_amount is_validator + was_validator_count is_banned was_banned_count banned_until min_delegator_stake + min_candidate_stake staking_address_hash mining_address_hash + )a schema "staking_pools" do field(:banned_until, :integer) @@ -77,7 +82,7 @@ defmodule Explorer.Chain.StakingPool do def changeset(staking_pool, attrs) do staking_pool |> cast(attrs, @attrs) - |> validate_required(@attrs) + |> validate_required(@req_attrs) |> validate_staked_amount() |> unique_constraint(:staking_address_hash) end diff --git a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs index aabef14d1a..739815e79b 100644 --- a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs +++ b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs @@ -13,8 +13,8 @@ defmodule Explorer.Repo.Migrations.CreateStakingPools do add(:is_banned, :boolean, default: false, null: false) add(:was_banned_count, :integer) add(:banned_until, :bigint) - add(:likelihood, :decimal) - add(:staked_ratio, :decimal) + add(:likelihood, :decimal, precision: 5, scale: 2) + add(:staked_ratio, :decimal, precision: 5, scale: 2) add(:min_delegator_stake, :numeric, precision: 100) add(:min_candidate_stake, :numeric, precision: 100) add(:staking_address_hash, :bytea) diff --git a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs index 138d7f3854..1c56fe294c 100644 --- a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs @@ -27,8 +27,8 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do Map.put(acc, pool.staking_address_hash, pool) end) - assert saved_list[pool1.staking_address_hash].staked_ratio == Decimal.from_float(0.5) - assert saved_list[pool2.staking_address_hash].staked_ratio == Decimal.from_float(0.5) + assert saved_list[pool1.staking_address_hash].staked_ratio == Decimal.new("50.00") + assert saved_list[pool2.staking_address_hash].staked_ratio == Decimal.new("50.00") end end diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 45bf3f0b54..627f8b1ee7 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -627,9 +627,7 @@ defmodule Explorer.Factory do was_banned_count: 0, was_validator_count: 1, min_delegator_stake: wei_per_ether * 100, - min_candidate_stake: wei_per_ether * 200, - staked_ratio: 0, - likelihood: 0 + min_candidate_stake: wei_per_ether * 200 } end end From 679e45cfa1f1bd1f180809c0af0ccf208435a444 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 13:57:06 +0300 Subject: [PATCH 08/53] min candidate and delegator stake are constants --- .../lib/explorer/chain/import/runner/staking_pools.ex | 6 ++---- apps/explorer/lib/explorer/chain/staking_pool.ex | 11 +++-------- .../20190521104412_create_staking_pools.exs | 2 -- apps/explorer/test/support/factory.ex | 4 +--- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index 3a698ad9f5..d30ca934fa 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -115,8 +115,6 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do is_validator: fragment("EXCLUDED.is_validator"), likelihood: fragment("EXCLUDED.likelihood"), staked_ratio: fragment("EXCLUDED.staked_ratio"), - min_candidate_stake: fragment("EXCLUDED.min_candidate_stake"), - min_delegator_stake: fragment("EXCLUDED.min_delegator_stake"), self_staked_amount: fragment("EXCLUDED.self_staked_amount"), staked_amount: fragment("EXCLUDED.staked_amount"), was_banned_count: fragment("EXCLUDED.was_banned_count"), @@ -140,7 +138,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do total = repo.one!(total_query) - if total > 0 do + if total > Decimal.new(0) do query = from( p in StakingPool, @@ -156,7 +154,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do {count, _} = repo.update_all(query, [], timeout: timeout) {:ok, count} else - {:ok, 0} + {:ok, 1} end rescue postgrex_error in Postgrex.Error -> diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index e04e5bd19f..297ee8d06d 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -22,8 +22,6 @@ defmodule Explorer.Chain.StakingPool do is_validator: boolean, likelihood: integer, staked_ratio: Decimal.t(), - min_candidate_stake: Wei.t(), - min_delegator_stake: Wei.t(), self_staked_amount: Wei.t(), staked_amount: Wei.t(), was_banned_count: integer, @@ -34,13 +32,12 @@ defmodule Explorer.Chain.StakingPool do @attrs ~w( is_active delegators_count staked_amount self_staked_amount is_validator was_validator_count is_banned was_banned_count banned_until likelihood - staked_ratio min_delegator_stake min_candidate_stake - staking_address_hash mining_address_hash + staked_ratio staking_address_hash mining_address_hash )a @req_attrs ~w( is_active delegators_count staked_amount self_staked_amount is_validator - was_validator_count is_banned was_banned_count banned_until min_delegator_stake - min_candidate_stake staking_address_hash mining_address_hash + was_validator_count is_banned was_banned_count banned_until + staking_address_hash mining_address_hash )a schema "staking_pools" do @@ -51,8 +48,6 @@ defmodule Explorer.Chain.StakingPool do field(:is_validator, :boolean, default: false) field(:likelihood, :decimal) field(:staked_ratio, :decimal) - field(:min_candidate_stake, Wei) - field(:min_delegator_stake, Wei) field(:self_staked_amount, Wei) field(:staked_amount, Wei) field(:was_banned_count, :integer) diff --git a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs index 739815e79b..94483112f2 100644 --- a/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs +++ b/apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs @@ -15,8 +15,6 @@ defmodule Explorer.Repo.Migrations.CreateStakingPools do add(:banned_until, :bigint) add(:likelihood, :decimal, precision: 5, scale: 2) add(:staked_ratio, :decimal, precision: 5, scale: 2) - add(:min_delegator_stake, :numeric, precision: 100) - add(:min_candidate_stake, :numeric, precision: 100) add(:staking_address_hash, :bytea) add(:mining_address_hash, :bytea) diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 627f8b1ee7..97a449f33e 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -625,9 +625,7 @@ defmodule Explorer.Factory do staked_amount: wei_per_ether * 500, self_staked_amount: wei_per_ether * 300, was_banned_count: 0, - was_validator_count: 1, - min_delegator_stake: wei_per_ether * 100, - min_candidate_stake: wei_per_ether * 200 + was_validator_count: 1 } end end From 109bba9dc1074ca73b0c7d05d00c58b984e6fce0 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 14:18:14 +0300 Subject: [PATCH 09/53] update pools reader test --- apps/explorer/lib/explorer/staking/pools_reader.ex | 4 ++-- apps/explorer/test/explorer/staking/pools_reader_test.exs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/explorer/lib/explorer/staking/pools_reader.ex b/apps/explorer/lib/explorer/staking/pools_reader.ex index 608fea3863..1c88e09493 100644 --- a/apps/explorer/lib/explorer/staking/pools_reader.ex +++ b/apps/explorer/lib/explorer/staking/pools_reader.ex @@ -38,8 +38,8 @@ defmodule Explorer.Staking.PoolsReader do { :ok, %{ - staking_address: staking_address, - mining_address: mining_address, + staking_address_hash: staking_address, + mining_address_hash: mining_address, is_active: is_active, delegators_count: delegators_count, staked_amount: staked_amount, diff --git a/apps/explorer/test/explorer/staking/pools_reader_test.exs b/apps/explorer/test/explorer/staking/pools_reader_test.exs index bb3af9fbcc..9608a2b3f5 100644 --- a/apps/explorer/test/explorer/staking/pools_reader_test.exs +++ b/apps/explorer/test/explorer/staking/pools_reader_test.exs @@ -40,11 +40,11 @@ defmodule Explorer.Token.PoolsReaderTest do is_active: true, is_banned: false, is_validator: true, - mining_address: + mining_address_hash: <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>>, staked_amount: 0, self_staked_amount: 0, - staking_address: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>, + staking_address_hash: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>, was_banned_count: 0, was_validator_count: 2 } From 8d2ecb9f6124cf7eed95ed7136ac56a2f4d2d226 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 14:18:32 +0300 Subject: [PATCH 10/53] update pools fetcher --- .../lib/indexer/fetcher/staking_pools.ex | 34 +++++++------------ .../indexer/fetcher/staking_pools_test.exs | 8 ++--- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/apps/indexer/lib/indexer/fetcher/staking_pools.ex b/apps/indexer/lib/indexer/fetcher/staking_pools.ex index fe4ab84c28..1632229e08 100644 --- a/apps/indexer/lib/indexer/fetcher/staking_pools.ex +++ b/apps/indexer/lib/indexer/fetcher/staking_pools.ex @@ -9,6 +9,7 @@ defmodule Indexer.Fetcher.StakingPools do require Logger alias Explorer.Chain + alias Explorer.Chain.StakingPool alias Explorer.Staking.PoolsReader alias Indexer.BufferedTask alias Indexer.Fetcher.StakingPools.Supervisor, as: StakingPoolsSupervisor @@ -71,7 +72,7 @@ defmodule Indexer.Fetcher.StakingPools do def entry(pool_address) do %{ - staking_address: pool_address, + staking_address_hash: pool_address, retries_count: 0 } end @@ -79,7 +80,7 @@ defmodule Indexer.Fetcher.StakingPools do defp fetch_from_blockchain(addresses) do addresses |> Enum.filter(&(&1.retries_count <= @max_retries)) - |> Enum.map(fn %{staking_address: staking_address} = pool -> + |> Enum.map(fn %{staking_address_hash: staking_address} = pool -> case PoolsReader.pool_data(staking_address) do {:ok, data} -> Map.merge(pool, data) @@ -93,11 +94,17 @@ defmodule Indexer.Fetcher.StakingPools do defp import_pools(pools) do {failed, success} = Enum.reduce(pools, {[], []}, fn - %{error: _error, staking_address: address}, {failed, success} -> + %{error: _error, staking_address_hash: address}, {failed, success} -> {[address | failed], success} - pool, {failed, success} -> - {failed, [changeset(pool) | success]} + %{staking_address_hash: address} = pool, {failed, success} -> + changeset = StakingPool.changeset(%StakingPool{}, pool) + + if changeset.valid? do + {failed, [changeset.changes | success]} + else + {[address | failed], success} + end end) import_params = %{ @@ -117,21 +124,4 @@ defmodule Indexer.Fetcher.StakingPools do failed end - - defp changeset(%{staking_address: staking_address} = pool) do - {:ok, mining_address} = Chain.Hash.Address.cast(pool[:mining_address]) - - data = - pool - |> Map.delete(:staking_address) - |> Map.put(:mining_address, mining_address) - |> Map.put(:is_pool, true) - - %{ - name: "anonymous", - primary: true, - address_hash: staking_address, - metadata: data - } - end end diff --git a/apps/indexer/test/indexer/fetcher/staking_pools_test.exs b/apps/indexer/test/indexer/fetcher/staking_pools_test.exs index 13e2c0d7ee..257c9e558c 100644 --- a/apps/indexer/test/indexer/fetcher/staking_pools_test.exs +++ b/apps/indexer/test/indexer/fetcher/staking_pools_test.exs @@ -6,7 +6,7 @@ defmodule Indexer.Fetcher.StakingPoolsTest do alias Indexer.Fetcher.StakingPools alias Explorer.Staking.PoolsReader - alias Explorer.Chain.Address + alias Explorer.Chain.StakingPool @moduletag :capture_log @@ -33,15 +33,15 @@ defmodule Indexer.Fetcher.StakingPoolsTest do success_address = list |> List.first() - |> Map.get(:staking_address) + |> Map.get(:staking_address_hash) get_pool_data_from_blockchain() assert {:retry, retry_list} = StakingPools.run(list, nil) assert Enum.count(retry_list) == 2 - pool = Explorer.Repo.get_by(Address.Name, address_hash: success_address) - assert pool.name == "anonymous" + pool = Explorer.Repo.get_by(StakingPool, staking_address_hash: success_address) + assert pool.is_active == true end end From 4728d4696a302c6d3663c10759b288f926a7fb3e Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 15:02:15 +0300 Subject: [PATCH 11/53] add delegators table and schema --- .../chain/staking_pools_delegators.ex | 64 +++++++++++++++++++ ...112839_create_staking_pools_delegators.exs | 26 ++++++++ .../chain/staking_pools_delegators_test.exs | 18 ++++++ apps/explorer/test/support/factory.ex | 17 ++++- 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 apps/explorer/lib/explorer/chain/staking_pools_delegators.ex create mode 100644 apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs create mode 100644 apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs diff --git a/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex new file mode 100644 index 0000000000..d40edfaad8 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex @@ -0,0 +1,64 @@ +defmodule Explorer.Chain.StakingPoolsDelegators do + @moduledoc """ + The representation of delegators from POSDAO network. + Delegators make stakes on staking pools and withdraw from them. + """ + use Ecto.Schema + import Ecto.Changeset + + alias Explorer.Chain.{ + Address, + Hash, + StakingPool, + Wei + } + + @type t :: %__MODULE__{ + pool_address_hash: Hash.Address.t(), + delegator_address_hash: Hash.Address.t(), + max_ordered_withdraw_allowed: Wei.t(), + max_withdraw_allowed: Wei.t(), + ordered_withdraw: Wei.t(), + stake_amount: Wei.t(), + ordered_withdraw_epoch: integer() + } + + @attrs ~w( + pool_address_hash delegator_address_hash max_ordered_withdraw_allowed + max_withdraw_allowed ordered_withdraw stake_amount ordered_withdraw_epoch + )a + + schema "staking_pools_delegators" do + field(:max_ordered_withdraw_allowed, Wei) + field(:max_withdraw_allowed, Wei) + field(:ordered_withdraw, Wei) + field(:ordered_withdraw_epoch, :integer) + field(:stake_amount, Wei) + + belongs_to( + :staking_pool, + StakingPool, + foreign_key: :pool_address_hash, + references: :staking_address_hash, + type: Hash.Address + ) + + belongs_to( + :delegator_address, + Address, + foreign_key: :delegator_address_hash, + references: :hash, + type: Hash.Address + ) + + timestamps(null: false, type: :utc_datetime_usec) + end + + @doc false + def changeset(staking_pools_delegators, attrs) do + staking_pools_delegators + |> cast(attrs, @attrs) + |> validate_required(@attrs) + |> unique_constraint(:pool_address_hash, name: :pools_delegator_index) + end +end diff --git a/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs b/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs new file mode 100644 index 0000000000..1f243771fb --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs @@ -0,0 +1,26 @@ +defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegators do + use Ecto.Migration + + def change do + create table(:staking_pools_delegators) do + add(:delegator_address_hash, :bytea) + add(:pool_address_hash, :bytea) + add(:stake_amount, :numeric, precision: 100) + add(:ordered_withdraw, :numeric, precision: 100) + add(:max_withdraw_allowed, :numeric, precision: 100) + add(:max_ordered_withdraw_allowed, :numeric, precision: 100) + add(:ordered_withdraw_epoch, :integer) + + timestamps(null: false, type: :utc_datetime_usec) + end + + create(index(:staking_pools_delegators, [:delegator_address_hash])) + + create( + index(:staking_pools_delegators, [:delegator_address_hash, :pool_address_hash], + unique: true, + name: :pools_delegator_index + ) + ) + end +end diff --git a/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs b/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs new file mode 100644 index 0000000000..a27dada2eb --- /dev/null +++ b/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs @@ -0,0 +1,18 @@ +defmodule Explorer.Chain.StakingPoolsDelegatorsTest do + use Explorer.DataCase + + alias Explorer.Chain.StakingPoolsDelegators + + describe "changeset/2" do + test "with valid attributes" do + params = params_for(:staking_pools_delegators) + changeset = StakingPoolsDelegators.changeset(%StakingPoolsDelegators{}, params) + assert changeset.valid? + end + + test "with invalid attributes" do + changeset = StakingPoolsDelegators.changeset(%StakingPoolsDelegators{}, %{pool_address_hash: 0}) + refute changeset.valid? + end + end +end diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 97a449f33e..58a16c97b9 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -27,7 +27,8 @@ defmodule Explorer.Factory do Token, TokenTransfer, Transaction, - StakingPool + StakingPool, + StakingPoolsDelegators } alias Explorer.Market.MarketHistory @@ -628,4 +629,18 @@ defmodule Explorer.Factory do was_validator_count: 1 } end + + def staking_pools_delegators_factory do + wei_per_ether = 1_000_000_000_000_000_000 + + %StakingPoolsDelegators{ + pool_address_hash: address_hash(), + delegator_address_hash: address_hash(), + max_ordered_withdraw_allowed: wei_per_ether * 100, + max_withdraw_allowed: wei_per_ether * 50, + ordered_withdraw: wei_per_ether * 600, + stake_amount: wei_per_ether * 200, + ordered_withdraw_epoch: 2 + } + end end From b6d30d4229961b1afa0c6571a46dce93e5434c91 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 15:02:44 +0300 Subject: [PATCH 12/53] mix format --- apps/explorer/test/explorer/staking/pools_reader_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/explorer/test/explorer/staking/pools_reader_test.exs b/apps/explorer/test/explorer/staking/pools_reader_test.exs index 9608a2b3f5..ec17f7b5f7 100644 --- a/apps/explorer/test/explorer/staking/pools_reader_test.exs +++ b/apps/explorer/test/explorer/staking/pools_reader_test.exs @@ -44,7 +44,8 @@ defmodule Explorer.Token.PoolsReaderTest do <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>>, staked_amount: 0, self_staked_amount: 0, - staking_address_hash: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>, + staking_address_hash: + <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>, was_banned_count: 0, was_validator_count: 2 } From 2a25481663fcff78e881c17399f99df84c73f04d Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 10:56:59 +0300 Subject: [PATCH 13/53] import staking pools delegators --- .../chain/import/runner/staking_pools.ex | 54 ++++++----- .../import/runner/staking_pools_delegators.ex | 91 +++++++++++++++++++ .../chain/import/stage/address_referencing.ex | 3 +- .../lib/explorer/chain/staking_pool.ex | 3 + .../lib/explorer/staking/pools_reader.ex | 47 ++++++++-- .../lib/indexer/fetcher/staking_pools.ex | 23 ++++- 6 files changed, 180 insertions(+), 41 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index d30ca934fa..d7655674d8 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -128,37 +128,35 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do end defp calculate_stakes_ratio(repo, %{timeout: timeout}) do - try do - total_query = - from( - pool in StakingPool, - where: pool.is_active == true, - select: sum(pool.staked_amount) - ) + total_query = + from( + pool in StakingPool, + where: pool.is_active == true, + select: sum(pool.staked_amount) + ) + + total = repo.one!(total_query) - total = repo.one!(total_query) - - if total > Decimal.new(0) do - query = - from( - p in StakingPool, - where: p.is_active == true, - update: [ - set: [ - staked_ratio: p.staked_amount / ^total * 100, - likelihood: p.staked_amount / ^total * 100 - ] + if total > Decimal.new(0) do + query = + from( + p in StakingPool, + where: p.is_active == true, + update: [ + set: [ + staked_ratio: p.staked_amount / ^total * 100, + likelihood: p.staked_amount / ^total * 100 ] - ) + ] + ) - {count, _} = repo.update_all(query, [], timeout: timeout) - {:ok, count} - else - {:ok, 1} - end - rescue - postgrex_error in Postgrex.Error -> - {:error, %{exception: postgrex_error}} + {count, _} = repo.update_all(query, [], timeout: timeout) + {:ok, count} + else + {:ok, 1} end + rescue + postgrex_error in Postgrex.Error -> + {:error, %{exception: postgrex_error}} end end diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex new file mode 100644 index 0000000000..5d44d68a92 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex @@ -0,0 +1,91 @@ +defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do + @moduledoc """ + Bulk imports staking pools to StakingPoolsDelegators tabe. + """ + + require Ecto.Query + + alias Ecto.{Changeset, Multi, Repo} + alias Explorer.Chain.{Import, StakingPoolsDelegators} + + import Ecto.Query, only: [from: 2] + + @behaviour Import.Runner + + # milliseconds + @timeout 60_000 + + @type imported :: [StakingPoolsDelegators.t()] + + @impl Import.Runner + def ecto_schema_module, do: StakingPoolsDelegators + + @impl Import.Runner + def option_key, do: :staking_pools_delegators + + @impl Import.Runner + def imported_table_row do + %{ + value_type: "[#{ecto_schema_module()}.t()]", + value_description: "List of `t:#{ecto_schema_module()}.t/0`s" + } + end + + @impl Import.Runner + def run(multi, changes_list, %{timestamps: timestamps} = options) do + insert_options = + options + |> Map.get(option_key(), %{}) + |> Map.take(~w(on_conflict timeout)a) + |> Map.put_new(:timeout, @timeout) + |> Map.put(:timestamps, timestamps) + + multi + |> Multi.run(:insert_staking_pools_delegators, fn repo, _ -> + insert(repo, changes_list, insert_options) + end) + end + + @impl Import.Runner + def timeout, do: @timeout + + @spec insert(Repo.t(), [map()], %{ + optional(:on_conflict) => Import.Runner.on_conflict(), + required(:timeout) => timeout, + required(:timestamps) => Import.timestamps() + }) :: + {:ok, [StakingPoolsDelegators.t()]} + | {:error, [Changeset.t()]} + defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do + on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0) + + {:ok, _} = + Import.insert_changes_list( + repo, + changes_list, + conflict_target: [:pool_address_hash, :delegator_address_hash], + on_conflict: on_conflict, + for: StakingPoolsDelegators, + returning: [:pool_address_hash, :delegator_address_hash], + timeout: timeout, + timestamps: timestamps + ) + end + + defp default_on_conflict do + from( + name in StakingPoolsDelegators, + update: [ + set: [ + stake_amount: fragment("EXCLUDED.stake_amount"), + ordered_withdraw: fragment("EXCLUDED.ordered_withdraw"), + max_withdraw_allowed: fragment("EXCLUDED.max_withdraw_allowed"), + max_ordered_withdraw_allowed: fragment("EXCLUDED.max_ordered_withdraw_allowed"), + ordered_withdraw_epoch: fragment("EXCLUDED.ordered_withdraw_epoch"), + inserted_at: fragment("LEAST(?, EXCLUDED.inserted_at)", name.inserted_at), + updated_at: fragment("GREATEST(?, EXCLUDED.updated_at)", name.updated_at) + ] + ] + ) + end +end diff --git a/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex b/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex index 0e42bdc1f9..b5037f3b04 100644 --- a/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex +++ b/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex @@ -25,7 +25,8 @@ defmodule Explorer.Chain.Import.Stage.AddressReferencing do Runner.TokenTransfers, Runner.Address.CurrentTokenBalances, Runner.Address.TokenBalances, - Runner.StakingPools + Runner.StakingPools, + Runner.StakingPoolsDelegators ] @impl Stage diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index 297ee8d06d..31c5b1cc26 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -9,6 +9,7 @@ defmodule Explorer.Chain.StakingPool do alias Explorer.Chain.{ Address, Hash, + StakingPoolsDelegators, Wei } @@ -53,6 +54,7 @@ defmodule Explorer.Chain.StakingPool do field(:was_banned_count, :integer) field(:was_validator_count, :integer) field(:is_deleted, :boolean, default: false) + has_many(:delegators, StakingPoolsDelegators) belongs_to( :staking_address, @@ -77,6 +79,7 @@ defmodule Explorer.Chain.StakingPool do def changeset(staking_pool, attrs) do staking_pool |> cast(attrs, @attrs) + |> cast_assoc(:delegators) |> validate_required(@req_attrs) |> validate_staked_amount() |> unique_constraint(:staking_address_hash) diff --git a/apps/explorer/lib/explorer/staking/pools_reader.ex b/apps/explorer/lib/explorer/staking/pools_reader.ex index 1c88e09493..0c04c8e570 100644 --- a/apps/explorer/lib/explorer/staking/pools_reader.ex +++ b/apps/explorer/lib/explorer/staking/pools_reader.ex @@ -24,10 +24,11 @@ defmodule Explorer.Staking.PoolsReader do @spec pool_data(String.t()) :: {:ok, map()} | :error def pool_data(staking_address) do with {:ok, [mining_address]} <- call_validators_method("miningByStakingAddress", [staking_address]), - data = fetch_data(staking_address, mining_address), + data = fetch_pool_data(staking_address, mining_address), {:ok, [is_active]} <- data["isPoolActive"], {:ok, [delegator_addresses]} <- data["poolDelegators"], delegators_count = Enum.count(delegator_addresses), + delegators = delegators_data(delegator_addresses, staking_address), {:ok, [staked_amount]} <- data["stakeAmountTotalMinusOrderedWithdraw"], {:ok, [self_staked_amount]} <- data["stakeAmountMinusOrderedWithdraw"], {:ok, [is_validator]} <- data["isValidator"], @@ -48,7 +49,8 @@ defmodule Explorer.Staking.PoolsReader do was_validator_count: was_validator_count, is_banned: is_banned, banned_until: banned_until, - was_banned_count: was_banned_count + was_banned_count: was_banned_count, + delegators: delegators } } else @@ -57,6 +59,35 @@ defmodule Explorer.Staking.PoolsReader do end end + defp delegators_data(delegators, pool_address) do + Enum.map(delegators, fn address -> + data = + call_methods([ + {:staking, "stakeAmount", [pool_address, address]}, + {:staking, "orderedWithdrawAmount", [pool_address, address]}, + {:staking, "maxWithdrawAllowed", [pool_address, address]}, + {:staking, "maxWithdrawOrderAllowed", [pool_address, address]}, + {:staking, "orderWithdrawEpoch", [pool_address, address]} + ]) + + {:ok, [stake_amount]} = data["stakeAmount"] + {:ok, [ordered_withdraw]} = data["orderedWithdrawAmount"] + {:ok, [max_withdraw_allowed]} = data["maxWithdrawAllowed"] + {:ok, [max_ordered_withdraw_allowed]} = data["maxWithdrawOrderAllowed"] + {:ok, [ordered_withdraw_epoch]} = data["orderWithdrawEpoch"] + + %{ + delegator_address_hash: address, + pool_address_hash: pool_address, + stake_amount: stake_amount, + ordered_withdraw: ordered_withdraw, + max_withdraw_allowed: max_withdraw_allowed, + max_ordered_withdraw_allowed: max_ordered_withdraw_allowed, + ordered_withdraw_epoch: ordered_withdraw_epoch + } + end) + end + defp call_staking_method(method, params) do %{^method => resp} = Reader.query_contract(config(:staking_contract_address), abi("staking.json"), %{ @@ -75,10 +106,8 @@ defmodule Explorer.Staking.PoolsReader do resp end - defp fetch_data(staking_address, mining_address) do - contract_abi = abi("staking.json") ++ abi("validators.json") - - methods = [ + defp fetch_pool_data(staking_address, mining_address) do + call_methods([ {:staking, "isPoolActive", [staking_address]}, {:staking, "poolDelegators", [staking_address]}, {:staking, "stakeAmountTotalMinusOrderedWithdraw", [staking_address]}, @@ -88,7 +117,11 @@ defmodule Explorer.Staking.PoolsReader do {:validators, "isValidatorBanned", [mining_address]}, {:validators, "bannedUntil", [mining_address]}, {:validators, "banCounter", [mining_address]} - ] + ]) + end + + defp call_methods(methods) do + contract_abi = abi("staking.json") ++ abi("validators.json") methods |> Enum.map(&format_request/1) diff --git a/apps/indexer/lib/indexer/fetcher/staking_pools.ex b/apps/indexer/lib/indexer/fetcher/staking_pools.ex index 1632229e08..e5fb5485a6 100644 --- a/apps/indexer/lib/indexer/fetcher/staking_pools.ex +++ b/apps/indexer/lib/indexer/fetcher/staking_pools.ex @@ -94,21 +94,22 @@ defmodule Indexer.Fetcher.StakingPools do defp import_pools(pools) do {failed, success} = Enum.reduce(pools, {[], []}, fn - %{error: _error, staking_address_hash: address}, {failed, success} -> - {[address | failed], success} + %{error: _error} = pool, {failed, success} -> + {[pool | failed], success} - %{staking_address_hash: address} = pool, {failed, success} -> + pool, {failed, success} -> changeset = StakingPool.changeset(%StakingPool{}, pool) if changeset.valid? do {failed, [changeset.changes | success]} else - {[address | failed], success} + {[pool | failed], success} end end) import_params = %{ - staking_pools: %{params: success}, + staking_pools: %{params: remove_assoc(success)}, + staking_pools_delegators: %{params: delegators_list(success)}, timeout: :infinity } @@ -124,4 +125,16 @@ defmodule Indexer.Fetcher.StakingPools do failed end + + defp delegators_list(pools) do + Enum.reduce(pools, [], fn pool, acc -> + pool.delegators + |> Enum.map(pool.delegators, &Map.get(&1, :changes)) + |> Enum.concat(acc) + end) + end + + defp remove_assoc(pools) do + Enum.map(pools, &Map.delete(&1, :delegators)) + end end From 93bd9f0a00280408fd6f939ea9cc7ee285f1680c Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 11:04:43 +0300 Subject: [PATCH 14/53] rename delegators module --- .../import/runner/staking_pools_delegators.ex | 14 +++++++------- .../lib/explorer/chain/staking_pool.ex | 4 ++-- ...elegators.ex => staking_pools_delegator.ex} | 6 +++--- ...3112839_create_staking_pools_delegators.exs | 2 +- .../chain/staking_pools_delegator_test.exs | 18 ++++++++++++++++++ .../chain/staking_pools_delegators_test.exs | 18 ------------------ apps/explorer/test/support/factory.ex | 6 +++--- 7 files changed, 34 insertions(+), 34 deletions(-) rename apps/explorer/lib/explorer/chain/{staking_pools_delegators.ex => staking_pools_delegator.ex} (92%) create mode 100644 apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs delete mode 100644 apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex index 5d44d68a92..22d62592c3 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex @@ -1,12 +1,12 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do @moduledoc """ - Bulk imports staking pools to StakingPoolsDelegators tabe. + Bulk imports staking pools to StakingPoolsDelegator tabe. """ require Ecto.Query alias Ecto.{Changeset, Multi, Repo} - alias Explorer.Chain.{Import, StakingPoolsDelegators} + alias Explorer.Chain.{Import, StakingPoolsDelegator} import Ecto.Query, only: [from: 2] @@ -15,10 +15,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do # milliseconds @timeout 60_000 - @type imported :: [StakingPoolsDelegators.t()] + @type imported :: [StakingPoolsDelegator.t()] @impl Import.Runner - def ecto_schema_module, do: StakingPoolsDelegators + def ecto_schema_module, do: StakingPoolsDelegator @impl Import.Runner def option_key, do: :staking_pools_delegators @@ -54,7 +54,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do required(:timeout) => timeout, required(:timestamps) => Import.timestamps() }) :: - {:ok, [StakingPoolsDelegators.t()]} + {:ok, [StakingPoolsDelegator.t()]} | {:error, [Changeset.t()]} defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0) @@ -65,7 +65,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do changes_list, conflict_target: [:pool_address_hash, :delegator_address_hash], on_conflict: on_conflict, - for: StakingPoolsDelegators, + for: StakingPoolsDelegator, returning: [:pool_address_hash, :delegator_address_hash], timeout: timeout, timestamps: timestamps @@ -74,7 +74,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do defp default_on_conflict do from( - name in StakingPoolsDelegators, + name in StakingPoolsDelegator, update: [ set: [ stake_amount: fragment("EXCLUDED.stake_amount"), diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index 31c5b1cc26..bb5635702d 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -9,7 +9,7 @@ defmodule Explorer.Chain.StakingPool do alias Explorer.Chain.{ Address, Hash, - StakingPoolsDelegators, + StakingPoolsDelegator, Wei } @@ -54,7 +54,7 @@ defmodule Explorer.Chain.StakingPool do field(:was_banned_count, :integer) field(:was_validator_count, :integer) field(:is_deleted, :boolean, default: false) - has_many(:delegators, StakingPoolsDelegators) + has_many(:delegators, StakingPoolsDelegator) belongs_to( :staking_address, diff --git a/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/staking_pools_delegator.ex similarity index 92% rename from apps/explorer/lib/explorer/chain/staking_pools_delegators.ex rename to apps/explorer/lib/explorer/chain/staking_pools_delegator.ex index d40edfaad8..8fabc6c447 100644 --- a/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex +++ b/apps/explorer/lib/explorer/chain/staking_pools_delegator.ex @@ -1,4 +1,4 @@ -defmodule Explorer.Chain.StakingPoolsDelegators do +defmodule Explorer.Chain.StakingPoolsDelegator do @moduledoc """ The representation of delegators from POSDAO network. Delegators make stakes on staking pools and withdraw from them. @@ -55,8 +55,8 @@ defmodule Explorer.Chain.StakingPoolsDelegators do end @doc false - def changeset(staking_pools_delegators, attrs) do - staking_pools_delegators + def changeset(staking_pools_delegator, attrs) do + staking_pools_delegator |> cast(attrs, @attrs) |> validate_required(@attrs) |> unique_constraint(:pool_address_hash, name: :pools_delegator_index) diff --git a/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs b/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs index 1f243771fb..ccf9c8c372 100644 --- a/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs +++ b/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs @@ -1,4 +1,4 @@ -defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegators do +defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegator do use Ecto.Migration def change do diff --git a/apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs b/apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs new file mode 100644 index 0000000000..222658e92e --- /dev/null +++ b/apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs @@ -0,0 +1,18 @@ +defmodule Explorer.Chain.StakingPoolsDelegatorTest do + use Explorer.DataCase + + alias Explorer.Chain.StakingPoolsDelegator + + describe "changeset/2" do + test "with valid attributes" do + params = params_for(:staking_pools_delegator) + changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, params) + assert changeset.valid? + end + + test "with invalid attributes" do + changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, %{pool_address_hash: 0}) + refute changeset.valid? + end + end +end diff --git a/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs b/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs deleted file mode 100644 index a27dada2eb..0000000000 --- a/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Explorer.Chain.StakingPoolsDelegatorsTest do - use Explorer.DataCase - - alias Explorer.Chain.StakingPoolsDelegators - - describe "changeset/2" do - test "with valid attributes" do - params = params_for(:staking_pools_delegators) - changeset = StakingPoolsDelegators.changeset(%StakingPoolsDelegators{}, params) - assert changeset.valid? - end - - test "with invalid attributes" do - changeset = StakingPoolsDelegators.changeset(%StakingPoolsDelegators{}, %{pool_address_hash: 0}) - refute changeset.valid? - end - end -end diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 58a16c97b9..9d0a2e9997 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -28,7 +28,7 @@ defmodule Explorer.Factory do TokenTransfer, Transaction, StakingPool, - StakingPoolsDelegators + StakingPoolsDelegator } alias Explorer.Market.MarketHistory @@ -630,10 +630,10 @@ defmodule Explorer.Factory do } end - def staking_pools_delegators_factory do + def staking_pools_delegator_factory do wei_per_ether = 1_000_000_000_000_000_000 - %StakingPoolsDelegators{ + %StakingPoolsDelegator{ pool_address_hash: address_hash(), delegator_address_hash: address_hash(), max_ordered_withdraw_allowed: wei_per_ether * 100, From 083f5e6f5d1a6b836b9f22c2f7a4dfcbfc8f928e Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 11:20:00 +0300 Subject: [PATCH 15/53] staking pools delegators importer test --- .../lib/explorer/chain/staking_pool.ex | 2 +- .../runner/staking_pools_delegators_test.exs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index bb5635702d..7949661c23 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -54,7 +54,7 @@ defmodule Explorer.Chain.StakingPool do field(:was_banned_count, :integer) field(:was_validator_count, :integer) field(:is_deleted, :boolean, default: false) - has_many(:delegators, StakingPoolsDelegator) + has_many(:delegators, StakingPoolsDelegator, foreign_key: :pool_address_hash) belongs_to( :staking_address, diff --git a/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs b/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs new file mode 100644 index 0000000000..4916f2ef84 --- /dev/null +++ b/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs @@ -0,0 +1,33 @@ +defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegatorsTest do + use Explorer.DataCase + + import Explorer.Factory + + alias Ecto.Multi + alias Explorer.Chain.Import.Runner.StakingPoolsDelegators + alias Explorer.Chain.StakingPoolsDelegator + + describe "run/1" do + test "insert new pools list" do + delegators = + [delegator1, delegator2] = + [params_for(:staking_pools_delegator), params_for(:staking_pools_delegator)] + |> Enum.map(fn param -> + changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, param) + changeset.changes + end) + + assert {:ok, %{insert_staking_pools_delegators: list}} = run_changes(delegators) + assert Enum.count(list) == Enum.count(delegators) + end + end + + defp run_changes(changes) do + Multi.new() + |> StakingPoolsDelegators.run(changes, %{ + timeout: :infinity, + timestamps: %{inserted_at: DateTime.utc_now(), updated_at: DateTime.utc_now()} + }) + |> Repo.transaction() + end +end From 7abfd0844bd2a36e50e38963b03f4f8d5de0e89f Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 11:23:27 +0300 Subject: [PATCH 16/53] update pools reader test --- apps/explorer/test/explorer/staking/pools_reader_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/explorer/test/explorer/staking/pools_reader_test.exs b/apps/explorer/test/explorer/staking/pools_reader_test.exs index ec17f7b5f7..aeea00c1e5 100644 --- a/apps/explorer/test/explorer/staking/pools_reader_test.exs +++ b/apps/explorer/test/explorer/staking/pools_reader_test.exs @@ -47,7 +47,8 @@ defmodule Explorer.Token.PoolsReaderTest do staking_address_hash: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>, was_banned_count: 0, - was_validator_count: 2 + was_validator_count: 2, + delegators: [] } } From 4808a8f06382166c42763bc057c232cc762c5e1f Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 12:44:51 +0300 Subject: [PATCH 17/53] update pools reader test --- .../runner/staking_pools_delegators_test.exs | 11 +- .../explorer/staking/pools_reader_test.exs | 172 ++++++++++++++---- .../lib/indexer/fetcher/staking_pools.ex | 2 +- 3 files changed, 143 insertions(+), 42 deletions(-) diff --git a/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs b/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs index 4916f2ef84..9a11e3edc8 100644 --- a/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs @@ -10,12 +10,11 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegatorsTest do describe "run/1" do test "insert new pools list" do delegators = - [delegator1, delegator2] = - [params_for(:staking_pools_delegator), params_for(:staking_pools_delegator)] - |> Enum.map(fn param -> - changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, param) - changeset.changes - end) + [params_for(:staking_pools_delegator), params_for(:staking_pools_delegator)] + |> Enum.map(fn param -> + changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, param) + changeset.changes + end) assert {:ok, %{insert_staking_pools_delegators: list}} = run_changes(delegators) assert Enum.count(list) == Enum.count(delegators) diff --git a/apps/explorer/test/explorer/staking/pools_reader_test.exs b/apps/explorer/test/explorer/staking/pools_reader_test.exs index aeea00c1e5..6fb5940010 100644 --- a/apps/explorer/test/explorer/staking/pools_reader_test.exs +++ b/apps/explorer/test/explorer/staking/pools_reader_test.exs @@ -30,27 +30,38 @@ defmodule Explorer.Token.PoolsReaderTest do test "get_pool_data success" do get_pool_data_from_blockchain() - address = <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>> + address = <<219, 156, 178, 71, 141, 145, 119, 25, 197, 56, 98, 0, 134, 114, 22, 104, 8, 37, 133, 119>> - response = { - :ok, - %{ - banned_until: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address_hash: - <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>>, - staked_amount: 0, - self_staked_amount: 0, - staking_address_hash: - <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>, - was_banned_count: 0, - was_validator_count: 2, - delegators: [] - } - } + response = + {:ok, + %{ + banned_until: 0, + is_active: true, + is_banned: false, + is_validator: true, + was_banned_count: 0, + was_validator_count: 2, + delegators: [ + %{ + delegator_address_hash: + <<243, 231, 124, 74, 245, 235, 47, 51, 175, 255, 118, 25, 216, 209, 231, 81, 215, 24, 164, 145>>, + max_ordered_withdraw_allowed: 1_000_000_000_000_000_000, + max_withdraw_allowed: 1_000_000_000_000_000_000, + ordered_withdraw: 0, + ordered_withdraw_epoch: 0, + pool_address_hash: + <<219, 156, 178, 71, 141, 145, 119, 25, 197, 56, 98, 0, 134, 114, 22, 104, 8, 37, 133, 119>>, + stake_amount: 1_000_000_000_000_000_000 + } + ], + delegators_count: 1, + mining_address_hash: + <<190, 105, 235, 9, 104, 34, 106, 24, 8, 151, 94, 26, 31, 33, 39, 102, 127, 43, 255, 179>>, + self_staked_amount: 2_000_000_000_000_000_000, + staked_amount: 3_000_000_000_000_000_000, + staking_address_hash: + <<219, 156, 178, 71, 141, 145, 119, 25, 197, 56, 98, 0, 134, 114, 22, 104, 8, 37, 133, 119>> + }} assert PoolsReader.pool_data(address) == response end @@ -103,7 +114,7 @@ defmodule Explorer.Token.PoolsReaderTest do expect( EthereumJSONRPC.Mox, :json_rpc, - 2, + 3, fn requests, _opts -> {:ok, Enum.map(requests, fn @@ -112,13 +123,13 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0x005351750000000000000000000000000b2f5e2f3cbd864eaa2c642e3769c1582361caf6", to: _}, + %{data: "0x00535175000000000000000000000000db9cb2478d917719c53862008672166808258577", to: _}, "latest" ] } -> %{ id: id, - result: "0x000000000000000000000000bbcaa8d48289bb1ffcf9808d9aa4b1d215054c78" + result: "0x000000000000000000000000be69eb0968226a1808975e1a1f2127667f2bffb3" } # isPoolActive @@ -126,7 +137,7 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0xa711e6a10000000000000000000000000b2f5e2f3cbd864eaa2c642e3769c1582361caf6", to: _}, + %{data: "0xa711e6a1000000000000000000000000db9cb2478d917719c53862008672166808258577", to: _}, "latest" ] } -> @@ -140,14 +151,14 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0x9ea8082b0000000000000000000000000b2f5e2f3cbd864eaa2c642e3769c1582361caf6", to: _}, + %{data: "0x9ea8082b000000000000000000000000db9cb2478d917719c53862008672166808258577", to: _}, "latest" ] } -> %{ id: id, result: - "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000" + "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000f3e77c4af5eb2f33afff7619d8d1e751d718a491" } # stakeAmountTotalMinusOrderedWithdraw @@ -155,13 +166,13 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0x234fbf2b0000000000000000000000000b2f5e2f3cbd864eaa2c642e3769c1582361caf6", to: _}, + %{data: "0x234fbf2b000000000000000000000000db9cb2478d917719c53862008672166808258577", to: _}, "latest" ] } -> %{ id: id, - result: "0x0000000000000000000000000000000000000000000000000000000000000000" + result: "0x00000000000000000000000000000000000000000000000029a2241af62c0000" } # stakeAmountMinusOrderedWithdraw @@ -172,7 +183,7 @@ defmodule Explorer.Token.PoolsReaderTest do params: [ %{ data: - "0x58daab6a0000000000000000000000000b2f5e2f3cbd864eaa2c642e3769c1582361caf60000000000000000000000000b2f5e2f3cbd864eaa2c642e3769c1582361caf6", + "0x58daab6a000000000000000000000000db9cb2478d917719c53862008672166808258577000000000000000000000000db9cb2478d917719c53862008672166808258577", to: _ }, "latest" @@ -180,7 +191,7 @@ defmodule Explorer.Token.PoolsReaderTest do } -> %{ id: id, - result: "0x0000000000000000000000000000000000000000000000000000000000000000" + result: "0x0000000000000000000000000000000000000000000000001bc16d674ec80000" } # isValidator @@ -188,7 +199,7 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0xfacd743b000000000000000000000000bbcaa8d48289bb1ffcf9808d9aa4b1d215054c78", to: _}, + %{data: "0xfacd743b000000000000000000000000be69eb0968226a1808975e1a1f2127667f2bffb3", to: _}, "latest" ] } -> @@ -202,7 +213,7 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0xb41832e4000000000000000000000000bbcaa8d48289bb1ffcf9808d9aa4b1d215054c78", to: _}, + %{data: "0xb41832e4000000000000000000000000be69eb0968226a1808975e1a1f2127667f2bffb3", to: _}, "latest" ] } -> @@ -216,7 +227,7 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0xa92252ae000000000000000000000000bbcaa8d48289bb1ffcf9808d9aa4b1d215054c78", to: _}, + %{data: "0xa92252ae000000000000000000000000be69eb0968226a1808975e1a1f2127667f2bffb3", to: _}, "latest" ] } -> @@ -230,7 +241,7 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0x5836d08a000000000000000000000000bbcaa8d48289bb1ffcf9808d9aa4b1d215054c78", to: _}, + %{data: "0x5836d08a000000000000000000000000be69eb0968226a1808975e1a1f2127667f2bffb3", to: _}, "latest" ] } -> @@ -244,7 +255,98 @@ defmodule Explorer.Token.PoolsReaderTest do id: id, method: "eth_call", params: [ - %{data: "0x1d0cd4c6000000000000000000000000bbcaa8d48289bb1ffcf9808d9aa4b1d215054c78", to: _}, + %{data: "0x1d0cd4c6000000000000000000000000be69eb0968226a1808975e1a1f2127667f2bffb3", to: _}, + "latest" + ] + } -> + %{ + id: id, + result: "0x0000000000000000000000000000000000000000000000000000000000000000" + } + + # DELEGATOR + # stakeAmount + %{ + id: id, + method: "eth_call", + params: [ + %{ + data: + "0xa697ecff000000000000000000000000db9cb2478d917719c53862008672166808258577000000000000000000000000f3e77c4af5eb2f33afff7619d8d1e751d718a491", + to: _ + }, + "latest" + ] + } -> + %{ + id: id, + result: "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000" + } + + # orderedWithdrawAmount + %{ + id: id, + method: "eth_call", + params: [ + %{ + data: + "0xe9ab0300000000000000000000000000db9cb2478d917719c53862008672166808258577000000000000000000000000f3e77c4af5eb2f33afff7619d8d1e751d718a491", + to: _ + }, + "latest" + ] + } -> + %{ + id: id, + result: "0x0000000000000000000000000000000000000000000000000000000000000000" + } + + # maxWithdrawAllowed + %{ + id: id, + method: "eth_call", + params: [ + %{ + data: + "0x6bda1577000000000000000000000000db9cb2478d917719c53862008672166808258577000000000000000000000000f3e77c4af5eb2f33afff7619d8d1e751d718a491", + to: _ + }, + "latest" + ] + } -> + %{ + id: id, + result: "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000" + } + + # maxWithdrawOrderAllowed + %{ + id: id, + method: "eth_call", + params: [ + %{ + data: + "0x950a6513000000000000000000000000db9cb2478d917719c53862008672166808258577000000000000000000000000f3e77c4af5eb2f33afff7619d8d1e751d718a491", + to: _ + }, + "latest" + ] + } -> + %{ + id: id, + result: "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000" + } + + # orderWithdrawEpoch + %{ + id: id, + method: "eth_call", + params: [ + %{ + data: + "0xa4205967000000000000000000000000db9cb2478d917719c53862008672166808258577000000000000000000000000f3e77c4af5eb2f33afff7619d8d1e751d718a491", + to: _ + }, "latest" ] } -> diff --git a/apps/indexer/lib/indexer/fetcher/staking_pools.ex b/apps/indexer/lib/indexer/fetcher/staking_pools.ex index e5fb5485a6..1576eb56e2 100644 --- a/apps/indexer/lib/indexer/fetcher/staking_pools.ex +++ b/apps/indexer/lib/indexer/fetcher/staking_pools.ex @@ -129,7 +129,7 @@ defmodule Indexer.Fetcher.StakingPools do defp delegators_list(pools) do Enum.reduce(pools, [], fn pool, acc -> pool.delegators - |> Enum.map(pool.delegators, &Map.get(&1, :changes)) + |> Enum.map(&Map.get(&1, :changes)) |> Enum.concat(acc) end) end From 0c0662d86e6340e51cfce84fc300ba037165072f Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 13:58:03 +0300 Subject: [PATCH 18/53] update method that return pools list --- apps/explorer/lib/explorer/chain.ex | 46 +++++++--------------- apps/explorer/test/explorer/chain_test.exs | 34 ++++++++-------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 0977df1dd2..ed76150bc3 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -34,6 +34,7 @@ defmodule Explorer.Chain do BlockNumberCache, Data, DecompiledSmartContract, + StakingPool, Hash, Import, InternalTransaction, @@ -2909,7 +2910,7 @@ defmodule Explorer.Chain do def staking_pools(filter, %PagingOptions{page_size: page_size, page_number: page_number} \\ @default_paging_options) do off = page_size * (page_number - 1) - Address.Name + StakingPool |> staking_pool_filter(filter) |> limit(^page_size) |> offset(^off) @@ -2919,55 +2920,36 @@ defmodule Explorer.Chain do @doc "Get count of staking pools from the DB" @spec staking_pools_count(filter :: :validator | :active | :inactive) :: integer def staking_pools_count(filter) do - Address.Name + StakingPool |> staking_pool_filter(filter) - |> Repo.aggregate(:count, :address_hash) + |> Repo.aggregate(:count, :staking_address_hash) end defp staking_pool_filter(query, :validator) do where( query, - [address], - fragment( - """ - (?->>'is_active')::boolean = true and - (?->>'deleted')::boolean is not true and - (?->>'is_validator')::boolean = true - """, - address.metadata, - address.metadata, - address.metadata - ) + [pool], + pool.is_active == true and + pool.is_deleted == false and + pool.is_validator == true ) end defp staking_pool_filter(query, :active) do where( query, - [address], - fragment( - """ - (?->>'is_active')::boolean = true and - (?->>'deleted')::boolean is not true - """, - address.metadata, - address.metadata - ) + [pool], + pool.is_active == true and + pool.is_deleted == false ) end defp staking_pool_filter(query, :inactive) do where( query, - [address], - fragment( - """ - (?->>'is_active')::boolean = false and - (?->>'deleted')::boolean is not true - """, - address.metadata, - address.metadata - ) + [pool], + pool.is_active == false and + pool.is_deleted == false ) end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index cafd742e2a..78b938d6f3 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3951,54 +3951,54 @@ defmodule Explorer.ChainTest do describe "staking_pools/3" do test "validators staking pools" do - inserted_validator = insert(:address_name, primary: true, metadata: %{is_active: true, is_validator: true}) - insert(:address_name, primary: true, metadata: %{is_active: true, is_validator: false}) + inserted_validator = insert(:staking_pool, is_active: true, is_validator: true) + insert(:staking_pool, is_active: true, is_validator: false) options = %PagingOptions{page_size: 20, page_number: 1} assert [gotten_validator] = Chain.staking_pools(:validator, options) - assert inserted_validator.address_hash == gotten_validator.address_hash + assert inserted_validator.staking_address_hash == gotten_validator.staking_address_hash end test "active staking pools" do - inserted_validator = insert(:address_name, primary: true, metadata: %{is_active: true}) - insert(:address_name, primary: true, metadata: %{is_active: false}) + inserted_pool = insert(:staking_pool, is_active: true) + insert(:staking_pool, is_active: false) options = %PagingOptions{page_size: 20, page_number: 1} - assert [gotten_validator] = Chain.staking_pools(:active, options) - assert inserted_validator.address_hash == gotten_validator.address_hash + assert [gotten_pool] = Chain.staking_pools(:active, options) + assert inserted_pool.staking_address_hash == gotten_pool.staking_address_hash end test "inactive staking pools" do - insert(:address_name, primary: true, metadata: %{is_active: true}) - inserted_validator = insert(:address_name, primary: true, metadata: %{is_active: false}) + insert(:staking_pool, is_active: true) + inserted_pool = insert(:staking_pool, is_active: false) options = %PagingOptions{page_size: 20, page_number: 1} - assert [gotten_validator] = Chain.staking_pools(:inactive, options) - assert inserted_validator.address_hash == gotten_validator.address_hash + assert [gotten_pool] = Chain.staking_pools(:inactive, options) + assert inserted_pool.staking_address_hash == gotten_pool.staking_address_hash end end describe "staking_pools_count/1" do test "validators staking pools" do - insert(:address_name, primary: true, metadata: %{is_active: true, is_validator: true}) - insert(:address_name, primary: true, metadata: %{is_active: true, is_validator: false}) + insert(:staking_pool, is_active: true, is_validator: true) + insert(:staking_pool, is_active: true, is_validator: false) assert Chain.staking_pools_count(:validator) == 1 end test "active staking pools" do - insert(:address_name, primary: true, metadata: %{is_active: true}) - insert(:address_name, primary: true, metadata: %{is_active: false}) + insert(:staking_pool, is_active: true) + insert(:staking_pool, is_active: false) assert Chain.staking_pools_count(:active) == 1 end test "inactive staking pools" do - insert(:address_name, primary: true, metadata: %{is_active: true}) - insert(:address_name, primary: true, metadata: %{is_active: false}) + insert(:staking_pool, is_active: true) + insert(:staking_pool, is_active: false) assert Chain.staking_pools_count(:inactive) == 1 end From f0b228e69a938ed8d1dd89624aaeaddfd0cd84b1 Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 14:16:46 +0300 Subject: [PATCH 19/53] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3d9ef4a3..8c00acabfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method - [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default - [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct +- [#2036](https://github.com/poanetwork/blockscout/pull/2036) - New tables for staking pools and delegators ### Fixes From e0bed0ea1c7a6843bc225ef9ff412a5275062ba1 Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 14:17:51 +0300 Subject: [PATCH 20/53] update doc --- .../explorer/chain/import/runner/staking_pools_delegators.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex index 22d62592c3..cf7391dc89 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex @@ -1,6 +1,6 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do @moduledoc """ - Bulk imports staking pools to StakingPoolsDelegator tabe. + Bulk imports delegators to StakingPoolsDelegator tabe. """ require Ecto.Query From 83cca0aa283dfaa44feca3bebb9fafc87173d24a Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 14:19:20 +0300 Subject: [PATCH 21/53] remove cast! and dump! functions from Wei module --- apps/explorer/lib/explorer/chain/wei.ex | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/wei.ex b/apps/explorer/lib/explorer/chain/wei.ex index 8b557b4ed5..4b12d3deb0 100644 --- a/apps/explorer/lib/explorer/chain/wei.ex +++ b/apps/explorer/lib/explorer/chain/wei.ex @@ -68,11 +68,6 @@ defmodule Explorer.Chain.Wei do @impl Ecto.Type def cast(_), do: :error - def cast!(arg) do - {:ok, wei} = cast(arg) - wei - end - @impl Ecto.Type def dump(%__MODULE__{value: %Decimal{} = decimal}) do {:ok, decimal} @@ -81,11 +76,6 @@ defmodule Explorer.Chain.Wei do @impl Ecto.Type def dump(_), do: :error - def dump!(arg) do - {:ok, decimal} = dump(arg) - decimal - end - @impl Ecto.Type def load(%Decimal{} = decimal) do {:ok, %__MODULE__{value: decimal}} @@ -248,11 +238,6 @@ defmodule Explorer.Chain.Wei do @spec to(t(), :wei) :: wei() def to(%__MODULE__{value: wei}, :wei), do: wei - - @spec to(t(), :integer) :: integer() - def to(%__MODULE__{value: wei}, :integer) do - Decimal.to_integer(wei) - end end defimpl Inspect, for: Explorer.Chain.Wei do From 1ea565d1a9bff872b4ae1b764360c8144ae42c1e Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 27 May 2019 14:23:48 +0300 Subject: [PATCH 22/53] mix credo --- apps/explorer/lib/explorer/chain.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index ed76150bc3..c6d88bc524 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -34,12 +34,12 @@ defmodule Explorer.Chain do BlockNumberCache, Data, DecompiledSmartContract, - StakingPool, Hash, Import, InternalTransaction, Log, SmartContract, + StakingPool, Token, TokenTransfer, Transaction, From e0468fffdd1cdbe986529abb0e740ff15d133e74 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 27 May 2019 15:50:57 +0300 Subject: [PATCH 23/53] add endpoint to search address logs by topic --- .../controllers/address_logs_controller.ex | 43 ++++++++++++++++++ .../lib/block_scout_web/router.ex | 2 + apps/explorer/lib/explorer/chain.ex | 14 +++++- apps/explorer/test/explorer/chain_test.exs | 44 +++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex index f79d9aa08d..8731efbb4f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex @@ -6,9 +6,11 @@ defmodule BlockScoutWeb.AddressLogsController do import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] + alias BlockScoutWeb.AddressLogsView alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token alias Indexer.Fetcher.CoinBalanceOnDemand + alias Phoenix.View use BlockScoutWeb, :controller @@ -43,4 +45,45 @@ defmodule BlockScoutWeb.AddressLogsController do not_found(conn) end end + + def search_logs(conn, %{"topic" => topic, "address_id" => address_hash_string} = params) do + with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), + {:ok, address} <- Chain.hash_to_address(address_hash) do + topic = String.trim(topic) + logs_plus_one = Chain.address_to_logs(address, topic: topic) + + {results, next_page} = split_list_by_page(logs_plus_one) + + next_page_url = + case next_page_params(next_page, results, params) do + nil -> + nil + + next_page_params -> + address_logs_path(conn, :index, address, Map.delete(next_page_params, "type")) + end + + items = + results + |> Enum.map(fn log -> + View.render_to_string( + AddressLogsView, + "_logs.html", + log: log, + conn: conn + ) + end) + + json( + conn, + %{ + items: items, + next_page_path: next_page_url + } + ) + else + _ -> + not_found(conn) + end + end end diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index b2f639d763..aa19725811 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -238,6 +238,8 @@ defmodule BlockScoutWeb.Router do get("/search", ChainController, :search) + get("/search_logs", AddressLogsController, :search_logs) + get("/token_autocomplete", ChainController, :token_autocomplete) get("/chain_blocks", ChainController, :chain_blocks, as: :chain_blocks) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 9446388531..d5117453bf 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -291,8 +291,9 @@ defmodule Explorer.Chain do paging_options = Keyword.get(options, :paging_options) || %PagingOptions{page_size: 50} {block_number, transaction_index, log_index} = paging_options.key || {BlockNumberCache.max_number(), 0, 0} + topic = Keyword.get(options, :topic) - query = + base_query = from(log in Log, inner_join: transaction in assoc(log, :transaction), order_by: [desc: transaction.block_number, desc: transaction.index], @@ -307,6 +308,17 @@ defmodule Explorer.Chain do select: log ) + query = + if topic do + from(log in base_query, + where: + log.first_topic == ^topic or log.second_topic == ^topic or log.third_topic == ^topic or + log.fourth_topic == ^topic + ) + else + base_query + end + query |> Repo.all() |> Enum.take(paging_options.page_size) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 0234672183..6f3de49226 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -93,6 +93,50 @@ defmodule Explorer.ChainTest do assert Enum.count(Chain.address_to_logs(address, paging_options: paging_options2)) == 50 end + + test "searches logs by topic when the first topic matches" do + address = insert(:address) + + transaction1 = + :transaction + |> insert(to_address: address) + |> with_block() + + insert(:log, transaction: transaction1, index: 1, address: address) + + transaction2 = + :transaction + |> insert(from_address: address) + |> with_block() + + insert(:log, transaction: transaction2, index: 2, address: address, first_topic: "test") + + [found_log] = Chain.address_to_logs(address, topic: "test") + + assert found_log.transaction.hash == transaction2.hash + end + + test "searches logs by topic when the fourth topic matches" do + address = insert(:address) + + transaction1 = + :transaction + |> insert(to_address: address) + |> with_block() + + insert(:log, transaction: transaction1, index: 1, address: address, fourth_topic: "test") + + transaction2 = + :transaction + |> insert(from_address: address) + |> with_block() + + insert(:log, transaction: transaction2, index: 2, address: address) + + [found_log] = Chain.address_to_logs(address, topic: "test") + + assert found_log.transaction.hash == transaction1.hash + end end describe "address_to_transactions_with_rewards/2" do From c71d372831cdc8d2ce16394fcf231bd136666d6d Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 28 May 2019 14:59:36 +0300 Subject: [PATCH 24/53] add js logic for logs search --- apps/block_scout_web/assets/js/app.js | 1 + .../assets/js/pages/address/logs.js | 64 +++++++++++++ .../templates/address_logs/_logs.html.eex | 54 +++++++++++ .../templates/address_logs/index.html.eex | 89 +++++-------------- 4 files changed, 139 insertions(+), 69 deletions(-) create mode 100644 apps/block_scout_web/assets/js/pages/address/logs.js create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex diff --git a/apps/block_scout_web/assets/js/app.js b/apps/block_scout_web/assets/js/app.js index f10e3d696d..0893b8b4ae 100644 --- a/apps/block_scout_web/assets/js/app.js +++ b/apps/block_scout_web/assets/js/app.js @@ -23,6 +23,7 @@ import './locale' import './pages/address' import './pages/address/coin_balances' import './pages/address/transactions' +import './pages/address/logs' import './pages/address/validations' import './pages/address/internal_transactions' import './pages/blocks' diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js new file mode 100644 index 0000000000..ddfe3e9bfc --- /dev/null +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -0,0 +1,64 @@ +import $ from 'jquery' +import _ from 'lodash' +import URI from 'urijs' +import humps from 'humps' +import { subscribeChannel } from '../../socket' +import { connectElements } from '../../lib/redux_helpers.js' +import { createAsyncLoadStore } from '../../lib/async_listing_load' + +export const initialState = { + addressHash: null +} + +export function reducer (state, action) { + switch (action.type) { + case 'PAGE_LOAD': + case 'ELEMENTS_LOAD': { + return Object.assign({}, state, _.omit(action, 'type')) + } + default: + return state + } +} + +const elements = { + '[data-search-field]' : { + render ($el, state) { + $el + } + }, + '[data-search-button]' : { + render ($el, state) { + $el + } + } +} + +if ($('[data-page="address-logs"]').length) { + console.log('iffff') + const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') + const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash + const $element = $('[data-async-listing]') + + + connectElements({ store, elements }) + + store.dispatch({ + type: 'PAGE_LOAD', + addressHash: addressHash}) + + function loadSearchItems () { + var topic = $('[data-search-field]').val(); + var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash + store.dispatch({type: 'START_REQUEST'}) + $.getJSON(path, {type: 'JSON'}) + .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) + .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) + .always(() => store.dispatch({type: 'FINISH_REQUEST'})) + } + + + $element.on('click', '[data-search-button]', (event) => { + loadSearchItems() + }) +} diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex new file mode 100644 index 0000000000..66f75362c3 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex @@ -0,0 +1,54 @@ +
+
+
<%= gettext "Transaction" %>
+
+

+ <%= link( + @log.transaction, + to: transaction_path(@conn, :show, @log.transaction), + "data-test": "log_address_link", + "data-address-hash": @log.transaction + ) %> +

+
+
<%= gettext "Topics" %>
+
+
+ <%= unless is_nil(@log.first_topic) do %> +
+ [0] + <%= @log.first_topic %> +
+ <% end %> + <%= unless is_nil(@log.second_topic) do %> +
+ [1] + <%= @log.second_topic %> +
+ <% end %> + <%= unless is_nil(@log.third_topic) do %> +
+ [2] + <%= @log.third_topic %> +
+ <% end %> + <%= unless is_nil(@log.fourth_topic) do %> +
+ [3] + <%= @log.fourth_topic %> +
+ <% end %> +
+
+
+ <%= gettext "Data" %> +
+
+ <%= unless is_nil(@log.data) do %> +
+ <%= @log.data %> +
+ <% end %> +
+
+
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex index 22f446924f..f873465372 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -1,82 +1,33 @@
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %> +
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %> -
- +

<%= gettext "Logs" %>

- <%= if @next_page_url do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, next_page_path: @next_page_url %> - <% end %> + id='search-text-input' /> + + + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> - <%= if !@next_page_url do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true %> - <% end %> + - <%= if Enum.count(@logs) > 0 do %> - <%= for log <- @logs do %> -
-
-
<%= gettext "Transaction" %>
-
-

- <%= link( - log.transaction, - to: transaction_path(@conn, :show, log.transaction), - "data-test": "log_address_link", - "data-address-hash": log.transaction - ) %> -

-
-
<%= gettext "Topics" %>
-
-
- <%= unless is_nil(log.first_topic) do %> -
- [0] - <%= log.first_topic %> -
- <% end %> - <%= unless is_nil(log.second_topic) do %> -
- [1] - <%= log.second_topic %> -
- <% end %> - <%= unless is_nil(log.third_topic) do %> -
- [2] - <%= log.third_topic %> -
- <% end %> - <%= unless is_nil(log.fourth_topic) do %> -
- [3] - <%= log.fourth_topic %> -
- <% end %> -
-
-
- <%= gettext "Data" %> -
-
- <%= unless is_nil(log.data) do %> -
- <%= log.data %> -
- <% end %> -
-
+
+
+ <%= gettext "There are no logs for this address." %>
- <% end %> - <% else %> -
- <%= gettext "There are no logs for this address." %> -
- <% end %> +
+ +
+ + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> +
+
+
From 8a49b546c7b8576adf9e859ff8c611267ac91fee Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 28 May 2019 15:25:00 +0300 Subject: [PATCH 25/53] free pages stack on search start --- apps/block_scout_web/assets/js/pages/address/logs.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index ddfe3e9bfc..444e3a9372 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -16,6 +16,9 @@ export function reducer (state, action) { case 'ELEMENTS_LOAD': { return Object.assign({}, state, _.omit(action, 'type')) } + case 'START_SEARCH': { + return Object.assign({}, state, {pagesStack: []}) + } default: return state } @@ -59,6 +62,9 @@ if ($('[data-page="address-logs"]').length) { $element.on('click', '[data-search-button]', (event) => { + store.dispatch({ + type: 'START_SEARCH', + addressHash: addressHash}) loadSearchItems() }) } From 1d3954fc625505f08ac7fdf6c1ce0ab7a75b955d Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 28 May 2019 15:26:36 +0300 Subject: [PATCH 26/53] change variable name in queries --- .../lib/explorer/chain/import/runner/staking_pools.ex | 6 +++--- .../chain/import/runner/staking_pools_delegators.ex | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index d7655674d8..ca83fa62ee 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -105,7 +105,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do defp default_on_conflict do from( - name in StakingPool, + pool in StakingPool, update: [ set: [ mining_address_hash: fragment("EXCLUDED.mining_address_hash"), @@ -120,8 +120,8 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do was_banned_count: fragment("EXCLUDED.was_banned_count"), was_validator_count: fragment("EXCLUDED.was_validator_count"), is_deleted: fragment("EXCLUDED.is_deleted"), - inserted_at: fragment("LEAST(?, EXCLUDED.inserted_at)", name.inserted_at), - updated_at: fragment("GREATEST(?, EXCLUDED.updated_at)", name.updated_at) + inserted_at: fragment("LEAST(?, EXCLUDED.inserted_at)", pool.inserted_at), + updated_at: fragment("GREATEST(?, EXCLUDED.updated_at)", pool.updated_at) ] ] ) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex index cf7391dc89..420882a833 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex @@ -74,7 +74,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do defp default_on_conflict do from( - name in StakingPoolsDelegator, + delegator in StakingPoolsDelegator, update: [ set: [ stake_amount: fragment("EXCLUDED.stake_amount"), @@ -82,8 +82,8 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do max_withdraw_allowed: fragment("EXCLUDED.max_withdraw_allowed"), max_ordered_withdraw_allowed: fragment("EXCLUDED.max_ordered_withdraw_allowed"), ordered_withdraw_epoch: fragment("EXCLUDED.ordered_withdraw_epoch"), - inserted_at: fragment("LEAST(?, EXCLUDED.inserted_at)", name.inserted_at), - updated_at: fragment("GREATEST(?, EXCLUDED.updated_at)", name.updated_at) + inserted_at: fragment("LEAST(?, EXCLUDED.inserted_at)", delegator.inserted_at), + updated_at: fragment("GREATEST(?, EXCLUDED.updated_at)", delegator.updated_at) ] ] ) From 35ef44a1abfe6f5b7e197acf087fb153366f5176 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 28 May 2019 15:54:44 +0300 Subject: [PATCH 27/53] add cancel search button --- .../assets/js/pages/address/logs.js | 20 ++++++++++++++++--- .../templates/address_logs/index.html.eex | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 444e3a9372..1479caeb58 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -7,7 +7,8 @@ import { connectElements } from '../../lib/redux_helpers.js' import { createAsyncLoadStore } from '../../lib/async_listing_load' export const initialState = { - addressHash: null + addressHash: null, + isSearch: false } export function reducer (state, action) { @@ -17,7 +18,7 @@ export function reducer (state, action) { return Object.assign({}, state, _.omit(action, 'type')) } case 'START_SEARCH': { - return Object.assign({}, state, {pagesStack: []}) + return Object.assign({}, state, {pagesStack: [], isSearch: true}) } default: return state @@ -34,11 +35,19 @@ const elements = { render ($el, state) { $el } + }, + '[data-cancel-search-button]' : { + render ($el, state) { + if (!state.isSearch) { + return $el.hide() + } + + return $el.show() + } } } if ($('[data-page="address-logs"]').length) { - console.log('iffff') const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash const $element = $('[data-async-listing]') @@ -67,4 +76,9 @@ if ($('[data-page="address-logs"]').length) { addressHash: addressHash}) loadSearchItems() }) + + $element.on('click', '[data-cancel-search-button]', (event) => { + console.log('click') + window.location.replace(window.location.href.split('?')[0]) + }) } diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex index f873465372..68897c51da 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -9,6 +9,7 @@ id='search-text-input' /> + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> From 0ca5f88b28caa33be58046f7b12cb2469b0a359e Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 09:56:42 +0300 Subject: [PATCH 28/53] fix gettext --- apps/block_scout_web/priv/gettext/default.pot | 17 +++- .../priv/gettext/en/LC_MESSAGES/default.po | 85 +++++++++++-------- 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index c62c47d890..d14665131d 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -500,7 +500,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:26 -#: lib/block_scout_web/templates/address_logs/index.html.eex:7 +#: lib/block_scout_web/templates/address_logs/index.html.eex:8 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:314 @@ -674,6 +674,7 @@ msgid "Responses" msgstr "" #, elixir-format +#: lib/block_scout_web/templates/address_logs/index.html.eex:11 #: lib/block_scout_web/templates/layout/_topnav.html.eex:111 #: lib/block_scout_web/templates/layout/_topnav.html.eex:128 msgid "Search" @@ -1217,7 +1218,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_coin_balance/index.html.eex:34 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:61 -#: lib/block_scout_web/templates/address_logs/index.html.eex:12 +#: lib/block_scout_web/templates/address_logs/index.html.eex:17 #: lib/block_scout_web/templates/address_token/index.html.eex:13 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:20 #: lib/block_scout_web/templates/address_transaction/index.html.eex:57 @@ -1682,7 +1683,7 @@ msgid "Displaying the init data provided of the creating transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:17 +#: lib/block_scout_web/templates/address_logs/index.html.eex:22 msgid "There are no logs for this address." msgstr "" @@ -1720,3 +1721,13 @@ msgstr "" #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:17 msgid "There are no token transfers for this transaction" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_logs/index.html.eex:12 +msgid "Cancel Search" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_logs/index.html.eex:10 +msgid "Topic" +msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 23a85c844b..3fd1cd6e9e 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -145,7 +145,7 @@ msgid "Block %{block_number} - %{subnetwork} Explorer" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:73 +#: lib/block_scout_web/templates/transaction/overview.html.eex:72 msgid "Block Confirmations" msgstr "" @@ -160,7 +160,7 @@ msgid "Block Mined, awaiting import..." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:59 +#: lib/block_scout_web/templates/transaction/overview.html.eex:58 msgid "Block Number" msgstr "" @@ -190,7 +190,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:32 #: lib/block_scout_web/templates/address/overview.html.eex:95 #: lib/block_scout_web/templates/address_validation/index.html.eex:13 -#: lib/block_scout_web/views/address_view.ex:308 +#: lib/block_scout_web/views/address_view.ex:313 msgid "Blocks Validated" msgstr "" @@ -207,8 +207,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:37 -#: lib/block_scout_web/templates/address/overview.html.eex:141 -#: lib/block_scout_web/templates/address/overview.html.eex:149 +#: lib/block_scout_web/templates/address/overview.html.eex:142 +#: lib/block_scout_web/templates/address/overview.html.eex:150 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:106 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:114 msgid "Close" @@ -218,7 +218,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:42 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 -#: lib/block_scout_web/views/address_view.ex:304 +#: lib/block_scout_web/views/address_view.ex:309 msgid "Code" msgstr "" @@ -382,7 +382,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:210 +#: lib/block_scout_web/templates/transaction/overview.html.eex:209 #: lib/block_scout_web/views/wei_helpers.ex:72 msgid "Ether" msgstr "POA" @@ -452,7 +452,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:39 -#: lib/block_scout_web/templates/transaction/_tile.html.eex:76 +#: lib/block_scout_web/templates/transaction/_tile.html.eex:74 msgid "IN" msgstr "" @@ -476,7 +476,7 @@ msgstr "" #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 -#: lib/block_scout_web/views/address_view.ex:303 +#: lib/block_scout_web/views/address_view.ex:308 #: lib/block_scout_web/views/transaction_view.ex:339 msgid "Internal Transactions" msgstr "" @@ -494,16 +494,16 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:238 +#: lib/block_scout_web/templates/transaction/overview.html.eex:237 msgid "Limit" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:26 -#: lib/block_scout_web/templates/address_logs/index.html.eex:7 +#: lib/block_scout_web/templates/address_logs/index.html.eex:8 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 -#: lib/block_scout_web/views/address_view.ex:309 +#: lib/block_scout_web/views/address_view.ex:314 #: lib/block_scout_web/views/transaction_view.ex:340 msgid "Logs" msgstr "" @@ -574,13 +574,13 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/overview.html.eex:73 -#: lib/block_scout_web/templates/transaction/overview.html.eex:80 +#: lib/block_scout_web/templates/transaction/overview.html.eex:79 msgid "Nonce" msgstr "" #, elixir-format #: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:37 -#: lib/block_scout_web/templates/transaction/_tile.html.eex:72 +#: lib/block_scout_web/templates/transaction/_tile.html.eex:70 msgid "OUT" msgstr "" @@ -634,7 +634,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:33 -#: lib/block_scout_web/templates/address/overview.html.eex:140 +#: lib/block_scout_web/templates/address/overview.html.eex:141 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:35 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:105 msgid "QR Code" @@ -648,7 +648,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:58 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25 -#: lib/block_scout_web/views/address_view.ex:306 +#: lib/block_scout_web/views/address_view.ex:311 #: lib/block_scout_web/views/tokens/overview_view.ex:37 msgid "Read Contract" msgstr "" @@ -674,6 +674,7 @@ msgid "Responses" msgstr "" #, elixir-format +#: lib/block_scout_web/templates/address_logs/index.html.eex:11 #: lib/block_scout_web/templates/layout/_topnav.html.eex:111 #: lib/block_scout_web/templates/layout/_topnav.html.eex:128 msgid "Search" @@ -705,7 +706,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:21 #: lib/block_scout_web/templates/transaction/_tile.html.eex:34 -#: lib/block_scout_web/templates/transaction/overview.html.eex:85 +#: lib/block_scout_web/templates/transaction/overview.html.eex:84 msgid "TX Fee" msgstr "" @@ -802,8 +803,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:5 -#: lib/block_scout_web/templates/transaction/overview.html.eex:180 -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:179 +#: lib/block_scout_web/templates/transaction/overview.html.eex:193 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/views/transaction_view.ex:284 msgid "Token Transfer" @@ -823,7 +824,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:8 #: lib/block_scout_web/templates/address_token/index.html.eex:8 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:9 -#: lib/block_scout_web/views/address_view.ex:301 +#: lib/block_scout_web/views/address_view.ex:306 msgid "Tokens" msgstr "" @@ -881,7 +882,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:108 #: lib/block_scout_web/templates/layout/_topnav.html.eex:35 -#: lib/block_scout_web/views/address_view.ex:302 +#: lib/block_scout_web/views/address_view.ex:307 msgid "Transactions" msgstr "" @@ -917,7 +918,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:232 +#: lib/block_scout_web/templates/transaction/overview.html.eex:231 msgid "Used" msgstr "" @@ -937,7 +938,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:210 +#: lib/block_scout_web/templates/transaction/overview.html.eex:209 msgid "Value" msgstr "" @@ -958,12 +959,12 @@ msgid "View Contract" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/_tile.html.eex:56 +#: lib/block_scout_web/templates/transaction/_tile.html.eex:55 msgid "View Less Transfers" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/_tile.html.eex:55 +#: lib/block_scout_web/templates/transaction/_tile.html.eex:54 msgid "View More Transfers" msgstr "" @@ -1101,7 +1102,7 @@ msgid "This API is provided for developers transitioning their applications from msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:110 +#: lib/block_scout_web/templates/transaction/overview.html.eex:109 msgid "Raw Input" msgstr "" @@ -1217,7 +1218,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_coin_balance/index.html.eex:34 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:61 -#: lib/block_scout_web/templates/address_logs/index.html.eex:12 +#: lib/block_scout_web/templates/address_logs/index.html.eex:17 #: lib/block_scout_web/templates/address_token/index.html.eex:13 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:20 #: lib/block_scout_web/templates/address_transaction/index.html.eex:57 @@ -1257,7 +1258,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:20 -#: lib/block_scout_web/views/address_view.ex:307 +#: lib/block_scout_web/views/address_view.ex:312 msgid "Coin Balance History" msgstr "" @@ -1499,18 +1500,18 @@ msgid "Transactions Sent" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:102 +#: lib/block_scout_web/templates/transaction/overview.html.eex:101 msgid "Transaction Speed" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:116 -#: lib/block_scout_web/templates/transaction/overview.html.eex:120 +#: lib/block_scout_web/templates/transaction/overview.html.eex:115 +#: lib/block_scout_web/templates/transaction/overview.html.eex:119 msgid "Hex (Default)" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:123 +#: lib/block_scout_web/templates/transaction/overview.html.eex:122 msgid "UTF-8" msgstr "" @@ -1561,7 +1562,7 @@ msgid "Copy Decompiled Contract Code" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:305 +#: lib/block_scout_web/views/address_view.ex:310 msgid "Decompiled Code" msgstr "" @@ -1586,12 +1587,12 @@ msgid "Optimization runs" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:180 +#: lib/block_scout_web/templates/transaction/overview.html.eex:179 msgid "ERC-20" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:193 msgid "ERC-721" msgstr "" @@ -1611,7 +1612,7 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:228 +#: lib/block_scout_web/templates/transaction/overview.html.eex:227 msgid "Gas" msgstr "" @@ -1682,7 +1683,7 @@ msgid "Displaying the init data provided of the creating transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:17 +#: lib/block_scout_web/templates/address_logs/index.html.eex:22 msgid "There are no logs for this address." msgstr "" @@ -1720,3 +1721,13 @@ msgstr "" #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:17 msgid "There are no token transfers for this transaction" msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_logs/index.html.eex:12 +msgid "Cancel Search" +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_logs/index.html.eex:10 +msgid "Topic" +msgstr "" From fb158da8fad284d346881e4b075c1e398e501427 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:01:54 +0300 Subject: [PATCH 29/53] fix js indent --- .../assets/js/pages/address/logs.js | 112 +++++++++--------- apps/explorer/lib/explorer/chain.ex | 2 +- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 1479caeb58..6cbced717e 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -7,78 +7,78 @@ import { connectElements } from '../../lib/redux_helpers.js' import { createAsyncLoadStore } from '../../lib/async_listing_load' export const initialState = { - addressHash: null, - isSearch: false + addressHash: null, + isSearch: false } export function reducer (state, action) { - switch (action.type) { - case 'PAGE_LOAD': - case 'ELEMENTS_LOAD': { - return Object.assign({}, state, _.omit(action, 'type')) - } - case 'START_SEARCH': { - return Object.assign({}, state, {pagesStack: [], isSearch: true}) - } - default: - return state - } + switch (action.type) { + case 'PAGE_LOAD': + case 'ELEMENTS_LOAD': { + return Object.assign({}, state, _.omit(action, 'type')) + } + case 'START_SEARCH': { + return Object.assign({}, state, {pagesStack: [], isSearch: true}) + } + default: + return state + } } const elements = { - '[data-search-field]' : { - render ($el, state) { - $el - } - }, - '[data-search-button]' : { - render ($el, state) { - $el - } - }, - '[data-cancel-search-button]' : { - render ($el, state) { - if (!state.isSearch) { - return $el.hide() - } + '[data-search-field]' : { + render ($el, state) { + $el + } + }, + '[data-search-button]' : { + render ($el, state) { + $el + } + }, + '[data-cancel-search-button]' : { + render ($el, state) { + if (!state.isSearch) { + return $el.hide() + } - return $el.show() - } + return $el.show() } + } } if ($('[data-page="address-logs"]').length) { - const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') - const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash - const $element = $('[data-async-listing]') + const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') + const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash + const $element = $('[data-async-listing]') - connectElements({ store, elements }) + connectElements({ store, elements }) - store.dispatch({ - type: 'PAGE_LOAD', - addressHash: addressHash}) + store.dispatch({ + type: 'PAGE_LOAD', + addressHash: addressHash}) - function loadSearchItems () { - var topic = $('[data-search-field]').val(); - var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash - store.dispatch({type: 'START_REQUEST'}) - $.getJSON(path, {type: 'JSON'}) - .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) - .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) - .always(() => store.dispatch({type: 'FINISH_REQUEST'})) - } + function loadSearchItems () { + var topic = $('[data-search-field]').val(); + var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash + store.dispatch({type: 'START_REQUEST'}) + $.getJSON(path, {type: 'JSON'}) + .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) + .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) + .always(() => store.dispatch({type: 'FINISH_REQUEST'})) + } - $element.on('click', '[data-search-button]', (event) => { - store.dispatch({ - type: 'START_SEARCH', - addressHash: addressHash}) - loadSearchItems() - }) + $element.on('click', '[data-search-button]', (event) => { + store.dispatch({ + type: 'START_SEARCH', + addressHash: addressHash}) + loadSearchItems() + }) - $element.on('click', '[data-cancel-search-button]', (event) => { - console.log('click') - window.location.replace(window.location.href.split('?')[0]) - }) + $element.on('click', '[data-cancel-search-button]', (event) => { + console.log('click') + window.location.replace(window.location.href.split('?')[0]) + }) } diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index d5117453bf..a52965a92b 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -280,7 +280,7 @@ defmodule Explorer.Chain do |> Enum.take(paging_options.page_size) end - @spec address_to_logs(Address.t(), [paging_options]) :: [ + @spec address_to_logs(Address.t(), [Keyword.t()]) :: [ Log.t() ] def address_to_logs( From e7ace9cae65ecfee65527de599ed1b1890be2578 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:20:11 +0300 Subject: [PATCH 30/53] fix credo --- .../assets/js/pages/address/logs.js | 18 ++++++------- apps/explorer/lib/explorer/chain.ex | 27 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 6cbced717e..a9ad5104c3 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -13,15 +13,15 @@ export const initialState = { export function reducer (state, action) { switch (action.type) { - case 'PAGE_LOAD': - case 'ELEMENTS_LOAD': { - return Object.assign({}, state, _.omit(action, 'type')) - } - case 'START_SEARCH': { - return Object.assign({}, state, {pagesStack: [], isSearch: true}) - } - default: - return state + case 'PAGE_LOAD': + case 'ELEMENTS_LOAD': { + return Object.assign({}, state, _.omit(action, 'type')) + } + case 'START_SEARCH': { + return Object.assign({}, state, {pagesStack: [], isSearch: true}) + } + default: + return state } } diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index a52965a92b..d2b88ba722 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -280,7 +280,7 @@ defmodule Explorer.Chain do |> Enum.take(paging_options.page_size) end - @spec address_to_logs(Address.t(), [Keyword.t()]) :: [ + @spec address_to_logs(Address.t(), Keyword.t()) :: [ Log.t() ] def address_to_logs( @@ -291,7 +291,6 @@ defmodule Explorer.Chain do paging_options = Keyword.get(options, :paging_options) || %PagingOptions{page_size: 50} {block_number, transaction_index, log_index} = paging_options.key || {BlockNumberCache.max_number(), 0, 0} - topic = Keyword.get(options, :topic) base_query = from(log in Log, @@ -308,22 +307,22 @@ defmodule Explorer.Chain do select: log ) - query = - if topic do - from(log in base_query, - where: - log.first_topic == ^topic or log.second_topic == ^topic or log.third_topic == ^topic or - log.fourth_topic == ^topic - ) - else - base_query - end - - query + base_query + |> filter_topic(options) |> Repo.all() |> Enum.take(paging_options.page_size) end + defp filter_topic(base_query, topic: topic) do + from(log in base_query, + where: + log.first_topic == ^topic or log.second_topic == ^topic or log.third_topic == ^topic or + log.fourth_topic == ^topic + ) + end + + defp filter_topic(base_query, _), do: base_query + @doc """ Finds all `t:Explorer.Chain.Transaction.t/0`s given the address_hash and the token contract address hash. From 0036876b24c5abec5751ea528acda3465dda7c98 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:25:48 +0300 Subject: [PATCH 31/53] remove extra spaces --- apps/block_scout_web/assets/js/pages/address/logs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index a9ad5104c3..063480619e 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -26,17 +26,17 @@ export function reducer (state, action) { } const elements = { - '[data-search-field]' : { + '[data-search-field]': { render ($el, state) { $el } }, - '[data-search-button]' : { + '[data-search-button]': { render ($el, state) { $el } }, - '[data-cancel-search-button]' : { + '[data-cancel-search-button]': { render ($el, state) { if (!state.isSearch) { return $el.hide() From 3a3e8cf260d0b86a2b69d1993991aeeb32e0a636 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:32:29 +0300 Subject: [PATCH 32/53] fix js style --- .../assets/js/pages/address/logs.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 063480619e..99ac742679 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -47,29 +47,27 @@ const elements = { } } +function loadSearchItems () { + var topic = $('[data-search-field]').val(); + var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash + store.dispatch({type: 'START_REQUEST'}) + $.getJSON(path, {type: 'JSON'}) + .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) + .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) + .always(() => store.dispatch({type: 'FINISH_REQUEST'})) +} + if ($('[data-page="address-logs"]').length) { const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash const $element = $('[data-async-listing]') - connectElements({ store, elements }) store.dispatch({ type: 'PAGE_LOAD', addressHash: addressHash}) - function loadSearchItems () { - var topic = $('[data-search-field]').val(); - var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash - store.dispatch({type: 'START_REQUEST'}) - $.getJSON(path, {type: 'JSON'}) - .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) - .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) - .always(() => store.dispatch({type: 'FINISH_REQUEST'})) - } - - $element.on('click', '[data-search-button]', (event) => { store.dispatch({ type: 'START_SEARCH', From 40d50cef4c8d10defca74dc3cf52bcb4470e2af8 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:36:25 +0300 Subject: [PATCH 33/53] remove function --- .../assets/js/pages/address/logs.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 99ac742679..c82bc7856e 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -47,16 +47,6 @@ const elements = { } } -function loadSearchItems () { - var topic = $('[data-search-field]').val(); - var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash - store.dispatch({type: 'START_REQUEST'}) - $.getJSON(path, {type: 'JSON'}) - .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) - .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) - .always(() => store.dispatch({type: 'FINISH_REQUEST'})) -} - if ($('[data-page="address-logs"]').length) { const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash @@ -72,7 +62,13 @@ if ($('[data-page="address-logs"]').length) { store.dispatch({ type: 'START_SEARCH', addressHash: addressHash}) - loadSearchItems() + var topic = $('[data-search-field]').val(); + var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash + store.dispatch({type: 'START_REQUEST'}) + $.getJSON(path, {type: 'JSON'}) + .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) + .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) + .always(() => store.dispatch({type: 'FINISH_REQUEST'})) }) $element.on('click', '[data-cancel-search-button]', (event) => { From cb0508e99165563e59589cbdfead95920736470d Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:43:29 +0300 Subject: [PATCH 34/53] fix remaining js issues --- apps/block_scout_web/assets/js/pages/address/logs.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index c82bc7856e..463ccced1b 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -1,6 +1,5 @@ import $ from 'jquery' import _ from 'lodash' -import URI from 'urijs' import humps from 'humps' import { subscribeChannel } from '../../socket' import { connectElements } from '../../lib/redux_helpers.js' @@ -28,12 +27,12 @@ export function reducer (state, action) { const elements = { '[data-search-field]': { render ($el, state) { - $el + return $el } }, '[data-search-button]': { render ($el, state) { - $el + return $el } }, '[data-cancel-search-button]': { @@ -62,8 +61,8 @@ if ($('[data-page="address-logs"]').length) { store.dispatch({ type: 'START_SEARCH', addressHash: addressHash}) - var topic = $('[data-search-field]').val(); - var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash + var topic = $('[data-search-field]').val() + var path = '/search_logs?topic=' + topic + '&address_id=' + store.getState().addressHash store.dispatch({type: 'START_REQUEST'}) $.getJSON(path, {type: 'JSON'}) .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) From 548db9a2a1965abeeb9adec0d3c05722ff48f30e Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:46:07 +0300 Subject: [PATCH 35/53] remove unused import --- apps/block_scout_web/assets/js/pages/address/logs.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 463ccced1b..bdcdf57087 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -1,7 +1,6 @@ import $ from 'jquery' import _ from 'lodash' import humps from 'humps' -import { subscribeChannel } from '../../socket' import { connectElements } from '../../lib/redux_helpers.js' import { createAsyncLoadStore } from '../../lib/async_listing_load' From fb42dedfdcc8a00a8a634046ed9c91474d4de544 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 11:23:55 +0300 Subject: [PATCH 36/53] add CHANGELOG entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 043d57d31f..8dca2fdef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ - [#1999](https://github.com/poanetwork/blockscout/pull/1999) - load data async on addresses page - [#2002](https://github.com/poanetwork/blockscout/pull/2002) - Get estimated count of blocks when cache is empty - [#1807](https://github.com/poanetwork/blockscout/pull/1807) - New theming capabilites. -- [#2040](https://github.com/poanetwork/blockscout/pull/2040) - Verification links to other explorers for ETH +- [#2040](https://github.com/poanetwork/blockscout/pull/2040) - Verification links to other explorers for ETH +- [#2037](https://github.com/poanetwork/blockscout/pull/2037) - add address logs search functionality ### Fixes - [#2043](https://github.com/poanetwork/blockscout/pull/2043) - Fixed modal dialog width for 'verify other explorers' From 7341e08c8ec65213ed572b457cf617b5ee507fa2 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 13:10:52 +0300 Subject: [PATCH 37/53] remove debug log --- apps/block_scout_web/assets/js/pages/address/logs.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index bdcdf57087..7c9f806c01 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -70,7 +70,6 @@ if ($('[data-page="address-logs"]').length) { }) $element.on('click', '[data-cancel-search-button]', (event) => { - console.log('click') window.location.replace(window.location.href.split('?')[0]) }) } From 43357ff7941fc1525a4090e0d083a5fad5d341c8 Mon Sep 17 00:00:00 2001 From: maxgrapps Date: Wed, 29 May 2019 15:00:13 +0300 Subject: [PATCH 38/53] log search form styles added --- apps/block_scout_web/assets/css/app.scss | 2 +- .../assets/css/components/_log-search.scss | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 apps/block_scout_web/assets/css/components/_log-search.scss diff --git a/apps/block_scout_web/assets/css/app.scss b/apps/block_scout_web/assets/css/app.scss index f658c087ef..9a71ee173f 100644 --- a/apps/block_scout_web/assets/css/app.scss +++ b/apps/block_scout_web/assets/css/app.scss @@ -122,7 +122,7 @@ $fa-font-path: "~@fortawesome/fontawesome-free/webfonts"; @import "components/alerts"; @import "components/verify_other_explorers"; @import "components/errors"; - +@import "components/log-search"; :export { dashboardBannerChartAxisFontColor: $dashboard-banner-chart-axis-font-color; dashboardLineColorMarket: $dashboard-line-color-market; diff --git a/apps/block_scout_web/assets/css/components/_log-search.scss b/apps/block_scout_web/assets/css/components/_log-search.scss new file mode 100644 index 0000000000..51ca8713d0 --- /dev/null +++ b/apps/block_scout_web/assets/css/components/_log-search.scss @@ -0,0 +1,60 @@ +.logs-topbar { + padding-bottom: 30px; + @media (min-width: 600px) { + display: flex; + justify-content: space-between; + } + .pagination-container.position-top { + padding-top: 0 !important; + } +} + +.logs-search { + display: flex; + @media (max-width: 599px) { + margin-bottom: 30px; + } +} + +.logs-search-input, .logs-search-btn, .logs-search-btn-cancel { + height: 24px; + background-color: #f5f6fa; + border: 1px solid #f5f6fa; + color: #333; + border-radius: 2px; + outline: none; + font-family: Nunito, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; + font-size: 12px; + font-weight: 600; +} + +.logs-search-input { + padding-left: 6px; + display: inline-flex; + flex-grow: 2; + min-width: 160px; + &::placeholder { + color: #a3a9b5; + } +} + +.logs-search-btn { + margin-left: 6px; + color: #a3a9b5; + transition: .1s ease-in; + cursor: pointer; + &:hover { + background-color: $primary; + color: #fff; + border-color: $primary; + } +} + +.logs-search-btn-cancel { + color: #a3a9b5; + cursor: pointer; + transition: .1s ease-in; + &:hover { + color: #333; + } +} \ No newline at end of file From ab74b9884515190f2dffcce8dec93c721233d6a5 Mon Sep 17 00:00:00 2001 From: maxgrapps <50101080+maxgrapps@users.noreply.github.com> Date: Wed, 29 May 2019 15:07:33 +0300 Subject: [PATCH 39/53] Update index.html.eex --- .../templates/address_logs/index.html.eex | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex index 68897c51da..bb5b2ce8d8 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -6,12 +6,15 @@

<%= gettext "Logs" %>

+
+ - id='search-text-input' /> - - - - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> +
+ +
- id='search-text-input' /> - - - - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> + diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 94187803dd..ff1da15027 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -674,7 +674,7 @@ msgid "Responses" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:13 +#: lib/block_scout_web/templates/address_logs/index.html.eex:14 #: lib/block_scout_web/templates/layout/_topnav.html.eex:111 #: lib/block_scout_web/templates/layout/_topnav.html.eex:128 msgid "Search" @@ -1218,7 +1218,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_coin_balance/index.html.eex:34 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:61 -#: lib/block_scout_web/templates/address_logs/index.html.eex:20 +#: lib/block_scout_web/templates/address_logs/index.html.eex:21 #: lib/block_scout_web/templates/address_token/index.html.eex:13 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:20 #: lib/block_scout_web/templates/address_transaction/index.html.eex:57 @@ -1683,7 +1683,7 @@ msgid "Displaying the init data provided of the creating transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:25 +#: lib/block_scout_web/templates/address_logs/index.html.eex:26 msgid "There are no logs for this address." msgstr "" @@ -1723,6 +1723,6 @@ msgid "There are no token transfers for this transaction" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:11 +#: lib/block_scout_web/templates/address_logs/index.html.eex:12 msgid "Topic" msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 059c7d4e4a..00e030a367 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -674,7 +674,7 @@ msgid "Responses" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:13 +#: lib/block_scout_web/templates/address_logs/index.html.eex:14 #: lib/block_scout_web/templates/layout/_topnav.html.eex:111 #: lib/block_scout_web/templates/layout/_topnav.html.eex:128 msgid "Search" @@ -1218,7 +1218,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_coin_balance/index.html.eex:34 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:61 -#: lib/block_scout_web/templates/address_logs/index.html.eex:20 +#: lib/block_scout_web/templates/address_logs/index.html.eex:21 #: lib/block_scout_web/templates/address_token/index.html.eex:13 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:20 #: lib/block_scout_web/templates/address_transaction/index.html.eex:57 @@ -1683,7 +1683,7 @@ msgid "Displaying the init data provided of the creating transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:25 +#: lib/block_scout_web/templates/address_logs/index.html.eex:26 msgid "There are no logs for this address." msgstr "" @@ -1723,6 +1723,6 @@ msgid "There are no token transfers for this transaction" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:11 +#: lib/block_scout_web/templates/address_logs/index.html.eex:12 msgid "Topic" msgstr "" From 77e8f457e006a0f151a67050b61ba844764e1b05 Mon Sep 17 00:00:00 2001 From: zachdaniel Date: Wed, 29 May 2019 14:06:23 -0400 Subject: [PATCH 43/53] fix: uniq by hash, instead of transaction --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain.ex | 2 +- .../lib/explorer/chain/token_transfer.ex | 60 +++---------------- 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 775c006a5c..84592d868b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ - [#2008](https://github.com/poanetwork/blockscout/pull/2008) - add new function clause for xDai network beneficiaries - [#2009](https://github.com/poanetwork/blockscout/pull/2009) - addresses page improvements - [#2027](https://github.com/poanetwork/blockscout/pull/2027) - fix: `BlocksTransactionsMismatch` ignoring blocks without transactions +- [#2062](https://github.com/poanetwork/blockscout/pull/2062) - fix: uniq by hash, instead of transaction ### Chore diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 9446388531..cc2375c2ef 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -266,7 +266,7 @@ defmodule Explorer.Chain do queries |> Stream.flat_map(&Repo.all/1) - |> Stream.uniq() + |> Stream.uniq_by(& &1.hash) |> Stream.concat(rewards_list) |> Enum.sort_by(fn item -> case item do diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index fa7ba99347..905d576aa1 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -204,59 +204,17 @@ defmodule Explorer.Chain.TokenTransfer do transaction_hashes_from_token_transfers_sql(address_bytes, paging_options) end - defp transaction_hashes_from_token_transfers_sql(address_bytes, %PagingOptions{key: nil, page_size: page_size}) do - {:ok, %Postgrex.Result{rows: transaction_hashes_from_token_transfers}} = - Repo.query( - """ - SELECT transaction_hash - FROM - ( - SELECT transaction_hash - FROM token_transfers - WHERE from_address_hash = $1 - - UNION - - SELECT transaction_hash - FROM token_transfers - WHERE to_address_hash = $1 - ) as token_transfers_transaction_hashes - LIMIT $2 - """, - [address_bytes, page_size] - ) - - List.flatten(transaction_hashes_from_token_transfers) - end - - defp transaction_hashes_from_token_transfers_sql(address_bytes, %PagingOptions{ - key: {block_number, _index}, - page_size: page_size - }) do - {:ok, %Postgrex.Result{rows: transaction_hashes_from_token_transfers}} = - Repo.query( - """ - SELECT transaction_hash - FROM - ( - SELECT transaction_hash - FROM token_transfers - WHERE from_address_hash = $1 - AND block_number < $2 - - UNION - - SELECT transaction_hash - FROM token_transfers - WHERE to_address_hash = $1 - AND block_number < $2 - ) as token_transfers_transaction_hashes - LIMIT $3 - """, - [address_bytes, block_number, page_size] + defp transaction_hashes_from_token_transfers_sql(address_bytes, %PagingOptions{page_size: page_size} = paging_options) do + query = + from(token_transfer in TokenTransfer, + where: token_transfer.to_address_hash == ^address_bytes or token_transfer.from_address_hash == ^address_bytes, + select: type(token_transfer.transaction_hash, :binary), + limit: ^page_size ) - List.flatten(transaction_hashes_from_token_transfers) + query + |> page_transaction_hashes_from_token_transfers(paging_options) + |> Repo.all() end defp page_transaction_hashes_from_token_transfers(query, %PagingOptions{key: nil}), do: query From 030c17c58bdd330fe54060585e9a8ccfb42fda9e Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 30 May 2019 09:35:53 +0300 Subject: [PATCH 44/53] do not load associations for internal trxs for transaction page --- .../transaction_internal_transaction_controller.ex | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex index e318a74e78..7c24b8d3b9 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex @@ -10,18 +10,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do def index(conn, %{"transaction_id" => hash_string, "type" => "JSON"} = params) do with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), - {:ok, transaction} <- - Chain.hash_to_transaction( - hash, - necessity_by_association: %{ - :block => :optional, - [created_contract_address: :names] => :optional, - [from_address: :names] => :optional, - [to_address: :names] => :optional, - [to_address: :smart_contract] => :optional, - :token_transfers => :optional - } - ) do + {:ok, transaction} <- Chain.hash_to_transaction(hash) do full_options = Keyword.merge( [ From e02b27975725d5df0e06e90b536b4e8d888db174 Mon Sep 17 00:00:00 2001 From: maxgrapps Date: Thu, 30 May 2019 12:56:03 +0300 Subject: [PATCH 45/53] fixed length of logs search input --- apps/block_scout_web/assets/css/components/_log-search.scss | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/assets/css/components/_log-search.scss b/apps/block_scout_web/assets/css/components/_log-search.scss index 51ca8713d0..a31de73262 100644 --- a/apps/block_scout_web/assets/css/components/_log-search.scss +++ b/apps/block_scout_web/assets/css/components/_log-search.scss @@ -11,6 +11,7 @@ .logs-search { display: flex; + position: relative; @media (max-width: 599px) { margin-bottom: 30px; } @@ -34,7 +35,7 @@ flex-grow: 2; min-width: 160px; &::placeholder { - color: #a3a9b5; + color: #a3a9b5; } } @@ -54,6 +55,9 @@ color: #a3a9b5; cursor: pointer; transition: .1s ease-in; + position: absolute; + top: 0; + left: 136px; &:hover { color: #333; } From 0195642d71928a971cbd329f72d06df0cc44a46b Mon Sep 17 00:00:00 2001 From: maxgrapps <50101080+maxgrapps@users.noreply.github.com> Date: Thu, 30 May 2019 12:58:08 +0300 Subject: [PATCH 46/53] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f131c6a582..5e0a0e99b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - [#2012](https://github.com/poanetwork/blockscout/pull/2012) - make all pages pagination async ### Fixes +- [#2066](https://github.com/poanetwork/blockscout/pull/2066) - fixed length of logs search input - [#2056](https://github.com/poanetwork/blockscout/pull/2056) - log search form styles added - [#2043](https://github.com/poanetwork/blockscout/pull/2043) - Fixed modal dialog width for 'verify other explorers' - [#2025](https://github.com/poanetwork/blockscout/pull/2025) - Added a new color to display transactions' errors. From 580598e7c09d7920b725a5cfa40b272f83a365c4 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 30 May 2019 13:35:59 +0300 Subject: [PATCH 47/53] fix log page number --- apps/block_scout_web/assets/js/lib/async_listing_load.js | 4 +++- apps/block_scout_web/assets/js/pages/address/logs.js | 2 +- .../lib/block_scout_web/templates/address_logs/_logs.html.eex | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/assets/js/lib/async_listing_load.js b/apps/block_scout_web/assets/js/lib/async_listing_load.js index e22f6e399d..3fe14be121 100644 --- a/apps/block_scout_web/assets/js/lib/async_listing_load.js +++ b/apps/block_scout_web/assets/js/lib/async_listing_load.js @@ -105,7 +105,9 @@ export function asyncReducer (state = asyncInitialState, action) { state.pagesStack.push(window.location.href.split('?')[0]) } - state.pagesStack.push(state.nextPagePath) + if (state.pagesStack[state.pagesStack.length - 1] !== state.nextPagePath) { + state.pagesStack.push(state.nextPagePath) + } return Object.assign({}, state, { beyondPageOne: true }) } diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 7c9f806c01..ffe8ad5676 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -46,7 +46,7 @@ const elements = { } if ($('[data-page="address-logs"]').length) { - const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') + const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierLog') const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash const $element = $('[data-async-listing]') diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex index 66f75362c3..1b5cb5c4fd 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex @@ -1,4 +1,4 @@ -
+
">
<%= gettext "Transaction" %>
From 4e7d74f05178fefbc473468ca35936d0095a88d2 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 30 May 2019 13:43:19 +0300 Subject: [PATCH 48/53] fix CR issues --- .../block_scout_web/controllers/address_logs_controller.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex index c702856a06..db76b9d447 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex @@ -76,7 +76,10 @@ defmodule BlockScoutWeb.AddressLogsController do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), {:ok, address} <- Chain.hash_to_address(address_hash) do topic = String.trim(topic) - logs_plus_one = Chain.address_to_logs(address, topic: topic) + + formatted_topic = if String.starts_with?(topic, "0x"), do: topic, else: "0x" <> topic + + logs_plus_one = Chain.address_to_logs(address, topic: formatted_topic) {results, next_page} = split_list_by_page(logs_plus_one) From 6702a8cdde86a3cfc575905726f93dd3a7f7139e Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 30 May 2019 15:41:36 +0300 Subject: [PATCH 49/53] stop click twice --- apps/block_scout_web/assets/js/lib/async_listing_load.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/block_scout_web/assets/js/lib/async_listing_load.js b/apps/block_scout_web/assets/js/lib/async_listing_load.js index 3fe14be121..3a3eb2fd6c 100644 --- a/apps/block_scout_web/assets/js/lib/async_listing_load.js +++ b/apps/block_scout_web/assets/js/lib/async_listing_load.js @@ -281,12 +281,14 @@ function firstPageLoad (store) { event.preventDefault() loadItemsNext() store.dispatch({type: 'NAVIGATE_TO_OLDER'}) + event.stopImmediatePropagation() }) $element.on('click', '[data-prev-page-button]', (event) => { event.preventDefault() loadItemsPrev() store.dispatch({type: 'NAVIGATE_TO_NEWER'}) + event.stopImmediatePropagation() }) } From 3ae753f3370121159efb988dfcea4ab5c7217ab6 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 30 May 2019 15:50:52 +0300 Subject: [PATCH 50/53] Add docs folder for docsify integration --- docs/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/.gitkeep diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From f7bbfe4f20be7842328a562d3f8c203be18b8164 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 30 May 2019 15:56:54 +0300 Subject: [PATCH 51/53] Docsify setup --- docs/.nojekyll | 0 docs/README.md | 323 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/index.html | 21 ++++ 3 files changed, 344 insertions(+) create mode 100644 docs/.nojekyll create mode 100644 docs/README.md create mode 100644 docs/index.html diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000000..f53a43e897 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,323 @@ +

+ + + +

+ +

BlockScout

+

Blockchain Explorer for inspecting and analyzing EVM Chains.

+
+ +[![CircleCI](https://circleci.com/gh/poanetwork/blockscout.svg?style=svg&circle-token=f8823a3d0090407c11f87028c73015a331dbf604)](https://circleci.com/gh/poanetwork/blockscout) [![Coverage Status](https://coveralls.io/repos/github/poanetwork/blockscout/badge.svg?branch=master)](https://coveralls.io/github/poanetwork/blockscout?branch=master) [![Join the chat at https://gitter.im/poanetwork/blockscout](https://badges.gitter.im/poanetwork/blockscout.svg)](https://gitter.im/poanetwork/blockscout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +
+ +BlockScout provides a comprehensive, easy-to-use interface for users to view, confirm, and inspect transactions on **all EVM** (Ethereum Virtual Machine) blockchains. This includes the Ethereum main and test networks as well as **Ethereum forks and sidechains**. + +Following is an overview of the project and instructions for [getting started](#getting-started). + +Visit the [POA BlockScout forum](https://forum.poa.network/c/blockscout) for additional deployment instructions, FAQs, troubleshooting, and other BlockScout related items. You can also post and answer questions here. + +You can also access the dev chatroom on our [Gitter Channel](https://gitter.im/poanetwork/blockscout). + +## About BlockScout + +BlockScout is an Elixir application that allows users to search transactions, view accounts and balances, and verify smart contracts on the entire Ethereum network including all forks and sidechains. + +Currently available block explorers (i.e. Etherscan and Etherchain) are closed systems which are not independently verifiable. As Ethereum sidechains continue to proliferate in both private and public settings, transparent tools are needed to analyze and validate transactions. + + +### Features + +- [x] **Open source development**: The code is community driven and available for anyone to use, explore and improve. + +- [x] **Real time transaction tracking**: Transactions are updated in real time - no page refresh required. Infinite scrolling is also enabled. + +- [x] **Smart contract interaction**: Users can read and verify Solidity smart contracts and access pre-existing contracts to fast-track development. Support for Vyper, LLL, and Web Assembly contracts is in progress. + +- [x] **Token support**: ERC20 and ERC721 tokens are supported. Future releases will support additional token types including ERC223 and ERC1155. + +- [x] **User customization**: Users can easily deploy on a network and customize the Bootstrap interface. + +- [x] **Ethereum sidechain networks**: BlockScout supports the Ethereum mainnet, Ethereum testnets, POA network, and forks like Ethereum Classic, xDAI, additional sidechains, and private EVM networks. + +### Supported Projects + +| **Hosted Mainnets** | **Hosted Testnets** | **Additional Chains using BlockScout** | +|--------------------------------------------------------|-------------------------------------------------------|----------------------------------------------------| +| [Aerum](https://blockscout.com/aerum/mainnet) | [Goerli Testnet](https://blockscout.com/eth/goerli) | [ARTIS](https://explorer.sigma1.artis.network) | +| [Callisto](https://blockscout.com/callisto/mainnet) | [Kovan Testnet](https://blockscout.com/eth/kovan) | [Ether-1](https://blocks.ether1.wattpool.net/) | +| [Ethereum Classic](https://blockscout.com/etc/mainnet) | [POA Sokol Testnet](https://blockscout.com/poa/sokol) | [Fuse Network](https://explorer.fuse.io/) | +| [Ethereum Mainnet](https://blockscout.com/eth/mainnet) | [Rinkeby Testnet](https://blockscout.com/eth/rinkeby) | [Oasis Labs](https://blockexplorer.oasiscloud.io/) | +| [POA Core Network](https://blockscout.com/poa/core) | [Ropsten Testnet](https://blockscout.com/eth/ropsten) | [Petrichor](https://explorer.petrachor.com/) | +| [RSK](https://blockscout.com/rsk/mainnet) | | [PIRL](http://pirl.es/) | +| [xDai Chain](https://blockscout.com/poa/dai) | | [SafeChain](https://explorer.safechain.io) | +| | | [SpringChain](https://explorer.springrole.com/) | +| | | [Kotti Testnet](https://kottiexplorer.ethernode.io/) | + + +### Visual Interface + +Interface for the POA network _updated 02/2019_ + +![BlockScout Example](explorer_example_2_2019.gif) + + +### Umbrella Project Organization + +This repository is an [umbrella project](https://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-projects.html). Each directory under `apps/` is a separate [Mix](https://hexdocs.pm/mix/Mix.html) project and [OTP application](https://hexdocs.pm/elixir/Application.html), but the projects can use each other as a dependency in their `mix.exs`. + +Each OTP application has a restricted domain. + +| Directory | OTP Application | Namespace | Purpose | +|:------------------------|:--------------------|:------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `apps/ethereum_jsonrpc` | `:ethereum_jsonrpc` | `EthereumJSONRPC` | Ethereum JSONRPC client. It is allowed to know `Explorer`'s param format, but it cannot directly depend on `:explorer` | +| `apps/explorer` | `:explorer` | `Explorer` | Storage for the indexed chain. Can read and write to the backing storage. MUST be able to boot in a read-only mode when run independently from `:indexer`, so cannot depend on `:indexer` as that would start `:indexer` indexing. | +| `apps/block_scout_web` | `:block_scout_web` | `BlockScoutWeb` | Phoenix interface to `:explorer`. The minimum interface to allow web access should go in `:block_scout_web`. Any business rules or interface not tied directly to `Phoenix` or `Plug` should go in `:explorer`. MUST be able to boot in a read-only mode when run independently from `:indexer`, so cannot depend on `:indexer` as that would start `:indexer` indexing. | +| `apps/indexer` | `:indexer` | `Indexer` | Uses `:ethereum_jsonrpc` to index chain and batch import data into `:explorer`. Any process, `Task`, or `GenServer` that automatically reads from the chain and writes to `:explorer` should be in `:indexer`. This restricts automatic writes to `:indexer` and read-only mode can be achieved by not running `:indexer`. | + + +## Getting Started + +### Requirements + +| Dependency | Mac | Linux | +|-------------|-----|-------| +| [Erlang/OTP 21.0.4](https://github.com/erlang/otp) | `brew install erlang` | [Erlang Install Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L134) | +| [Elixir 1.8.1](https://elixir-lang.org/) | :point_up: | [Elixir Install Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L138) | +| [Postgres 10.3](https://www.postgresql.org/) | `brew install postgresql` | [Postgres Install Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L187) | +| [Node.js 10.x.x](https://nodejs.org/en/) | `brew install node` | [Node.js Install Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L66) | +| [Automake](https://www.gnu.org/software/automake/) | `brew install automake` | [Automake Install Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L72) | +| [Libtool](https://www.gnu.org/software/libtool/) | `brew install libtool` | [Libtool Install Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L62) | +| [Inotify-tools](https://github.com/rvoicilas/inotify-tools/wiki) | Not Required | Ubuntu - `apt-get install inotify-tools` | +| [GCC Compiler](https://gcc.gnu.org/) | `brew install gcc` | [GCC Compiler Example](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L70) | +| [GMP](https://gmplib.org/) | `brew install gmp` | [Install GMP Devel](https://github.com/poanetwork/blockscout-terraform/blob/33f68e816e36dc2fb055911fa0372531f0e956e7/modules/stack/libexec/init.sh#L74) | + +### Build and Run + +#### Playbook Deployment + +We use [Ansible](https://docs.ansible.com/ansible/latest/index.html) & [Terraform](https://www.terraform.io/intro/getting-started/install.html) to build the correct infrastructure to run BlockScout. See [https://github.com/poanetwork/blockscout-terraform](https://github.com/poanetwork/blockscout-terraform) for details and instructions. + +#### Manual Deployment + +See [Manual BlockScout Deployment](https://forum.poa.network/t/manual-blockscout-deployment/2458) for instructions. + +#### Environment Variables + +Our forum contains a [full list of BlockScout environment variables](https://forum.poa.network/t/faq-blockscout-environment-variables/1814). + +#### Configuring EVM Chains + +* **CSS:** Update the import instruction in `apps/block_scout_web/assets/css/theme/_variables.scss` to select a preset css file. This is reflected in the `production-${chain}` branch for each instance. For example, in the `production-xdai` branch, it is set to `@import "dai-variables"`. + +* **ENV:** Update the [environment variables](https://forum.poa.network/t/faq-blockscout-environment-variables/1814) to match the chain specs. + +#### Automating Restarts + +By default `blockscout` does not restart if it crashes. To enable automated +restarts, set the environment variable `HEART_COMMAND` to whatever command you run to start `blockscout`. Configure the heart beat timeout to change how long it waits before considering the application unresponsive. At that point, it will kill the current blockscout instance and execute the `HEART_COMMAND`. By default a crash dump is not written unless you set `ERL_CRASH_DUMP_SECONDS` to a positive or negative integer. See the [heart](http://erlang.org/doc/man/heart.html) documentation for more information. + + +#### CircleCI Updates + +To monitor build status, configure your local [CCMenu](http://ccmenu.org/) with the following url: [`https://circleci.com/gh/poanetwork/blockscout.cc.xml?circle-token=f8823a3d0090407c11f87028c73015a331dbf604`](https://circleci.com/gh/poanetwork/blockscout.cc.xml?circle-token=f8823a3d0090407c11f87028c73015a331dbf604) + + +## Testing + +### Requirements + + * PhantomJS (for wallaby) + +### Running the tests + + 1. Build the assets. + `cd apps/block_scout_web/assets && npm run build; cd -` + + 2. Format the Elixir code. + `mix format` + + 3. Run the test suite with coverage for whole umbrella project. This step can be run with different configuration outlined below. + `mix coveralls.html --umbrella` + + 4. Lint the Elixir code. + `mix credo --strict` + + 5. Run the dialyzer. + `mix dialyzer --halt-exit-status` + + 6. Check the Elixir code for vulnerabilities. + `cd apps/explorer && mix sobelow --config; cd -` + `cd apps/block_scout_web && mix sobelow --config; cd -` + + 7. Lint the JavaScript code. + `cd apps/block_scout_web/assets && npm run eslint; cd -` + + 8. Test the JavaScript code. + `cd apps/block_scout_web/assets && npm run test; cd -` + +#### Parity + +##### Mox + +**This is the default setup. `mix coveralls.html --umbrella` will work on its own, but to be explicit, use the following setup**: + +```shell +export ETHEREUM_JSONRPC_CASE=EthereumJSONRPC.Case.Parity.Mox +export ETHEREUM_JSONRPC_WEB_SOCKET_CASE=EthereumJSONRPC.WebSocket.Case.Mox +mix coveralls.html --umbrella --exclude no_parity +``` + +##### HTTP / WebSocket + +```shell +export ETHEREUM_JSONRPC_CASE=EthereumJSONRPC.Case.Parity.HTTPWebSocket +export ETHEREUM_JSONRPC_WEB_SOCKET_CASE=EthereumJSONRPC.WebSocket.Case.Parity +mix coveralls.html --umbrella --exclude no_parity +``` + +| Protocol | URL | +|:----------|:-----------------------------------| +| HTTP | `http://localhost:8545` | +| WebSocket | `ws://localhost:8546` | + +#### Geth + +##### Mox + +```shell +export ETHEREUM_JSONRPC_CASE=EthereumJSONRPC.Case.Geth.Mox +export ETHEREUM_JSONRPC_WEB_SOCKET_CASE=EthereumJSONRPC.WebSocket.Case.Mox +mix coveralls.html --umbrella --exclude no_geth +``` + +##### HTTP / WebSocket + +```shell +export ETHEREUM_JSONRPC_CASE=EthereumJSONRPC.Case.Geth.HTTPWebSocket +export ETHEREUM_JSONRPC_WEB_SOCKET_CASE=EthereumJSONRPC.WebSocket.Case.Geth +mix coveralls.html --umbrella --exclude no_geth +``` + +| Protocol | URL | +|:----------|:--------------------------------------------------| +| HTTP | `https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY` | +| WebSocket | `wss://mainnet.infura.io/ws/8lTvJTKmHPCHazkneJsY` | + +### API Documentation + +To view Modules and API Reference documentation: + +1. Generate documentation. +`mix docs` +2. View the generated docs. +`open doc/index.html` + +## Front-end + +### Javascript + +All Javascript files are under [apps/block_scout_web/assets/js](https://github.com/poanetwork/blockscout/tree/master/apps/block_scout_web/assets/js) and the main file is [app.js](https://github.com/poanetwork/blockscout/blob/master/apps/block_scout_web/assets/js/app.js). This file imports all javascript used in the application. If you want to create a new JS file consider creating into [/js/pages](https://github.com/poanetwork/blockscout/tree/master/apps/block_scout_web/assets/js/pages) or [/js/lib](https://github.com/poanetwork/blockscout/tree/master/apps/block_scout_web/assets/js/lib), as follows: + +#### js/lib +This folder contains all scripts that can be reused in any page or can be used as a helper to some component. + +#### js/pages +This folder contains the scripts that are specific for some page. + +#### Redux +This project uses Redux to control the state in some pages. There are pages that have things happening in real-time thanks to the Phoenix channels, e.g. Address page, so the page state changes a lot depending on which events it is listening. The redux is also used to load some contents asynchronous, see [async_listing_load.js](https://github.com/poanetwork/blockscout/blob/master/apps/block_scout_web/assets/js/lib/async_listing_load.js). + +To understand how to build new pages that need redux in this project, see the [redux_helpers.js](https://github.com/poanetwork/blockscout/blob/master/apps/block_scout_web/assets/js/lib/redux_helpers.js) + +## Internationalization + +The app is currently internationalized. It is only localized to U.S. English. To translate new strings. + +1. To setup translation file. +`cd apps/block_scout_web; mix gettext.extract --merge; cd -` +2. To edit the new strings, go to `apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po`. + +## Metrics + +BlockScout is setup to export [Prometheus](https://prometheus.io/) metrics at `/metrics`. + +### Prometheus + +1. Install prometheus: `brew install prometheus` +2. Start the web server `iex -S mix phx.server` +3. Start prometheus: `prometheus --config.file=prometheus.yml` + +### Grafana + +1. Install grafana: `brew install grafana` +2. Install Pie Chart panel plugin: `grafana-cli plugins install grafana-piechart-panel` +3. Start grafana: `brew services start grafana` +4. Add Prometheus as a Data Source + 1. `open http://localhost:3000/datasources` + 2. Click "+ Add data source" + 3. Put "Prometheus" for "Name" + 4. Change "Type" to "Prometheus" + 5. Set "URL" to "http://localhost:9090" + 6. Set "Scrape Interval" to "10s" +5. Add the dashboards from https://github.com/deadtrickster/beam-dashboards: + For each `*.json` file in the repo. + 1. `open http://localhost:3000/dashboard/import` + 2. Copy the contents of the JSON file in the "Or paste JSON" entry + 3. Click "Load" +6. View the dashboards. (You will need to click-around and use BlockScout for the web-related metrics to show up.) + +## Tracing + +Blockscout supports tracing via +[Spandex](http://git@github.com:spandex-project/spandex.git). Each application +has its own tracer, that is configured internally to that application. In order +to enable it, visit each application's `config/.ex` and update its tracer +configuration to change `disabled?: true` to `disabled?: false`. Do this for +each application you'd like included in your trace data. + +Currently, only [Datadog](https://www.datadoghq.com/) is supported as a +tracing backend, but more will be added soon. + +### DataDog + +If you would like to use DataDog, after enabling `Spandex`, set +`"DATADOG_HOST"` and `"DATADOG_PORT"` environment variables to the +host/port that your Datadog agent is running on. For more information on +Datadog and the Datadog agent, see their +[documentation](https://docs.datadoghq.com/). + +### Other + +If you want to use a different backend, remove the +`SpandexDatadog.ApiServer` `Supervisor.child_spec` from +`Explorer.Application` and follow any instructions provided in `Spandex` +for setting up that backend. + +## Memory Usage + +The work queues for building the index of all blocks, balances (coin and token), and internal transactions can grow quite large. By default, the soft-limit is 1 GiB, which can be changed in `apps/indexer/config/config.exs`: + +``` +config :indexer, memory_limit: 1 <<< 30 +``` + +Memory usage is checked once per minute. If the soft-limit is reached, the shrinkable work queues will shed half their load. The shed load will be restored from the database, the same as when a restart of the server occurs, so rebuilding the work queue will be slower, but use less memory. + +If all queues are at their minimum size, then no more memory can be reclaimed and an error will be logged. + +## Acknowledgements + +We would like to thank the [EthPrize foundation](http://ethprize.io/) for their funding support. + +## Contributing + +See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution and pull request protocol. We expect contributors to follow our [code of conduct](CODE_OF_CONDUCT.md) when submitting code or comments. + + +## License + +[![License: GPL v3.0](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) + +This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details. diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000000..f48a914259 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,21 @@ + + + + + Document + + + + + + +
+ + + + From 146280d857837c2397ab5bb54d9a2430537f91c5 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 30 May 2019 16:05:36 +0300 Subject: [PATCH 52/53] Add CHANGELOG entry and add 1.3.15 changelog --- CHANGELOG.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e3fe6e3a9..697a40007e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,17 +6,14 @@ - [#1928](https://github.com/poanetwork/blockscout/pull/1928) - pagination styles were updated - [#1940](https://github.com/poanetwork/blockscout/pull/1940) - qr modal button and background issue - [#1907](https://github.com/poanetwork/blockscout/pull/1907) - dropdown color bug fix (lukso theme) and tooltip color bug fix -- [#1857](https://github.com/poanetwork/blockscout/pull/1857) - Re-implement Geth JS internal transaction tracer in Elixir - [#1859](https://github.com/poanetwork/blockscout/pull/1859) - feat: show raw transaction traces - [#1941](https://github.com/poanetwork/blockscout/pull/1941) - feat: add on demand fetching and stale attr to rpc - [#1957](https://github.com/poanetwork/blockscout/pull/1957) - Calculate stakes ratio before insert pools - [#1956](https://github.com/poanetwork/blockscout/pull/1956) - add logs tab to address - [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default -- [#1989](https://github.com/poanetwork/blockscout/pull/1989) - fix: consolidate address w/ balance one at a time - [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct - [#1974](https://github.com/poanetwork/blockscout/pull/1974) - feat: previous page button logic - [#1999](https://github.com/poanetwork/blockscout/pull/1999) - load data async on addresses page -- [#2002](https://github.com/poanetwork/blockscout/pull/2002) - Get estimated count of blocks when cache is empty - [#1807](https://github.com/poanetwork/blockscout/pull/1807) - New theming capabilites. - [#2040](https://github.com/poanetwork/blockscout/pull/2040) - Verification links to other explorers for ETH - [#2012](https://github.com/poanetwork/blockscout/pull/2012) - make all pages pagination async @@ -30,7 +27,6 @@ - [#1944](https://github.com/poanetwork/blockscout/pull/1944) - fixed styles for token's dropdown. - [#1926](https://github.com/poanetwork/blockscout/pull/1926) - status label alignment - [#1849](https://github.com/poanetwork/blockscout/pull/1849) - Improve chains menu -- [#1869](https://github.com/poanetwork/blockscout/pull/1869) - Fix output and gas extraction in JS tracer for Geth - [#1868](https://github.com/poanetwork/blockscout/pull/1868) - fix: logs list endpoint performance - [#1822](https://github.com/poanetwork/blockscout/pull/1822) - Fix style breaks in decompiled contract code view - [#1885](https://github.com/poanetwork/blockscout/pull/1885) - highlight reserved words in decompiled code @@ -40,7 +36,6 @@ - [#1915](https://github.com/poanetwork/blockscout/pull/1915) - fallback to 2 latest evm versions - [#1937](https://github.com/poanetwork/blockscout/pull/1937) - Check the presence of overlap[i] object before retrieving properties from it - [#1960](https://github.com/poanetwork/blockscout/pull/1960) - do not remove bold text in decompiled contacts -- [#1992](https://github.com/poanetwork/blockscout/pull/1992) - fix: support https for wobserver polling - [#1966](https://github.com/poanetwork/blockscout/pull/1966) - fix: add fields for contract filter performance - [#2017](https://github.com/poanetwork/blockscout/pull/2017) - fix: fix to/from filters on tx list pages - [#2008](https://github.com/poanetwork/blockscout/pull/2008) - add new function clause for xDai network beneficiaries @@ -48,7 +43,6 @@ - [#2052](https://github.com/poanetwork/blockscout/pull/2052) - allow bytes32 for name and symbol - [#2047](https://github.com/poanetwork/blockscout/pull/2047) - fix: show creating internal transactions - [#2014](https://github.com/poanetwork/blockscout/pull/2014) - fix: use better queries for listLogs endpoint -- [#2027](https://github.com/poanetwork/blockscout/pull/2027) - fix: `BlocksTransactionsMismatch` ignoring blocks without transactions ### Chore @@ -60,11 +54,25 @@ - [#2000](https://github.com/poanetwork/blockscout/pull/2000) - docker/Makefile: always set a container name - [#2018](https://github.com/poanetwork/blockscout/pull/2018) - Use PORT env variable in dev config - [#2055](https://github.com/poanetwork/blockscout/pull/2055) - Increase timeout for geth indexers +- [#2069](https://github.com/poanetwork/blockscout/pull/2069) - Docsify integration: static docs page generation -## 1.3.14-beta +## 1.3.15-beta ### Features +- [#1857](https://github.com/poanetwork/blockscout/pull/1857) - Re-implement Geth JS internal transaction tracer in Elixir +- [#1989](https://github.com/poanetwork/blockscout/pull/1989) - fix: consolidate address w/ balance one at a time +- [#2002](https://github.com/poanetwork/blockscout/pull/2002) - Get estimated count of blocks when cache is empty + +### Fixes + +- [#1869](https://github.com/poanetwork/blockscout/pull/1869) - Fix output and gas extraction in JS tracer for Geth +- [#1992](https://github.com/poanetwork/blockscout/pull/1992) - fix: support https for wobserver polling +- [#2027](https://github.com/poanetwork/blockscout/pull/2027) - fix: `BlocksTransactionsMismatch` ignoring blocks without transactions + + +## 1.3.14-beta + - [#1812](https://github.com/poanetwork/blockscout/pull/1812) - add pagination to addresses page - [#1920](https://github.com/poanetwork/blockscout/pull/1920) - fix: remove source code fields from list endpoint - [#1876](https://github.com/poanetwork/blockscout/pull/1876) - async calculate a count of blocks From ad5ed095128b99e7cf5f4b9a3f6f224e0b0ab899 Mon Sep 17 00:00:00 2001 From: maxgrapps <50101080+maxgrapps@users.noreply.github.com> Date: Thu, 30 May 2019 22:48:12 +0300 Subject: [PATCH 53/53] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e3fe6e3a9..b7bb111e6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2073](https://github.com/poanetwork/blockscout/pull/2073) - blockscout default theme - [#1963](https://github.com/poanetwork/blockscout/pull/1963), [#1959](https://github.com/poanetwork/blockscout/pull/1959), [#1948](https://github.com/poanetwork/blockscout/pull/1948), [#1936](https://github.com/poanetwork/blockscout/pull/1936), [#1925](https://github.com/poanetwork/blockscout/pull/1925), [#1922](https://github.com/poanetwork/blockscout/pull/1922), [#1903](https://github.com/poanetwork/blockscout/pull/1903), [#1874](https://github.com/poanetwork/blockscout/pull/1874), [#1895](https://github.com/poanetwork/blockscout/pull/1895), [#2031](https://github.com/poanetwork/blockscout/pull/2031) - added new themes and logos for poa, eth, rinkeby, goerli, ropsten, kovan, sokol, xdai, etc, rsk - [#2010](https://github.com/poanetwork/blockscout/pull/2010) - added "block not found" and "tx not found pages" - [#1928](https://github.com/poanetwork/blockscout/pull/1928) - pagination styles were updated