From d2740b0056750bb619d7916c73dc0bc0de66dda0 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 23 May 2019 11:43:33 +0300 Subject: [PATCH] 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