add cast! and dump! to Wei module

pull/2036/head
saneery 6 years ago
parent 03fd6f9540
commit 85401da1d0
  1. 10
      apps/explorer/lib/explorer/chain/wei.ex

@ -68,6 +68,11 @@ defmodule Explorer.Chain.Wei do
@impl Ecto.Type @impl Ecto.Type
def cast(_), do: :error def cast(_), do: :error
def cast!(arg) do
{:ok, wei} = cast(arg)
wei
end
@impl Ecto.Type @impl Ecto.Type
def dump(%__MODULE__{value: %Decimal{} = decimal}) do def dump(%__MODULE__{value: %Decimal{} = decimal}) do
{:ok, decimal} {:ok, decimal}
@ -76,6 +81,11 @@ defmodule Explorer.Chain.Wei do
@impl Ecto.Type @impl Ecto.Type
def dump(_), do: :error def dump(_), do: :error
def dump!(arg) do
{:ok, decimal} = dump(arg)
decimal
end
@impl Ecto.Type @impl Ecto.Type
def load(%Decimal{} = decimal) do def load(%Decimal{} = decimal) do
{:ok, %__MODULE__{value: decimal}} {:ok, %__MODULE__{value: decimal}}

Loading…
Cancel
Save