@ -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
defimpl Poison.Encoder do
def encode(data, options) do
data
|> to_string()
|> BitString.encode(options)
defimpl Jason.Encoder do
alias Jason.Encode
def encode(data, opts) do
|> Encode.string(opts)
@ -286,4 +286,18 @@ defmodule Explorer.Chain.TransactionTest do
assert Transaction.decoded_input_data(transaction) == {:ok, "60fe47b1", "set(uint256 x)", [{"x", "uint256", 10}]}
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!()