From 9333e1acb2c3bc52a756d851c1823cdbc3d5219b Mon Sep 17 00:00:00 2001 From: Aki Wu Date: Mon, 24 Jun 2024 02:55:06 +0800 Subject: [PATCH] fix event signature (#250) * add struct support in event topic calc * fix event signature in contract.rb --------- Co-authored-by: Afri <58883403+q9f@users.noreply.github.com> --- lib/eth/abi/event.rb | 12 +++++++++++- lib/eth/contract/event.rb | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/eth/abi/event.rb b/lib/eth/abi/event.rb index d0af31d8..d61b429d 100644 --- a/lib/eth/abi/event.rb +++ b/lib/eth/abi/event.rb @@ -40,10 +40,20 @@ def compute_topic(interface) def signature(interface) name = interface.fetch("name") inputs = interface.fetch("inputs", []) - types = inputs.map { |i| i.fetch("type") } + types = inputs.map { |i| type(i) } "#{name}(#{types.join(",")})" end + def type(input) + if input["type"] == "tuple" + "(#{input["components"].map {|c| type(c) }.join(",")})" + elsif input["type"] == "enum" + "uint8" + else + input["type"] + end + end + # A decoded event log. class LogDescription # The event ABI interface used to decode the log. diff --git a/lib/eth/contract/event.rb b/lib/eth/contract/event.rb index 0106b3e8..60233ee4 100644 --- a/lib/eth/contract/event.rb +++ b/lib/eth/contract/event.rb @@ -30,7 +30,7 @@ def initialize(data) type_name x end @inputs = data["inputs"].collect { |x| x["name"] } - @event_string = "#{@name}(#{@input_types.join(",")})" + @event_string = Abi::Event.signature(data) @signature = Digest::Keccak.hexdigest(@event_string, 256) end