From 779dc276eecc3ffb909823fed70c9f9beede79c5 Mon Sep 17 00:00:00 2001 From: Afr Schoe <58883403+q9f@users.noreply.github.com> Date: Sun, 23 Jun 2024 20:56:38 +0200 Subject: [PATCH 1/2] gem: run rufo --- lib/eth/abi/decoder.rb | 2 +- lib/eth/abi/event.rb | 14 ++-- lib/eth/contract/event.rb | 3 +- spec/eth/abi/event_spec.rb | 1 - spec/eth/contract/event_spec.rb | 130 ++++++++++++++++---------------- 5 files changed, 75 insertions(+), 75 deletions(-) diff --git a/lib/eth/abi/decoder.rb b/lib/eth/abi/decoder.rb index 27911a60..45da7f46 100644 --- a/lib/eth/abi/decoder.rb +++ b/lib/eth/abi/decoder.rb @@ -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| diff --git a/lib/eth/abi/event.rb b/lib/eth/abi/event.rb index d61b429d..a44bcbcb 100644 --- a/lib/eth/abi/event.rb +++ b/lib/eth/abi/event.rb @@ -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 @@ -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 diff --git a/lib/eth/contract/event.rb b/lib/eth/contract/event.rb index 60233ee4..01dc7649 100644 --- a/lib/eth/contract/event.rb +++ b/lib/eth/contract/event.rb @@ -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 diff --git a/spec/eth/abi/event_spec.rb b/spec/eth/abi/event_spec.rb index 19ed435f..fe22ba4d 100644 --- a/spec/eth/abi/event_spec.rb +++ b/spec/eth/abi/event_spec.rb @@ -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) diff --git a/spec/eth/contract/event_spec.rb b/spec/eth/contract/event_spec.rb index f5e78c91..b841f154 100644 --- a/spec/eth/contract/event_spec.rb +++ b/spec/eth/contract/event_spec.rb @@ -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" + "anonymous" => false, + "inputs" => [ + { + "components" => [ + { + "internalType" => "uint256", + "name" => "topicId", + "type" => "uint256", }, - { - "internalType" => "uint256", - "name" => "proposalId", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "proposalId", + "type" => "uint256", }, - { - "internalType" => "string", - "name" => "name", - "type" => "string" + { + "internalType" => "string", + "name" => "name", + "type" => "string", }, - { - "internalType" => "string", - "name" => "symbol", - "type" => "string" + { + "internalType" => "string", + "name" => "symbol", + "type" => "string", }, - { - "internalType" => "uint256", - "name" => "duration", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "duration", + "type" => "uint256", }, - { - "internalType" => "uint256", - "name" => "totalSupply", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "totalSupply", + "type" => "uint256", }, - { - "internalType" => "uint256", - "name" => "miniStakeValue", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "miniStakeValue", + "type" => "uint256", }, - { - "internalType" => "uint256", - "name" => "maxStakeValue", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "maxStakeValue", + "type" => "uint256", }, - { - "internalType" => "uint256", - "name" => "maxParticipants", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "maxParticipants", + "type" => "uint256", }, - { - "internalType" => "uint256", - "name" => "whitelistIndex", - "type" => "uint256" + { + "internalType" => "uint256", + "name" => "whitelistIndex", + "type" => "uint256", }, - { - "internalType" => "address", - "name" => "proposer", - "type" => "address" + { + "internalType" => "address", + "name" => "proposer", + "type" => "address", }, - { - "internalType" => "bool", - "name" => "useWhitelist", - "type" => "bool" - } - ], - "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') + { + "internalType" => "bool", + "name" => "useWhitelist", + "type" => "bool", + }, + ], + "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 From ca43ae764ff1ae3b2212acde95924a174721aa28 Mon Sep 17 00:00:00 2001 From: Afr Schoe <58883403+q9f@users.noreply.github.com> Date: Sun, 23 Jun 2024 20:59:57 +0200 Subject: [PATCH 2/2] gem: run rufo --- spec/eth/contract/event_spec.rb | 134 ++++++++++++++++---------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/spec/eth/contract/event_spec.rb b/spec/eth/contract/event_spec.rb index b841f154..94ba35ec 100644 --- a/spec/eth/contract/event_spec.rb +++ b/spec/eth/contract/event_spec.rb @@ -19,73 +19,73 @@ "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", - }, + "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", + }, ], "name" => "ProposalCreated", "type" => "event",