diff --git a/apps/explorer/lib/explorer/chain/data.ex b/apps/explorer/lib/explorer/chain/data.ex index ee03bdeb24..a3bec019af 100644 --- a/apps/explorer/lib/explorer/chain/data.ex +++ b/apps/explorer/lib/explorer/chain/data.ex @@ -7,6 +7,7 @@ defmodule Explorer.Chain.Data do """ alias Explorer.Chain.Data + alias Poison.Encoder.BitString @behaviour Ecto.Type @@ -380,4 +381,22 @@ defmodule Explorer.Chain.Data do @for.to_string(data) end end + + defimpl Poison.Encoder do + def encode(data, options) do + data + |> to_string() + |> BitString.encode(options) + end + end + + defimpl Jason.Encoder do + alias Jason.Encode + + def encode(data, opts) do + data + |> to_string() + |> Encode.string(opts) + end + end end diff --git a/apps/explorer/test/explorer/chain/transaction_test.exs b/apps/explorer/test/explorer/chain/transaction_test.exs index 08f30a0bfa..5fe6b9958c 100644 --- a/apps/explorer/test/explorer/chain/transaction_test.exs +++ b/apps/explorer/test/explorer/chain/transaction_test.exs @@ -286,4 +286,18 @@ defmodule Explorer.Chain.TransactionTest do assert Transaction.decoded_input_data(transaction) == {:ok, "60fe47b1", "set(uint256 x)", [{"x", "uint256", 10}]} end end + + describe "Poison.encode!/1" do + test "encodes transaction input" do + assert %{ + insert(:transaction) + | input: %Explorer.Chain.Data{ + bytes: + <<169, 5, 156, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 193, 108, 45, 196, 42, 228, 149, 239, 119, + 191, 128, 248>> + } + } + |> Poison.encode!() + end + end end