Skip to content

Commit

Permalink
use fixed version of ex_abi (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 authored Jun 1, 2020
1 parent c8cad63 commit 1feed63
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion apps/omg/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule OMG.MixProject do

defp deps() do
[
{:ex_plasma, git: "https://github.com/omisego/ex_plasma.git", ref: "c220f4087957bf98db63fc6250cdc1ca37a89a52"},
{:ex_plasma, git: "https://github.com/omisego/ex_plasma.git", ref: "83db9a0f5a441f7e59ae23f8c64658e2c387f8a5"},
{:ex_rlp, "~> 0.5.3"},
{:merkle_tree, "~> 2.0.0"},
{:telemetry, "~> 0.4.1"},
Expand Down
2 changes: 1 addition & 1 deletion apps/omg_eth/lib/omg_eth/encoding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule OMG.Eth.Encoding do
...> {{:uint, 8}, 255},
...> {:string, "hello"},
...> ])
"00000000000000000000000000000000000000000000000000000000000000ff000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000ff0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000"
"""
@spec encode_constructor_params(types_values :: [tuple()]) :: abi_base16_encoded :: binary()
def encode_constructor_params(types_values) do
Expand Down
56 changes: 10 additions & 46 deletions apps/omg_eth/lib/omg_eth/root_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule OMG.Eth.RootChain do
"""

require Logger
import OMG.Eth.Encoding, only: [to_hex: 1, from_hex: 1, int_from_hex: 1]
import OMG.Eth.Encoding, only: [int_from_hex: 1]

alias OMG.Eth
alias OMG.Eth.Configuration
Expand Down Expand Up @@ -52,49 +52,28 @@ defmodule OMG.Eth.RootChain do
{block_hash, block_timestamp}
end

##
## these two cannot be parsed with ABI decoder!
##
@doc """
Returns standard exits data from the contract for a list of `exit_id`s. Calls contract method.
"""
def get_standard_exit_structs(exit_ids) do
contract = Configuration.contracts().payment_exit_game

return_types = [
{:array, {:tuple, [:bool, {:uint, 256}, {:bytes, 32}, :address, {:uint, 256}, {:uint, 256}]}}
]

# TODO: hack around an issue with `ex_abi` https://github.com/poanetwork/ex_abi/issues/22
# We procure a hacky version of `OMG.Eth.Client.call_contract` which strips the offending offsets from
# the ABI-encoded binary and proceeds to decode the array without the offset
# Revert to `call_contract` when that issue is resolved
call_contract_manual_exits(
contract,
"standardExits(uint160[])",
[exit_ids],
return_types
)
%{"standard_exit_structs" => standard_exit_structs} =
get_external_data(contract, "standardExits(uint160[])", [exit_ids])

{:ok, standard_exit_structs}
end

@doc """
Returns in flight exits of the specified ids. Calls a contract method.
"""
def get_in_flight_exit_structs(in_flight_exit_ids) do
contract = Configuration.contracts().payment_exit_game
{:array, {:tuple, [:bool, {:uint, 256}, {:bytes, 32}, :address, {:uint, 256}, {:uint, 256}]}}

# solidity does not return arrays of structs
return_types = [
{:array, {:tuple, [:bool, {:uint, 64}, {:uint, 256}, {:uint, 256}, :address, {:uint, 256}, {:uint, 256}]}}
]

call_contract_manual_exits(
contract,
"inFlightExits(uint160[])",
[in_flight_exit_ids],
return_types
)

%{"in_flight_exit_structs" => in_flight_exit_structs} =
get_external_data(contract, "inFlightExits(uint160[])", [in_flight_exit_ids])

{:ok, in_flight_exit_structs}
end

########################
Expand All @@ -119,21 +98,6 @@ defmodule OMG.Eth.RootChain do
end
end

# TODO: see above in where it is called - temporary function
defp call_contract_manual_exits(contract, signature, args, return_types) do
data = ABI.encode(signature, args)

{:ok, return} = Ethereumex.HttpClient.eth_call(%{to: contract, data: to_hex(data)})
decode_answer_manual_exits(return, return_types)
end

# TODO: see above in where it is called - temporary function
defp decode_answer_manual_exits(enc_return, return_types) do
<<32::size(32)-unit(8), raw_array_data::binary>> = from_hex(enc_return)
[single_return] = ABI.TypeDecoder.decode(raw_array_data, return_types)
{:ok, single_return}
end

