From b235be554cb73576f698baa2285f5b38d1ee8430 Mon Sep 17 00:00:00 2001 From: daoready Date: Fri, 30 Nov 2018 00:34:17 +0300 Subject: [PATCH 01/36] ABI tuple parser --- lib/web3/eth/abi/abi_coder.rb | 4 +++- lib/web3/eth/abi/type.rb | 27 +++++++++++++++++++++++++++ lib/web3/eth/contract.rb | 12 ++++++++++-- lib/web3/eth/version.rb | 2 +- web3-eth.gemspec | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index a131b39..326c393 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -248,7 +248,9 @@ def decode_typed_data type_name, data end def decode_type(type, arg) - if %w(string bytes).include?(type.base) && type.sub.empty? + if type.kind_of?(Tuple) + decode_abi(type.types, arg) + elsif %w(string bytes).include?(type.base) && type.sub.empty? l = Utils.big_endian_to_int arg[0,32] data = arg[32..-1] data[0, l] diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index c0c01ad..edd3484 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -12,6 +12,11 @@ class < Date: Fri, 30 Nov 2018 00:42:00 +0300 Subject: [PATCH 02/36] https://github.com/Bloxy-info/web3-eth --- README.md | 2 +- web3-eth.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0167b24..b1f687d 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/izetex/web3-eth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. +Bug reports and pull requests are welcome on GitHub at https://github.com/Bloxy-info/web3-eth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License diff --git a/web3-eth.gemspec b/web3-eth.gemspec index adf92ca..bbfacec 100644 --- a/web3-eth.gemspec +++ b/web3-eth.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.summary = %q{Web3 client to connect to Ethereum node by RPC.} spec.description = %q{Calling RPC methods of Ethereum node with Ruby.} - spec.homepage = "https://github.com/izetex/web3-eth" + spec.homepage = "https://github.com/Bloxy-info/web3-eth" spec.license = "MIT" From c24a2f11d1bae6829e8dabde540523fe92215c83 Mon Sep 17 00:00:00 2001 From: daoready Date: Fri, 30 Nov 2018 01:32:30 +0300 Subject: [PATCH 03/36] fix event with tuple parse --- lib/web3/eth/abi/abi_coder.rb | 2 +- lib/web3/eth/contract.rb | 6 +++--- lib/web3/eth/version.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index 326c393..317a39a 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -249,7 +249,7 @@ def decode_typed_data type_name, data def decode_type(type, arg) if type.kind_of?(Tuple) - decode_abi(type.types, arg) + arg ? decode_abi(type.types, arg) : [] elsif %w(string bytes).include?(type.base) && type.sub.empty? l = Utils.big_endian_to_int arg[0,32] data = arg[32..-1] diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index 596af04..519e4d3 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -52,8 +52,8 @@ def parse_component_type argument def parse_event_args log log_data = remove_0x_head log.raw_data['data'] - indexed_types = abi['inputs'].select{|a| a['indexed']}.collect{|a| a['type']} - not_indexed_types = abi['inputs'].select{|a| !a['indexed']}.collect{|a| a['type']} + indexed_types = abi['inputs'].select{|a| a['indexed']}.collect{|a| parse_component_type a } + not_indexed_types = abi['inputs'].select{|a| !a['indexed']}.collect{|a| parse_component_type a } indexed_args = log.indexed_args @@ -73,7 +73,7 @@ def parse_event_args log } elsif !indexed_args.empty? || !log_data.empty? - all_types = abi['inputs'].collect{|a| a['type']} + all_types = abi['inputs'].collect{|a| parse_component_type a } [all_types[0...indexed_args.size], indexed_args].transpose.collect{|arg| decode_typed_data( arg.first, [arg.second].pack('H*') ) } + decode_abi(all_types[indexed_args.size..-1], [log_data].pack('H*') ) diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 3910328..c3dd052 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.17" + VERSION = "0.2.18" end end From 24e20f2e7d40ed41b4560b187a53260e603a6269 Mon Sep 17 00:00:00 2001 From: astudnev Date: Sun, 31 Mar 2019 12:45:23 +0300 Subject: [PATCH 04/36] Structures of tuples --- lib/web3/eth/contract.rb | 4 ++-- lib/web3/eth/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index 519e4d3..0a7f2a6 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -42,8 +42,8 @@ def initialize abi end def parse_component_type argument - if argument['type']=='tuple' - argument['components'] ? "(#{argument['components'].collect{|c| c['type'] }.join(',')})" : '()' + if argument['type']=~/^tuple((\[[0-9]*\])*)/ + argument['components'] ? "(#{argument['components'].collect{|c| parse_component_type c['type'] }.join(',')})#{$1}" : "()#{$1}" else argument['type'] end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index c3dd052..43bbdd7 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.18" + VERSION = "0.2.19" end end From ef34f18162f5eb8528a143f6745d41b8b48f06a8 Mon Sep 17 00:00:00 2001 From: astudnev Date: Sun, 31 Mar 2019 13:25:06 +0300 Subject: [PATCH 05/36] Structures of tuples --- lib/web3/eth/contract.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index 0a7f2a6..4cf68e1 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -43,7 +43,7 @@ def initialize abi def parse_component_type argument if argument['type']=~/^tuple((\[[0-9]*\])*)/ - argument['components'] ? "(#{argument['components'].collect{|c| parse_component_type c['type'] }.join(',')})#{$1}" : "()#{$1}" + argument['components'] ? "(#{argument['components'].collect{|c| parse_component_type c }.join(',')})#{$1}" : "()#{$1}" else argument['type'] end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 43bbdd7..9e1d613 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.19" + VERSION = "0.2.20" end end From 8c0758cc5b33deab46ce8dd238b233c35c985de3 Mon Sep 17 00:00:00 2001 From: astudnev Date: Mon, 1 Apr 2019 12:51:51 +0300 Subject: [PATCH 06/36] array of tuples ABI parse --- lib/web3/eth/abi/abi_coder.rb | 5 +++-- lib/web3/eth/abi/type.rb | 3 +++ lib/web3/eth/version.rb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index 317a39a..0bacace 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -248,7 +248,8 @@ def decode_typed_data type_name, data end def decode_type(type, arg) - if type.kind_of?(Tuple) + return nil if arg.nil? + if type.kind_of?(Tuple) && type.dims.empty? arg ? decode_abi(type.types, arg) : [] elsif %w(string bytes).include?(type.base) && type.sub.empty? l = Utils.big_endian_to_int arg[0,32] @@ -261,7 +262,7 @@ def decode_type(type, arg) if subtype.dynamic? raise DecodingError, "Not enough data for head" unless arg.size >= 32 + 32*l - start_positions = (1..l).map {|i| Utils.big_endian_to_int arg[32*i, 32] } + start_positions = (1..l).map {|i| 32+Utils.big_endian_to_int(arg[32*i, 32]) } start_positions.push arg.size outputs = (0...l).map {|i| arg[start_positions[i]...start_positions[i+1]] } diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index edd3484..6dacd69 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -139,6 +139,9 @@ def size nil end + def subtype + @subtype ||= Tuple.new(types, dims[0...-1]) + end end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 9e1d613..8d924a7 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.20" + VERSION = "0.2.21" end end From 39884761d1bbd6f64c58fac721d7b7c4b85292df Mon Sep 17 00:00:00 2001 From: astudnev Date: Tue, 2 Apr 2019 18:52:50 +0300 Subject: [PATCH 07/36] fixed tuple structures parse --- lib/web3/eth/abi/type.rb | 61 +++++++++++++++++++++++++++++++++++++--- lib/web3/eth/version.rb | 2 +- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index 6dacd69..4baaf84 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -14,7 +14,7 @@ class < Date: Tue, 2 Apr 2019 19:19:42 +0300 Subject: [PATCH 08/36] fixed tuple structures parse --- lib/web3/eth/abi/abi_coder.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index 0bacace..4cb5623 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -248,7 +248,7 @@ def decode_typed_data type_name, data end def decode_type(type, arg) - return nil if arg.nil? + return nil if arg.nil? || arg.empty? if type.kind_of?(Tuple) && type.dims.empty? arg ? decode_abi(type.types, arg) : [] elsif %w(string bytes).include?(type.base) && type.sub.empty? diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 36beed6..d5dfbc6 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.22" + VERSION = "0.2.23" end end From 5724059edbcccb8b59b0dbd5a5c0cd43444e8837 Mon Sep 17 00:00:00 2001 From: astudnev Date: Tue, 2 Apr 2019 20:17:53 +0300 Subject: [PATCH 09/36] fixed tuple structures parse --- lib/web3/eth/abi/abi_coder.rb | 4 +++- lib/web3/eth/version.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index 4cb5623..c697b81 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -235,7 +235,9 @@ def decode_abi(types, data) parsed_types.each_with_index do |t, i| if t.dynamic? offset, next_offset = start_positions[i, 2] - outputs[i] = data[offset...next_offset] + if offset<=data.size && next_offset<=data.size + outputs[i] = data[offset...next_offset] + end end end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index d5dfbc6..eed91d2 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.23" + VERSION = "0.2.24" end end From 2122429cd2b43690dec514372ef258afc0b16026 Mon Sep 17 00:00:00 2001 From: astudnev Date: Wed, 29 May 2019 14:41:52 +0300 Subject: [PATCH 10/36] Constructor arguments parsed in trial cycle if can not detect automatically --- lib/web3/eth/abi/abi_coder.rb | 25 ++++++++++++++++-- lib/web3/eth/contract.rb | 49 +++++++++++++++++++++++++++++++++-- lib/web3/eth/transaction.rb | 14 +--------- lib/web3/eth/version.rb | 2 +- 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index c697b81..0c28b73 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -192,10 +192,15 @@ def encode_primitive_type(type, arg) end end + + def min_data_size types + types.size*32 + end + ## # Decodes multiple arguments using the head/tail mechanism. # - def decode_abi(types, data) + def decode_abi types, data, raise_errors = false parsed_types = types.map {|t| Type.parse(t) } outputs = [nil] * types.size @@ -207,8 +212,17 @@ def decode_abi(types, data) # If a type is static, grab the data directly, otherwise record its # start position if t.dynamic? + + if raise_errors && pos>data.size-1 + raise DecodingError, "Position out of bounds #{pos}>#{data.size-1}" + end + start_positions[i] = Utils.big_endian_to_int(data[pos, 32]) + if raise_errors && start_positions[i]>data.size-1 + raise DecodingError, "Start position out of bounds #{start_positions[i]}>#{data.size-1}" + end + j = i - 1 while j >= 0 && start_positions[j].nil? start_positions[j] = start_positions[i] @@ -230,7 +244,10 @@ def decode_abi(types, data) j -= 1 end -# raise DecodingError, "Not enough data for head" unless pos <= data.size + if raise_errors && pos > data.size + raise DecodingError, "Not enough data for head" + end + parsed_types.each_with_index do |t, i| if t.dynamic? @@ -241,6 +258,10 @@ def decode_abi(types, data) end end + if raise_errors && outputs.include?(nil) + raise DecodingError, "Not all data can be parsed" + end + parsed_types.zip(outputs).map {|(type, out)| decode_type(type, out) } end alias :decode :decode_abi diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index 4cf68e1..554432e 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -103,6 +103,52 @@ def do_call web3_rpc, contract_address, args end + class ContractConstructor < ContractMethod + + def initialize abi + super abi + end + + def parse_method_args transaction + return [] if input_types.empty? + + input = transaction.input + + d = fetch_constructor_data input + result = (d && !d.empty? && try_parse(d)) + + unless result + start = input.length-1-min_data_size(input_types) + while start>=0 && !result + result = try_parse input, start + start -= 1 + end + end + + result + end + + private + + CONSTRUCTOR_SEQ = /a165627a7a72305820\w{64}0029(\w*)$/ + def fetch_constructor_data input + data = input[CONSTRUCTOR_SEQ,1] + while data && (d = data[CONSTRUCTOR_SEQ,1]) + data = d + end + data + end + + def try_parse input, start = 0 + d = start==0 ? input : input.slice(start, input.length-start-1) + decode_abi input_types, [d].pack('H*'), true + rescue Exception => err + nil + end + + end + + attr_reader :web3_rpc, :abi, :functions, :events, :constructor, :functions_by_hash, :events_by_hash def initialize abi, web_rpc = nil @@ -168,8 +214,7 @@ def parse_abi abi @events[method.name] = method @events_by_hash[method.signature_hash] = method when 'constructor' - method = ContractMethod.new(a) - @constructor = method + @constructor = ContractConstructor.new(a) end } end diff --git a/lib/web3/eth/transaction.rb b/lib/web3/eth/transaction.rb index d648fbe..9201c73 100644 --- a/lib/web3/eth/transaction.rb +++ b/lib/web3/eth/transaction.rb @@ -26,9 +26,7 @@ def method_hash # suffix # 0xa1 0x65 'b' 'z' 'z' 'r' '0' 0x58 0x20 <32 bytes swarm hash> 0x00 0x29 # look http://solidity.readthedocs.io/en/latest/metadata.html for details def call_input_data - if raw_data['creates'] && input - fetch_constructor_data input - elsif input && input.length>10 + if input && input.length>10 input[10..input.length] else [] @@ -57,16 +55,6 @@ def gasPrice_eth wei_to_ether from_hex gasPrice end - private - - CONSTRUCTOR_SEQ = /a165627a7a72305820\w{64}0029(\w*)$/ - def fetch_constructor_data input - data = input[CONSTRUCTOR_SEQ,1] - while data && (d = data[CONSTRUCTOR_SEQ,1]) - data = d - end - data - end end end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index eed91d2..573ad88 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.24" + VERSION = "0.2.25" end end From e3419c5c2bf5342c9c18b257d73265feac293555 Mon Sep 17 00:00:00 2001 From: astudnev Date: Wed, 3 Jul 2019 16:59:00 +0300 Subject: [PATCH 11/36] Fix for decoding wrong data set --- lib/web3/eth/abi/abi_coder.rb | 1 + lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index 0c28b73..bb419b8 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -280,6 +280,7 @@ def decode_type(type, arg) data[0, l] elsif type.dynamic? l = Utils.big_endian_to_int arg[0,32] + raise DecodingError, "Too long length: #{l}" if l>1000 subtype = type.subtype if subtype.dynamic? diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 573ad88..aa4ff9b 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.25" + VERSION = "0.2.26" end end From 85ac968f16859617d9798784b94aa17c3f61e7f0 Mon Sep 17 00:00:00 2001 From: astudnev Date: Fri, 23 Aug 2019 22:43:17 +0300 Subject: [PATCH 12/36] fixes for TRON compatibility --- lib/web3/eth/contract.rb | 6 +++--- lib/web3/eth/utility.rb | 1 + lib/web3/eth/version.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index 554432e..fe3cf37 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -35,10 +35,10 @@ def initialize abi @abi = abi @name = abi['name'] @constant = !!abi['constant'] - @input_types = abi['inputs'].map{|a| parse_component_type a } + @input_types = abi['inputs'] ? abi['inputs'].map{|a| parse_component_type a } : [] @output_types = abi['outputs'].map{|a| parse_component_type a } if abi['outputs'] @signature = Abi::Utils.function_signature @name, @input_types - @signature_hash = Abi::Utils.signature_hash @signature, (abi['type']=='event' ? 64 : 8) + @signature_hash = Abi::Utils.signature_hash @signature, (abi['type'].try(:downcase)=='event' ? 64 : 8) end def parse_component_type argument @@ -204,7 +204,7 @@ def parse_abi abi abi.each{|a| - case a['type'] + case a['type'].try(:downcase) when 'function' method = ContractMethod.new(a) @functions[method.name] = method diff --git a/lib/web3/eth/utility.rb b/lib/web3/eth/utility.rb index 500699c..08decf0 100644 --- a/lib/web3/eth/utility.rb +++ b/lib/web3/eth/utility.rb @@ -16,6 +16,7 @@ def from_hex h end def remove_0x_head(s) + return s if !s || s.length<2 s[0,2] == '0x' ? s[2..-1] : s end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index aa4ff9b..e7a16e4 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.26" + VERSION = "0.2.27" end end From d3fbfb36cb3b03d5cef25175b07525f3b5b60b09 Mon Sep 17 00:00:00 2001 From: astudnev Date: Sun, 25 Aug 2019 22:44:07 +0300 Subject: [PATCH 13/36] string[32] support --- lib/web3/eth/abi/type.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index 4baaf84..eac8f7f 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -25,9 +25,7 @@ def parse(type) case base when '' return parse 'address' - when 'string' - raise ParseError, "String type must have no suffix or numerical suffix" unless sub.empty? - when 'bytes' + when 'bytes', 'string' raise ParseError, "Maximum 32 bytes for fixed-length string or bytes" unless sub.empty? || sub.to_i <= 32 when 'uint', 'int' raise ParseError, "Integer type must have numerical suffix" unless sub =~ /\A[0-9]+\z/ From fdc9f47a48f3287c698041db8e383460be5d5b82 Mon Sep 17 00:00:00 2001 From: astudnev Date: Sun, 25 Aug 2019 23:27:20 +0300 Subject: [PATCH 14/36] string[32] support --- lib/web3/eth/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index e7a16e4..868590b 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.27" + VERSION = "0.2.28" end end From a22a93ddfb17626fbaf3c5dd896017b2b5646f2d Mon Sep 17 00:00:00 2001 From: astudnev Date: Tue, 27 Aug 2019 15:16:56 +0300 Subject: [PATCH 15/36] trc token type --- lib/web3/eth/abi/type.rb | 2 ++ lib/web3/eth/version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index eac8f7f..43200af 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -13,6 +13,8 @@ class < Date: Wed, 28 Aug 2019 17:26:14 +0300 Subject: [PATCH 16/36] fix parser for dynamic types --- lib/web3/eth/abi/abi_coder.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index bb419b8..5327e3f 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -280,7 +280,7 @@ def decode_type(type, arg) data[0, l] elsif type.dynamic? l = Utils.big_endian_to_int arg[0,32] - raise DecodingError, "Too long length: #{l}" if l>1000 + raise DecodingError, "Too long length: #{l}" if l>100000 subtype = type.subtype if subtype.dynamic? diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 905d662..4fad251 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.29" + VERSION = "0.2.30" end end From 84715b35b71f687fb7a5a3f8698cab0b9cee2bb5 Mon Sep 17 00:00:00 2001 From: astudnev Date: Wed, 18 Sep 2019 10:06:14 +0300 Subject: [PATCH 17/36] fix parser for fixed types --- lib/web3/eth/abi/type.rb | 3 ++- lib/web3/eth/version.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index 43200af..00571aa 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -42,7 +42,8 @@ def parse(type) total = high + low raise ParseError, "Fixed size out of bounds (max 32 bytes)" unless total >= 8 && total <= 256 - raise ParseError, "Fixed high/low sizes must be multiples of 8" unless high % 8 == 0 && low % 8 == 0 + raise ParseError, "Fixed high size must be multiple of 8" unless high % 8 == 0 + raise ParseError, "Low sizes must be 0 to 80" unless low>0 && low<=80 when 'hash' raise ParseError, "Hash type must have numerical suffix" unless sub =~ /\A[0-9]+\z/ when 'address' diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 4fad251..37a6033 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.30" + VERSION = "0.2.31" end end From fe63311c6112742806f58aa2d9b30c92d8e26618 Mon Sep 17 00:00:00 2001 From: astudnev Date: Thu, 26 Mar 2020 15:37:03 +0300 Subject: [PATCH 18/36] debug module added --- lib/web3/eth.rb | 2 + lib/web3/eth/debug/debug_module.rb | 36 ++++++++ lib/web3/eth/debug/transaction_call_trace.rb | 86 ++++++++++++++++++++ lib/web3/eth/rpc.rb | 5 ++ lib/web3/eth/utility.rb | 2 +- lib/web3/eth/version.rb | 2 +- 6 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 lib/web3/eth/debug/debug_module.rb create mode 100644 lib/web3/eth/debug/transaction_call_trace.rb diff --git a/lib/web3/eth.rb b/lib/web3/eth.rb index f98d545..e287898 100644 --- a/lib/web3/eth.rb +++ b/lib/web3/eth.rb @@ -8,6 +8,8 @@ require "web3/eth/log" require "web3/eth/transaction_receipt" require "web3/eth/eth_module" +require "web3/eth/debug/debug_module" +require "web3/eth/debug/transaction_call_trace" require "web3/eth/trace_module" require "web3/eth/etherscan" require "web3/eth/rpc" diff --git a/lib/web3/eth/debug/debug_module.rb b/lib/web3/eth/debug/debug_module.rb new file mode 100644 index 0000000..6e43bff --- /dev/null +++ b/lib/web3/eth/debug/debug_module.rb @@ -0,0 +1,36 @@ +module Web3::Eth::Debug + + class DebugModule + + include Web3::Eth::Utility + + PREFIX = 'debug_' + + def initialize web3_rpc + @web3_rpc = web3_rpc + end + + def traceTransaction hash, tracer = 'callTracer', convert_to_object = true + raw = @web3_rpc.request("#{PREFIX}#{__method__}", [hash, {tracer: tracer}]) + convert_to_object ? TransactionCallTrace.new(raw) : raw + end + + def traceBlockByNumber number, tracer = 'callTracer', convert_to_object = true + raw = @web3_rpc.request("#{PREFIX}#{__method__}", [hex(number), {tracer: tracer}]) + convert_to_object ? raw.map{|r| TransactionCallTrace.new(r['result'])} : raw + end + + def traceBlockByHash hash, tracer = 'callTracer', convert_to_object = true + raw = @web3_rpc.request("#{PREFIX}#{__method__}", [hash, {tracer: tracer}]) + convert_to_object ? raw.map{|r| TransactionCallTrace.new(r['result'])} : raw + end + + + def method_missing m, *args + @web3_rpc.request "#{PREFIX}#{m}", args[0] + end + + + end + +end diff --git a/lib/web3/eth/debug/transaction_call_trace.rb b/lib/web3/eth/debug/transaction_call_trace.rb new file mode 100644 index 0000000..0c3fc31 --- /dev/null +++ b/lib/web3/eth/debug/transaction_call_trace.rb @@ -0,0 +1,86 @@ +module Web3::Eth::Debug + + class TransactionCallTrace + + include Web3::Eth::Utility + + attr_reader :raw_data, :calls, :traceAddress + def initialize raw, traceAddress = [] + @raw_data = raw + @traceAddress = traceAddress + @calls = raw['calls'] ? raw['calls'].each_with_index.map{|c,i| TransactionCallTrace.new c, (traceAddress + [i]) } : [] + end + + # CALL STATICCALL DELEGATECALL CREATE SELFDESTRUCT + def type + raw_data['type'] + end + + def creates + (type=='CREATE' || type=='CREATE2') ? to : nil + end + + def suicide? + type=='SELFDESTRUCT' + end + + def from + raw_data['from'] + end + + def to + raw_data['to'] + end + + def value_wei + from_hex raw_data['value'] + end + + def value_eth + wei_to_ether value_wei + end + + def gas + from_hex raw_data['gas'] + end + + def gas_used + from_hex raw_data['gasUsed'] + end + + def input + raw_data['input'] + end + + def output + raw_data['output'] + end + + def time + raw_data['time'] + end + + def error + raw_data['error'] + end + + def success? + !raw_data['error'] + end + + # suffix # 0xa1 0x65 'b' 'z' 'z' 'r' '0' 0x58 0x20 <32 bytes swarm hash> 0x00 0x29 + # look http://solidity.readthedocs.io/en/latest/metadata.html for details + def call_input_data + if creates && input + input[/a165627a7a72305820\w{64}0029(\w*)/,1] + elsif input && input.length>10 + input[10..input.length] + else + [] + end + end + + end + + +end diff --git a/lib/web3/eth/rpc.rb b/lib/web3/eth/rpc.rb index 095dcc2..e661b5e 100644 --- a/lib/web3/eth/rpc.rb +++ b/lib/web3/eth/rpc.rb @@ -32,6 +32,11 @@ def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_ end + def debug + Debug::DebugModule.new self + end + + def request method, params = nil diff --git a/lib/web3/eth/utility.rb b/lib/web3/eth/utility.rb index 08decf0..8fc8c50 100644 --- a/lib/web3/eth/utility.rb +++ b/lib/web3/eth/utility.rb @@ -12,7 +12,7 @@ def wei_to_ether(wei) end def from_hex h - h.to_i 16 + h.nil? ? 0 : h.to_i(16) end def remove_0x_head(s) diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 37a6033..f6511e7 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.31" + VERSION = "0.2.32" end end From 5c8f85a216cc7c1594fced805e5035f6f7f63ffc Mon Sep 17 00:00:00 2001 From: astudnev Date: Thu, 26 Mar 2020 18:01:16 +0300 Subject: [PATCH 19/36] bulk simulation for geth method hash --- lib/web3/eth/debug/transaction_call_trace.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/web3/eth/debug/transaction_call_trace.rb b/lib/web3/eth/debug/transaction_call_trace.rb index 0c3fc31..8d2da3a 100644 --- a/lib/web3/eth/debug/transaction_call_trace.rb +++ b/lib/web3/eth/debug/transaction_call_trace.rb @@ -20,6 +20,14 @@ def creates (type=='CREATE' || type=='CREATE2') ? to : nil end + def method_hash + if input && input.length>=10 + input[2...10] + else + nil + end + end + def suicide? type=='SELFDESTRUCT' end From d7c586bd4e52a8c5ca4014a3e535ca73241567a5 Mon Sep 17 00:00:00 2001 From: astudnev Date: Sat, 28 Mar 2020 14:06:28 +0300 Subject: [PATCH 20/36] added properties for transaction --- lib/web3/eth/block.rb | 24 ++++++++++++++++++++++++ lib/web3/eth/transaction.rb | 9 +++++++++ lib/web3/eth/transaction_receipt.rb | 5 ++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/web3/eth/block.rb b/lib/web3/eth/block.rb index 17dc3c6..074b89e 100644 --- a/lib/web3/eth/block.rb +++ b/lib/web3/eth/block.rb @@ -27,6 +27,30 @@ def block_number from_hex number end + def block_difficulty + from_hex difficulty + end + + def block_gasLimit + from_hex gasLimit + end + + def block_gasUsed + from_hex gasUsed + end + + def block_nonce + from_hex nonce + end + + def block_size + from_hex size + end + + def block_totalDifficulty + from_hex totalDifficulty + end + end end diff --git a/lib/web3/eth/transaction.rb b/lib/web3/eth/transaction.rb index 9201c73..4586d61 100644 --- a/lib/web3/eth/transaction.rb +++ b/lib/web3/eth/transaction.rb @@ -55,6 +55,15 @@ def gasPrice_eth wei_to_ether from_hex gasPrice end + def gasPrice_weth + from_hex gasPrice + end + + + def transaction_nonce + from_hex nonce + end + end end diff --git a/lib/web3/eth/transaction_receipt.rb b/lib/web3/eth/transaction_receipt.rb index 0ac8a09..779ba41 100644 --- a/lib/web3/eth/transaction_receipt.rb +++ b/lib/web3/eth/transaction_receipt.rb @@ -31,11 +31,14 @@ def gas_used from_hex gasUsed end - def cumulative_gas_used from_hex cumulativeGasUsed end + def transaction_index + from_hex transactionIndex + end + end end end \ No newline at end of file From fb2f077b19a2dc0a7a66669228f7fd7a856cb2b3 Mon Sep 17 00:00:00 2001 From: astudnev Date: Sat, 28 Mar 2020 22:05:26 +0300 Subject: [PATCH 21/36] added properties for transaction --- lib/web3/eth/debug/transaction_call_trace.rb | 7 +++++++ lib/web3/eth/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/web3/eth/debug/transaction_call_trace.rb b/lib/web3/eth/debug/transaction_call_trace.rb index 8d2da3a..5feaaba 100644 --- a/lib/web3/eth/debug/transaction_call_trace.rb +++ b/lib/web3/eth/debug/transaction_call_trace.rb @@ -16,6 +16,13 @@ def type raw_data['type'] end + def action + { + 'callType' => type.downcase, + 'address' => raw_data['to'] + } + end + def creates (type=='CREATE' || type=='CREATE2') ? to : nil end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index f6511e7..a4adae5 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.32" + VERSION = "0.2.33" end end From f50f170bc3098ee21cbd32ee0761e47d6ddbe878 Mon Sep 17 00:00:00 2001 From: astudnev Date: Fri, 24 Apr 2020 12:05:04 +0300 Subject: [PATCH 22/36] Celo blockchain does not have difficulty on web3 --- lib/web3/eth/block.rb | 12 ++++++------ lib/web3/eth/version.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/web3/eth/block.rb b/lib/web3/eth/block.rb index 074b89e..7a15dd0 100644 --- a/lib/web3/eth/block.rb +++ b/lib/web3/eth/block.rb @@ -28,27 +28,27 @@ def block_number end def block_difficulty - from_hex difficulty + self.respond_to?(:difficulty) ? from_hex(difficulty) : 0 end def block_gasLimit - from_hex gasLimit + self.respond_to?(:gasLimit) ? from_hex(gasLimit) : 0 end def block_gasUsed - from_hex gasUsed + self.respond_to?(:gasUsed) ? from_hex(gasUsed) : 0 end def block_nonce - from_hex nonce + self.respond_to?(:nonce) ? from_hex(nonce) : 0 end def block_size - from_hex size + self.respond_to?(:size) ? from_hex(size) : 0 end def block_totalDifficulty - from_hex totalDifficulty + self.respond_to?(:totalDifficulty) ? from_hex(totalDifficulty) : 0 end end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index a4adae5..b9f0a66 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.33" + VERSION = "0.2.34" end end From 9214ee918a34e1d6713cd64251e2436229eb942c Mon Sep 17 00:00:00 2001 From: astudnev Date: Fri, 24 Apr 2020 18:57:49 +0300 Subject: [PATCH 23/36] suicide address field --- lib/web3/eth/debug/transaction_call_trace.rb | 13 +++++++++---- lib/web3/eth/version.rb | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/web3/eth/debug/transaction_call_trace.rb b/lib/web3/eth/debug/transaction_call_trace.rb index 5feaaba..5e60b10 100644 --- a/lib/web3/eth/debug/transaction_call_trace.rb +++ b/lib/web3/eth/debug/transaction_call_trace.rb @@ -4,11 +4,12 @@ class TransactionCallTrace include Web3::Eth::Utility - attr_reader :raw_data, :calls, :traceAddress - def initialize raw, traceAddress = [] + attr_reader :raw_data, :calls, :traceAddress, :parent + def initialize raw, traceAddress = [], parent = nil @raw_data = raw @traceAddress = traceAddress - @calls = raw['calls'] ? raw['calls'].each_with_index.map{|c,i| TransactionCallTrace.new c, (traceAddress + [i]) } : [] + @parent = parent + @calls = raw['calls'] ? raw['calls'].each_with_index.map{|c,i| TransactionCallTrace.new c, (traceAddress + [i]), parent } : [] end # CALL STATICCALL DELEGATECALL CREATE SELFDESTRUCT @@ -19,10 +20,14 @@ def type def action { 'callType' => type.downcase, - 'address' => raw_data['to'] + 'address' => ( suicide? ? parent.smart_contract : raw_data['to']) } end + def smart_contract + ['DELEGATECALL','CALL'].include?(type) ? to : from + end + def creates (type=='CREATE' || type=='CREATE2') ? to : nil end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index b9f0a66..64b0179 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.34" + VERSION = "0.2.35" end end From 1a67dbfa53522306751127ea51a74df57ff7d2a1 Mon Sep 17 00:00:00 2001 From: astudnev Date: Fri, 24 Apr 2020 19:02:13 +0300 Subject: [PATCH 24/36] suicide address field --- lib/web3/eth/debug/transaction_call_trace.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/debug/transaction_call_trace.rb b/lib/web3/eth/debug/transaction_call_trace.rb index 5e60b10..3f9150c 100644 --- a/lib/web3/eth/debug/transaction_call_trace.rb +++ b/lib/web3/eth/debug/transaction_call_trace.rb @@ -9,7 +9,7 @@ def initialize raw, traceAddress = [], parent = nil @raw_data = raw @traceAddress = traceAddress @parent = parent - @calls = raw['calls'] ? raw['calls'].each_with_index.map{|c,i| TransactionCallTrace.new c, (traceAddress + [i]), parent } : [] + @calls = raw['calls'] ? raw['calls'].each_with_index.map{|c,i| TransactionCallTrace.new c, (traceAddress + [i]), self } : [] end # CALL STATICCALL DELEGATECALL CREATE SELFDESTRUCT diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 64b0179..7031648 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.35" + VERSION = "0.2.36" end end From b98be95bdd8d05b768b2a597faeaa921a52d437b Mon Sep 17 00:00:00 2001 From: astudnev Date: Fri, 24 Apr 2020 19:06:25 +0300 Subject: [PATCH 25/36] suicide address field --- lib/web3/eth/debug/transaction_call_trace.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/debug/transaction_call_trace.rb b/lib/web3/eth/debug/transaction_call_trace.rb index 3f9150c..9f5f2ba 100644 --- a/lib/web3/eth/debug/transaction_call_trace.rb +++ b/lib/web3/eth/debug/transaction_call_trace.rb @@ -25,7 +25,7 @@ def action end def smart_contract - ['DELEGATECALL','CALL'].include?(type) ? to : from + ['STATICCALL','CALL'].include?(type) ? to : from end def creates diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 7031648..836d2b8 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.36" + VERSION = "0.2.37" end end From 7cbbed295ab8de20edfa7ca1e5b935a9b035122a Mon Sep 17 00:00:00 2001 From: astudnev Date: Mon, 27 Apr 2020 22:08:36 +0300 Subject: [PATCH 26/36] Added timeout for debug_module tracing --- lib/web3/eth/debug/debug_module.rb | 5 ++++- lib/web3/eth/rpc.rb | 2 +- lib/web3/eth/version.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/web3/eth/debug/debug_module.rb b/lib/web3/eth/debug/debug_module.rb index 6e43bff..460dbc6 100644 --- a/lib/web3/eth/debug/debug_module.rb +++ b/lib/web3/eth/debug/debug_module.rb @@ -16,7 +16,10 @@ def traceTransaction hash, tracer = 'callTracer', convert_to_object = true end def traceBlockByNumber number, tracer = 'callTracer', convert_to_object = true - raw = @web3_rpc.request("#{PREFIX}#{__method__}", [hex(number), {tracer: tracer}]) + timeout = @web3_rpc.connect_options[:read_timeout] || 120 + raw = @web3_rpc.request("#{PREFIX}#{__method__}", [hex(number), {tracer: tracer, + timeout: "#{timeout}s"}]) + raise raw.first['error'] if (raw.first && raw.first['error']) convert_to_object ? raw.map{|r| TransactionCallTrace.new(r['result'])} : raw end diff --git a/lib/web3/eth/rpc.rb b/lib/web3/eth/rpc.rb index e661b5e..180c516 100644 --- a/lib/web3/eth/rpc.rb +++ b/lib/web3/eth/rpc.rb @@ -17,7 +17,7 @@ class Rpc DEFAULT_HOST = 'localhost' DEFAULT_PORT = 8545 - attr_reader :eth, :trace + attr_reader :eth, :trace, :connect_options def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_CONNECT_OPTIONS diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 836d2b8..631fb7b 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.37" + VERSION = "0.2.38" end end From c645b5f16bc750bd9c6b234d970cb7d40a883b45 Mon Sep 17 00:00:00 2001 From: astudnev Date: Mon, 1 Jun 2020 14:18:58 +0300 Subject: [PATCH 27/36] tracesByBlockNumber added --- lib/web3/eth/trace_module.rb | 6 ++++++ lib/web3/eth/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/web3/eth/trace_module.rb b/lib/web3/eth/trace_module.rb index 19ac43f..8060206 100644 --- a/lib/web3/eth/trace_module.rb +++ b/lib/web3/eth/trace_module.rb @@ -21,6 +21,12 @@ def internalCallsByHash tx_hash } end + def tracesByBlockNumber block + @web3_rpc.request("#{PREFIX}block", [hex(block)]).collect{|t| + CallTrace.new t + } + end + end end end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 631fb7b..9e799a5 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.38" + VERSION = "0.2.39" end end From 70144cf57da51b1546c954df8255822778dcd9af Mon Sep 17 00:00:00 2001 From: astudnev Date: Mon, 1 Jun 2020 16:41:29 +0300 Subject: [PATCH 28/36] parity_module.rb module added --- lib/web3/eth.rb | 1 + lib/web3/eth/parity_module.rb | 26 ++++++++++++++++++++++++++ lib/web3/eth/rpc.rb | 13 +++++++++---- lib/web3/eth/version.rb | 2 +- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 lib/web3/eth/parity_module.rb diff --git a/lib/web3/eth.rb b/lib/web3/eth.rb index e287898..f3e11e3 100644 --- a/lib/web3/eth.rb +++ b/lib/web3/eth.rb @@ -11,5 +11,6 @@ require "web3/eth/debug/debug_module" require "web3/eth/debug/transaction_call_trace" require "web3/eth/trace_module" +require "web3/eth/parity_module" require "web3/eth/etherscan" require "web3/eth/rpc" diff --git a/lib/web3/eth/parity_module.rb b/lib/web3/eth/parity_module.rb new file mode 100644 index 0000000..b34cb49 --- /dev/null +++ b/lib/web3/eth/parity_module.rb @@ -0,0 +1,26 @@ +module Web3 + module Eth + + class ParityModule + + include Web3::Eth::Utility + + PREFIX = 'parity_' + + def initialize web3_rpc + @web3_rpc = web3_rpc + end + + def method_missing m, *args + @web3_rpc.request "#{PREFIX}#{m}", args[0] + end + + def getBlockReceiptsByBlockNumber block + @web3_rpc.request("#{PREFIX}getBlockReceipts", [hex(block)]).collect{|tr| + TransactionReceipt.new tr + } + end + + end + end +end diff --git a/lib/web3/eth/rpc.rb b/lib/web3/eth/rpc.rb index 180c516..cc3420c 100644 --- a/lib/web3/eth/rpc.rb +++ b/lib/web3/eth/rpc.rb @@ -17,7 +17,7 @@ class Rpc DEFAULT_HOST = 'localhost' DEFAULT_PORT = 8545 - attr_reader :eth, :trace, :connect_options + attr_reader :eth, :connect_options def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_CONNECT_OPTIONS @@ -27,15 +27,20 @@ def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_ @connect_options = connect_options @eth = EthModule.new self - @trace = TraceModule.new self end + def trace + @trace ||= TraceModule.new(self) + end - def debug - Debug::DebugModule.new self + def parity + @parity ||= ParityModule.new(self) end + def debug + @debug ||= Debug::DebugModule.new(self) + end def request method, params = nil diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 9e799a5..07965e3 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.39" + VERSION = "0.2.40" end end From 9af1287fe013d5924da3a3b64873ea78d2849ca3 Mon Sep 17 00:00:00 2001 From: astudnev Date: Tue, 2 Jun 2020 20:39:12 +0300 Subject: [PATCH 29/36] web3.eth call used instead of direct name --- lib/web3/eth/contract.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index fe3cf37..6a18e6c 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -92,7 +92,7 @@ def parse_method_args transaction def do_call web3_rpc, contract_address, args data = '0x' + signature_hash + encode_hex(encode_abi(input_types, args) ) - response = web3_rpc.request "eth_call", [{ to: contract_address, data: data}, 'latest'] + response = web3_rpc.eth.call [{ to: contract_address, data: data}, 'latest'] string_data = [remove_0x_head(response)].pack('H*') return nil if string_data.empty? diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 07965e3..aa216b8 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.40" + VERSION = "0.2.41" end end From 6aae6f7b0341a93079d60a9b1e45e6d7255752e1 Mon Sep 17 00:00:00 2001 From: astudnev Date: Thu, 18 Jun 2020 19:14:40 +0300 Subject: [PATCH 30/36] JSON level up to 1500 --- lib/web3/eth/rpc.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/rpc.rb b/lib/web3/eth/rpc.rb index cc3420c..8e50da1 100644 --- a/lib/web3/eth/rpc.rb +++ b/lib/web3/eth/rpc.rb @@ -53,7 +53,7 @@ def request method, params = nil raise "Error code #{response.code} on request #{@uri.to_s} #{request.body}" unless response.kind_of? Net::HTTPOK - body = JSON.parse(response.body) + body = JSON.parse(response.body, max_nesting: 1500) if body['result'] body['result'] diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index aa216b8..85f32a6 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.41" + VERSION = "0.2.42" end end From e9ec838c80162857e0fbaf2658274fd88732b428 Mon Sep 17 00:00:00 2001 From: astudnev Date: Thu, 23 Jul 2020 15:19:59 +0300 Subject: [PATCH 31/36] Padding fixed size data with zeros added --- lib/web3/eth/abi/abi_coder.rb | 14 +++++++++++++- lib/web3/eth/version.rb | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/abi/abi_coder.rb b/lib/web3/eth/abi/abi_coder.rb index 5327e3f..7b93213 100644 --- a/lib/web3/eth/abi/abi_coder.rb +++ b/lib/web3/eth/abi/abi_coder.rb @@ -231,7 +231,7 @@ def decode_abi types, data, raise_errors = false pos += 32 else - outputs[i] = data[pos, t.size] + outputs[i] = zero_padding data, pos, t.size, start_positions pos += t.size end end @@ -266,6 +266,18 @@ def decode_abi types, data, raise_errors = false end alias :decode :decode_abi + def zero_padding data, pos, count, start_positions + if pos >= data.size + start_positions[start_positions.size-1] += count + "\x00"*count + elsif pos + count > data.size + start_positions[start_positions.size-1] += ( count - (data.size-pos)) + data[pos,data.size-pos] + "\x00"*( count - (data.size-pos)) + else + data[pos, count] + end + end + def decode_typed_data type_name, data decode_primitive_type Type.parse(type_name), data end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 85f32a6..5988bb4 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.42" + VERSION = "0.2.43" end end From 7d3eec1ab574b878464fc99d12e00ddb9155a302 Mon Sep 17 00:00:00 2001 From: astudnev Date: Tue, 18 Aug 2020 21:11:25 +0300 Subject: [PATCH 32/36] Fix utiliity --- lib/web3/eth/utility.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web3/eth/utility.rb b/lib/web3/eth/utility.rb index 8fc8c50..1354a52 100644 --- a/lib/web3/eth/utility.rb +++ b/lib/web3/eth/utility.rb @@ -12,7 +12,7 @@ def wei_to_ether(wei) end def from_hex h - h.nil? ? 0 : h.to_i(16) + h.nil? ? 0 : (h.kind_of?(String) ? h.to_i(16) : h) end def remove_0x_head(s) From bf7b605fd4cb9dd8302af936a7aba48b18c2c71d Mon Sep 17 00:00:00 2001 From: astudnev Date: Tue, 18 Aug 2020 21:11:41 +0300 Subject: [PATCH 33/36] Fix utiliity --- lib/web3/eth/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 5988bb4..80eedc1 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.43" + VERSION = "0.2.44" end end From 4318aacd40ca2c9ca3d14537e0bc75df0bb2a13e Mon Sep 17 00:00:00 2001 From: astudnev Date: Fri, 28 Aug 2020 18:25:35 +0300 Subject: [PATCH 34/36] Fix contsnat for views --- lib/web3/eth/contract.rb | 2 +- lib/web3/eth/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/contract.rb b/lib/web3/eth/contract.rb index 6a18e6c..9ed4082 100644 --- a/lib/web3/eth/contract.rb +++ b/lib/web3/eth/contract.rb @@ -34,7 +34,7 @@ class ContractMethod def initialize abi @abi = abi @name = abi['name'] - @constant = !!abi['constant'] + @constant = !!abi['constant'] || abi['stateMutability']=='view' @input_types = abi['inputs'] ? abi['inputs'].map{|a| parse_component_type a } : [] @output_types = abi['outputs'].map{|a| parse_component_type a } if abi['outputs'] @signature = Abi::Utils.function_signature @name, @input_types diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 80eedc1..8c4a936 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.44" + VERSION = "0.2.45" end end From a631f0d3f3d62dbd622a8f9f54708a2ebe4d6f90 Mon Sep 17 00:00:00 2001 From: astudnev Date: Mon, 7 Dec 2020 13:48:58 +0300 Subject: [PATCH 35/36] Fixed tuple array parse --- lib/web3/eth/abi/type.rb | 4 ++-- lib/web3/eth/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/web3/eth/abi/type.rb b/lib/web3/eth/abi/type.rb index 00571aa..e29fecd 100644 --- a/lib/web3/eth/abi/type.rb +++ b/lib/web3/eth/abi/type.rb @@ -152,13 +152,13 @@ def self.parse types, dims end collected << current unless current.empty? - Tuple.new collected, dims + Tuple.new collected, dims.map {|x| x[1...-1].to_i} end attr_reader :types, :parsed_types def initialize types, dims - super('tuple', '', dims.map {|x| x[1...-1].to_i}) + super('tuple', '', dims) @types = types @parsed_types = types.map{|t| Type.parse t} end diff --git a/lib/web3/eth/version.rb b/lib/web3/eth/version.rb index 8c4a936..a0ddfab 100644 --- a/lib/web3/eth/version.rb +++ b/lib/web3/eth/version.rb @@ -1,5 +1,5 @@ module Web3 module Eth - VERSION = "0.2.45" + VERSION = "0.2.46" end end From 672f94081a70f3ece3d9b77d144364a51e88ffbc Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 5 Apr 2021 13:29:49 +0200 Subject: [PATCH 36/36] Fix exception when etherscan responds no status --- lib/web3/eth/etherscan.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web3/eth/etherscan.rb b/lib/web3/eth/etherscan.rb index eea92f7..385ab1d 100644 --- a/lib/web3/eth/etherscan.rb +++ b/lib/web3/eth/etherscan.rb @@ -58,7 +58,7 @@ def request api_module, action, args = {} json = JSON.parse(response.body) - raise "Response #{json['message']} on request #{uri.to_s}" unless json['status']=='1' + raise "Response #{json['message']} on request #{uri.to_s}" if json['status'] && json['status']!='1' json['result'] @@ -68,4 +68,4 @@ def request api_module, action, args = {} end end -end \ No newline at end of file +end