add convert wei to integer

pull/2036/head
saneery 6 years ago
parent 85401da1d0
commit d2740b0056
  1. 8
      apps/explorer/lib/explorer/chain/staking_pool.ex
  2. 5
      apps/explorer/lib/explorer/chain/wei.ex

@ -15,7 +15,7 @@ defmodule Explorer.Chain.StakingPool do
@attrs ~w( @attrs ~w(
is_active delegators_count staked_amount self_staked_amount is_validator is_active delegators_count staked_amount self_staked_amount is_validator
was_validator_count is_banned was_banned_count banned_until likelihood 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 staking_address_hash mining_address_hash
)a )a
@ -28,11 +28,12 @@ defmodule Explorer.Chain.StakingPool do
field(:likelihood, :decimal) field(:likelihood, :decimal)
field(:staked_ratio, :decimal) field(:staked_ratio, :decimal)
field(:min_candidate_stake, Wei) field(:min_candidate_stake, Wei)
field(:min_delegators_stake, Wei) field(:min_delegator_stake, Wei)
field(:self_staked_amount, Wei) field(:self_staked_amount, Wei)
field(:staked_amount, Wei) field(:staked_amount, Wei)
field(:was_banned_count, :integer) field(:was_banned_count, :integer)
field(:was_validator_count, :integer) field(:was_validator_count, :integer)
field(:is_deleted, :boolean, default: false)
belongs_to( belongs_to(
:staking_address, :staking_address,
@ -50,7 +51,7 @@ defmodule Explorer.Chain.StakingPool do
type: Hash.Address type: Hash.Address
) )
timestamps() timestamps(null: false, type: :utc_datetime_usec)
end end
@doc false @doc false
@ -59,6 +60,7 @@ defmodule Explorer.Chain.StakingPool do
|> cast(attrs, @attrs) |> cast(attrs, @attrs)
|> validate_required(@attrs) |> validate_required(@attrs)
|> validate_staked_amount() |> validate_staked_amount()
|> unique_constraint(:staking_address_hash)
end end
defp validate_staked_amount(%{valid?: false} = c), do: c defp validate_staked_amount(%{valid?: false} = c), do: c

@ -248,6 +248,11 @@ defmodule Explorer.Chain.Wei do
@spec to(t(), :wei) :: wei() @spec to(t(), :wei) :: wei()
def to(%__MODULE__{value: wei}, :wei), do: 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 end
defimpl Inspect, for: Explorer.Chain.Wei do defimpl Inspect, for: Explorer.Chain.Wei do

Loading…
Cancel
Save