Skip to content

Commit

Permalink
update ex_rlp, implement ExRLP.Encode for LogEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed May 1, 2018
1 parent d4c7d53 commit 4c1ce64
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .dialyzer.ignore-warnings
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ lib/evm/interface/mock/mock_account_interface.ex:138: The inferred return type o
lib/evm/interface/mock/mock_account_interface.ex:199: The return type {integer(),atom(),#{'__struct__':='Elixir.EVM.SubState', 'logs':=binary(), 'refund':=integer(), 'suicide_list':=[<<_:160>>]}} in the specification of create_contract/9 is not a subtype of {atom(),integer(),#{'__struct__':='Elixir.EVM.SubState', 'logs':=binary(), 'refund':=integer(), 'suicide_list':=[<<_:160>>]}}, which is the expected return type for the callback of the 'Elixir.EVM.Interface.AccountInterface' behaviour
lib/evm/interface/mock/mock_account_interface.ex:199: Invalid type specification for function 'Elixir.EVM.Interface.AccountInterface.EVM.Interface.Mock.MockAccountInterface':create_contract/9. The success typing is (atom() | #{'contract_result':='nil' | [{atom(),_}] | map(), _=>_},_,_,_,_,_,_,_,_) -> {atom() | #{'contract_result':='nil' | [{_,_}] | map(), _=>_},_,_}
lib/evm/interface/mock/mock_block_interface.ex:10: Invalid type specification for function 'Elixir.EVM.Interface.Mock.MockBlockInterface':new/2. The success typing is (_,_) -> #{'__struct__':='Elixir.EVM.Interface.Mock.MockBlockInterface', 'block_header':=_, 'block_map':=_}
lib/evm/interface/mock/mock_account_interface.ex:199: The return type {integer(),atom(),#{'__struct__':='Elixir.EVM.SubState', 'logs':=[#{'__struct__':='Elixir.EVM.LogEntry', 'address':=<<_:160>>, 'data':=binary(), 'topics':=[integer()]}], 'refund':=integer(), 'suicide_list':=[<<_:160>>]}} in the specification of create_contract/9 is not a subtype of {atom(),integer(),#{'__struct__':='Elixir.EVM.SubState', 'logs':=[#{'__struct__':='Elixir.EVM.LogEntry', 'address':=<<_:160>>, 'data':=binary(), 'topics':=[integer()]}], 'refund':=integer(), 'suicide_list':=[<<_:160>>]}}, which is the expected return type for the callback of the 'Elixir.EVM.Interface.AccountInterface' behaviour
lib/evm/interface/mock/mock_account_interface.ex:199: The return type {integer(),atom(),#{'__struct__':='Elixir.EVM.SubState', 'logs':=[#{'__struct__':='Elixir.EVM.LogEntry', 'address':=<<_:160>>, 'data':=binary(), 'topics':=[binary()]}], 'refund':=integer(), 'suicide_list':=[<<_:160>>]}} in the specification of create_contract/9 is not a subtype of {atom(),integer(),#{'__struct__':='Elixir.EVM.SubState', 'logs':=[#{'__struct__':='Elixir.EVM.LogEntry', 'address':=<<_:160>>, 'data':=binary(), 'topics':=[binary()]}], 'refund':=integer(), 'suicide_list':=[<<_:160>>]}}, which is the expected return type for the callback of the 'Elixir.EVM.Interface.AccountInterface' behaviour

lib/evm/machine_code.ex:113: The variable _@1 can never match since previous clauses completely covered the type bitstring()
lib/evm/machine_code.ex:113: Cons will produce an improper list since its 2nd argument is binary(
24 changes: 23 additions & 1 deletion lib/evm/log_entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@ defmodule EVM.LogEntry do
This module contains functions to work with logs.
"""

alias EVM.Address

defstruct address: nil, topics: [], data: nil

@type t :: %__MODULE__{
address: EVM.address(),
topics: [integer()],
topics: [binary()],
data: binary()
}

@spec new(integer() | binary(), [integer()], binary()) :: t()
def new(address, topics, data) do
address = if is_number(address), do: address |> Address.new(), else: address

%__MODULE__{
address: address,
topics: topics,
data: data
}
end

@spec to_list(t()) :: [binary()]
def to_list(log) do
[log.address, log.topics, log.data]
end
end

defimpl ExRLP.Encode, for: EVM.LogEntry do
alias ExRLP.Encode
alias EVM.LogEntry

@spec encode(LogEntry.t(), keyword()) :: binary()
def encode(log, options \\ []) do
log
|> LogEntry.to_list()
|> Encode.encode(options)
end
end
2 changes: 1 addition & 1 deletion lib/evm/sub_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule EVM.SubState do
## Examples
iex> sub_state = %EVM.SubState{suicide_list: [], logs: [], refund: 0}
iex> sub_state |> EVM.SubState.add_log(<<0::160>>, [1, 10, 12], "adsfa")
iex> sub_state |> EVM.SubState.add_log(0, [1, 10, 12], "adsfa")
%EVM.SubState{
logs: [
%EVM.LogEntry{
Expand Down
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ defmodule EVM.Mixfile do
# Type "mix help deps" for more examples and options
defp deps do
[
{:ex_rlp, "~> 0.3.0"},
{:credo, "~> 0.9.1", only: [:dev, :test], runtime: false},
{:poison, "~> 3.1.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.14", only: :dev, runtime: false},
{:merkle_patricia_tree, "~> 0.2.5"},
{:merkle_patricia_tree,
git: "[email protected]:poanetwork/merkle_patricia_tree.git", branch: 'update_ex_rlp'},
{:keccakf1600, "~> 2.0.0", hex: :keccakf1600_orig},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false}
]
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], [], "hexpm"},
"eleveldb": {:hex, :eleveldb, "2.2.20", "1fff63a5055bbf4bf821f797ef76065882b193f5e8095f95fcd9287187773b58", [:rebar3], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.16.2", "3b3e210ebcd85a7c76b4e73f85c5640c011d2a0b2f06dcdf5acdb2ae904e5084", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"ex_rlp": {:hex, :ex_rlp, "0.2.1", "bd320900d6316cdfe01d365d4bda22eb2f39b359798daeeffd3bd1ca7ba958ec", [:mix], [], "hexpm"},
"exleveldb": {:hex, :exleveldb, "0.11.1", "37c0414208a50d2419d8246305e6c4a33ed339c25c0bdfa27774795e1e089f7b", [:mix], [{:eleveldb, "~> 2.2.19", [hex: :eleveldb, repo: "hexpm", optional: false]}], "hexpm"},
"ex_rlp": {:hex, :ex_rlp, "0.3.0", "76eb293a743b17d6071693014c1a57eb0f3f71fbf560716046d62c8a14340628", [:mix], [], "hexpm"},
"exleveldb": {:hex, :exleveldb, "0.13.1", "7f82ef6ae75bdcbea4e7aaa297601e7adea3631525114412fa7548d83b70bbca", [:mix], [{:eleveldb, "~> 2.2.20", [hex: :eleveldb, repo: "hexpm", optional: false]}], "hexpm"},
"hex_prefix": {:hex, :hex_prefix, "0.1.0", "e96b5cbb6ad8493196ce193726240023f5ce0ae0753118a19a5b43e2db0267ca", [:mix], [], "hexpm"},
"keccakf1600": {:hex, :keccakf1600_orig, "2.0.0", "0a7217ddb3ee8220d449bbf7575ec39d4e967099f220a91e3dfca4dbaef91963", [:rebar3], [], "hexpm"},
"merkle_patricia_tree": {:hex, :merkle_patricia_tree, "0.2.5", "cdbd2addf8fe46c5d6025dc76b31049c3d252c776b7ec01b0760f5142848e5b2", [:mix], [{:ex_rlp, "~> 0.2.0", [hex: :ex_rlp, repo: "hexpm", optional: false]}, {:exleveldb, "~> 0.11.1", [hex: :exleveldb, repo: "hexpm", optional: false]}, {:hex_prefix, "~> 0.1.0", [hex: :hex_prefix, repo: "hexpm", optional: false]}, {:keccakf1600, "~> 2.0.0", [hex: :keccakf1600_orig, repo: "hexpm", optional: false]}], "hexpm"},
"merkle_patricia_tree": {:git, "[email protected]:poanetwork/merkle_patricia_tree.git", "fa712e49882cd920d3a8195c7806384b98e9daf1", [branch: 'update_ex_rlp']},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
}

0 comments on commit 4c1ce64

Please sign in to comment.