Skip to content

Commit

Permalink
fix the topic hash generation for tuple params
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRay committed Jun 11, 2024
1 parent 9f5efda commit 505f48d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/eth/contract/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Contract::Event
# @param data [Hash] contract event data.
def initialize(data)
@name = data["name"]
@input_types = data["inputs"].collect { |x| x["type"] }
@input_types = data["inputs"].collect do |x|
type_name x
end
@inputs = data["inputs"].collect { |x| x["name"] }
@event_string = "#{@name}(#{@input_types.join(",")})"
@signature = Digest::Keccak.hexdigest(@event_string, 256)
Expand All @@ -38,5 +40,16 @@ def initialize(data)
def set_address(address)
@address = address.nil? ? nil : Eth::Address.new(address).address
end

private
def type_name(x)
type = x["type"]
case type
when "tuple"
"(#{x['components'].collect { |c| type_name(c) }.join(',')})"
else
type
end
end
end
end

0 comments on commit 505f48d

Please sign in to comment.