4
0
Fork 0

Providing filter indexes works

indexed
hswick 7 years ago
parent 586a8b416c
commit 15c2b5accb
  1. 33
      lib/exw3.ex
  2. 2
      test/exw3_test.exs

@ -329,7 +329,6 @@ defmodule ExW3 do
)
end
@spec encode_option(integer()) :: binary()
@doc "Encodes options into Ethereum JSON RPC hex string"
def encode_option(0), do: "0x0"
@ -732,7 +731,26 @@ defmodule ExW3 do
# Calls
defp filter_topics_helper(event_signature, event_data, topic_types) do
if event_data[:topics] do
topics = event_data[:topics]
if topics do
formatted_topics =
Enum.map(0..length(topics) - 1, fn i ->
topic = Enum.at(topics, i)
if topic do
if is_list(topic) do
topic_type = Enum.at(topic_types, i)
Enum.map(topic, fn t ->
"0x" <> (ExW3.encode_data(topic_type, [t]) |> Base.encode16(case: :lower))
end)
else
topic_type = Enum.at(topic_types, i)
"0x" <> (ExW3.encode_data(topic_type, [topic]) |> Base.encode16(case: :lower))
end
else
topic
end
end)
[event_signature] ++ formatted_topics
else
[event_signature]
end
@ -747,12 +765,17 @@ defmodule ExW3 do
end
event_signature = contract_info[:event_names][event_name]
topic_types = contract_info[:events][event_signature]
IO.inspect topic_types
topic_types = contract_info[:events][event_signature][:topic_types]
topics = filter_topics_helper(event_signature, event_data, topic_types)
payload = Map.merge(%{address: contract_info[:address], topics: topics}, event_data)
payload = Map.merge(
%{address: contract_info[:address], topics: topics},
Map.delete(event_data, :topics)
)
IO.inspect payload
filter_id = ExW3.new_filter(payload)
event_attributes = contract_info[:events][contract_info[:event_names][event_name]]

@ -268,7 +268,7 @@ defmodule EXW3Test do
{:ok, agent} = Agent.start_link(fn -> [] end)
indexed_filter_id = ExW3.Contract.filter(:EventTester, "SimpleIndex", self(), %{topics: [46, "Hello, World!"]})
indexed_filter_id = ExW3.Contract.filter(:EventTester, "SimpleIndex", self(), %{topics: [nil, ["Hello, World", "Hello, World!"]]})
{:ok, _tx_hash} =
ExW3.Contract.send(

Loading…
Cancel
Save