Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gem: run rufo #277

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/eth/abi/decoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def type(type, arg)
type(Type.parse(type.base_type), arg[pointer + 32, Util.ceil32(data_l) + 32])
end
end
elsif type.base_type == 'tuple'
elsif type.base_type == "tuple"
offset = 0
data = {}
type.components.each do |c|
Expand Down
14 changes: 7 additions & 7 deletions lib/eth/abi/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def signature(interface)

def type(input)
if input["type"] == "tuple"
"(#{input["components"].map {|c| type(c) }.join(",")})"
"(#{input["components"].map { |c| type(c) }.join(",")})"
elsif input["type"] == "enum"
"uint8"
else
Expand Down Expand Up @@ -127,17 +127,17 @@ def decode_log(inputs, data, topics, anonymous = false)
topic_inputs, data_inputs = inputs.partition { |i| i["indexed"] }

topic_types = topic_inputs.map do |i|
if i['type'] == 'tuple'
Type.parse(i['type'], i['components'], i['name'])
if i["type"] == "tuple"
Type.parse(i["type"], i["components"], i["name"])
else
i['type']
i["type"]
end
end
data_types = data_inputs.map do |i|
if i['type'] == 'tuple'
Type.parse(i['type'], i['components'], i['name'])
if i["type"] == "tuple"
Type.parse(i["type"], i["components"], i["name"])
else
i['type']
i["type"]
end
end
# If event is anonymous, all topics are arguments. Otherwise, the first
Expand Down
3 changes: 2 additions & 1 deletion lib/eth/contract/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def set_address(address)
end

private

def type_name(x)
type = x["type"]
case type
when "tuple"
"(#{x['components'].collect { |c| type_name(c) }.join(',')})"
"(#{x["components"].collect { |c| type_name(c) }.join(",")})"
else
type
end
Expand Down
1 change: 0 additions & 1 deletion spec/eth/abi/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
expect(signature).to eq "Transfer(address,address,uint256)"
end


it "generates transfer function signature" do
abi = erc20_abi.find { |i| i["type"] == "function" && i["name"] == "transfer" }
signature = Abi::Event.signature(abi)
Expand Down
150 changes: 75 additions & 75 deletions spec/eth/contract/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,82 @@

it "generates signature for event with tuple params" do
event = Eth::Contract::Event.new({
"anonymous" => false,
"inputs" => [
{
"components" => [
{
"internalType" => "uint256",
"name" => "topicId",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "proposalId",
"type" => "uint256"
},
{
"internalType" => "string",
"name" => "name",
"type" => "string"
},
{
"internalType" => "string",
"name" => "symbol",
"type" => "string"
},
{
"internalType" => "uint256",
"name" => "duration",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "totalSupply",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "miniStakeValue",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "maxStakeValue",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "maxParticipants",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "whitelistIndex",
"type" => "uint256"
},
{
"internalType" => "address",
"name" => "proposer",
"type" => "address"
},
{
"internalType" => "bool",
"name" => "useWhitelist",
"type" => "bool"
}
],
"indexed" => false,
"internalType" => "struct VoteContract.ProposalCreatedParams",
"name" => "params",
"type" => "tuple"
}
"anonymous" => false,
"inputs" => [
{
"components" => [
{
"internalType" => "uint256",
"name" => "topicId",
"type" => "uint256",
},
{
"internalType" => "uint256",
"name" => "proposalId",
"type" => "uint256",
},
{
"internalType" => "string",
"name" => "name",
"type" => "string",
},
{
"internalType" => "string",
"name" => "symbol",
"type" => "string",
},
{
"internalType" => "uint256",
"name" => "duration",
"type" => "uint256",
},
{
"internalType" => "uint256",
"name" => "totalSupply",
"type" => "uint256",
},
{
"internalType" => "uint256",
"name" => "miniStakeValue",
"type" => "uint256",
},
{
"internalType" => "uint256",
"name" => "maxStakeValue",
"type" => "uint256",
},
{
"internalType" => "uint256",
"name" => "maxParticipants",
"type" => "uint256",
},
{
"internalType" => "uint256",
"name" => "whitelistIndex",
"type" => "uint256",
},
{
"internalType" => "address",
"name" => "proposer",
"type" => "address",
},
{
"internalType" => "bool",
"name" => "useWhitelist",
"type" => "bool",
},
],
"name" => "ProposalCreated",
"type" => "event"
})
expect(event.event_string).to eq('ProposalCreated((uint256,uint256,string,string,uint256,uint256,uint256,uint256,uint256,uint256,address,bool))')
expect(event.signature).to eq('4449031b77cbe261580701c097fb63211e768f685581e616330dfff20493536c')
"indexed" => false,
"internalType" => "struct VoteContract.ProposalCreatedParams",
"name" => "params",
"type" => "tuple",
},
],
"name" => "ProposalCreated",
"type" => "event",
})
expect(event.event_string).to eq("ProposalCreated((uint256,uint256,string,string,uint256,uint256,uint256,uint256,uint256,uint256,address,bool))")
expect(event.signature).to eq("4449031b77cbe261580701c097fb63211e768f685581e616330dfff20493536c")
end
end
end
Loading