defp get_external_data(contract_address, signature, args) do
{:ok, data} = Rpc.call_contract(contract_address, signature, args)
Abi.decode_function(data, signature)
Expand Down
45 changes: 45 additions & 0 deletions apps/omg_eth/lib/omg_eth/root_chain/abi_function_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,49 @@ defmodule OMG.Eth.RootChain.AbiFunctionSelector do
types: [bytes: 32, uint: 256]
}
end

def standard_exits() do
%ABI.FunctionSelector{
function: "standardExits",
input_names: ["standard_exit_structs"],
inputs_indexed: nil,
method_id: <<12, 165, 182, 118>>,
# returns: [
# array: {:tuple, [:bool, {:uint, 256}, {:bytes, 32}, :address, {:uint, 256}, {:uint, 256}]}
# ],
type: :function,
# types: [array: {:uint, 160}]
types: [
array: {:tuple, [:bool, {:uint, 256}, {:bytes, 32}, :address, {:uint, 256}, {:uint, 256}]}
]
}
end

def in_flight_exits() do
%ABI.FunctionSelector{
function: "inFlightExits",
input_names: ["in_flight_exit_structs"],
inputs_indexed: nil,
method_id: <<206, 201, 225, 167>>,
# returns: [
# array: {:tuple,
# [
# :bool,
# {:uint, 64},
# {:uint, 256},
# {:uint, 256},
# {:array, :tuple, 4},
# {:array, :tuple, 4},
# :address,
# {:uint, 256},
# {:uint, 256}
# ]}
# ],
type: :function,
# types: [array: {:uint, 160}]
types: [
{:array, {:tuple, [:bool, {:uint, 64}, {:uint, 256}, {:uint, 256}, :address, {:uint, 256}, {:uint, 256}]}}
]
}
end
end
2 changes: 1 addition & 1 deletion apps/omg_eth/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule OMG.Eth.MixProject do

defp deps() do
[
{:ex_abi, "~> 0.2.1"},
{:ex_abi, "~> 0.4"},
{:ethereumex, "~> 0.6.0"},
# Umbrella
{:omg_bus, in_umbrella: true},
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"erlexec": {:hex, :erlexec, "1.10.9", "3cbb3476f942bfb8b68b85721c21c1835061cf6dd35f5285c2362e85b100ddc7", [:rebar3], [], "hexpm", "271e5b5f2d91cdb9887efe74d89026c199bfc69f074cade0d08dab60993fa14e"},
"ethereumex": {:hex, :ethereumex, "0.6.2", "310954c27e7f7b0397795525f7eaae60169fbe5082a5935bde4a65a121fad8e7", [:mix], [{:httpoison, "~> 1.6", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "76d2c65cbbdac3abf13cbc9615767c90678a8d56643cd34d6ce114782769e57c"},
"ex_abi": {:hex, :ex_abi, "0.2.2", "805c19edccb98ecd02a2eee1851d49f625ae036953ae45b3349468333b19870e", [:mix], [{:exth_crypto, "~> 0.1.6", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm", "649688a53dde9c676f6a760cc0c1e43cb246010a7f83b13b9e5bd75aa04cc409"},
"ex_abi": {:hex, :ex_abi, "0.4.0", "ff7e7f5b56c228b117e1f54e80c668a8f0424c275f233a50373548b70d99bd5c", [:mix], [{:exth_crypto, "~> 0.1.6", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm", "2d33499de38c54531103e58530d0453863fb6149106327f691001873b0556e68"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"},
"ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"},
"ex_plasma": {:git, "https://github.com/omisego/ex_plasma.git", "c220f4087957bf98db63fc6250cdc1ca37a89a52", [ref: "c220f4087957bf98db63fc6250cdc1ca37a89a52"]},
"ex_plasma": {:git, "https://github.com/omisego/ex_plasma.git", "83db9a0f5a441f7e59ae23f8c64658e2c387f8a5", [ref: "83db9a0f5a441f7e59ae23f8c64658e2c387f8a5"]},
"ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"},
"ex_unit_fixtures": {:git, "https://github.com/omisego/ex_unit_fixtures.git", "4a099c621dc70e0d65cb9619b38192e31ec5f504", [branch: "feature/require_files_not_load"]},
"excoveralls": {:hex, :excoveralls, "0.12.3", "2142be7cb978a3ae78385487edda6d1aff0e482ffc6123877bb7270a8ffbcfe0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "568a3e616c264283f5dea5b020783ae40eef3f7ee2163f7a67cbd7b35bcadada"},
Expand Down

0 comments on commit 1feed63

Please sign in to comment.