Skip to content

Commit

Permalink
fix event signature (#250)
Browse files Browse the repository at this point in the history
* add struct support in event topic calc

* fix event signature in contract.rb

---------

Co-authored-by: Afri <[email protected]>
  • Loading branch information
wuminzhe and q9f authored Jun 23, 2024
1 parent 502aa91 commit 9333e1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/eth/abi/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/eth/contract/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9333e1a

Please sign in to comment.