Skip to content
Open
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
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*_test.rb']
end
desc "Run tests"
10 changes: 7 additions & 3 deletions lib/web3/eth/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize abi
@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'].try(:downcase)=='event' ? 64 : 8)
@signature_hash = Abi::Utils.signature_hash @signature, (abi['type']&.downcase=='event' ? 64 : 8)
end

def parse_component_type argument
Expand Down Expand Up @@ -92,7 +92,11 @@ 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.eth.call [{ to: contract_address, data: data}, 'latest']
block = web3_rpc.block
if block.is_a?(Numeric)
block = "0x#{block.to_s(16)}"
end
response = web3_rpc.eth.call [{ to: contract_address, data: data}, block]

string_data = [remove_0x_head(response)].pack('H*')
return nil if string_data.empty?
Expand Down Expand Up @@ -204,7 +208,7 @@ def parse_abi abi

abi.each{|a|

case a['type'].try(:downcase)
case a['type']&.downcase
when 'function'
method = ContractMethod.new(a)
@functions[method.name] = method
Expand Down
6 changes: 4 additions & 2 deletions lib/web3/eth/rpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ class Rpc

DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 8545
DEFAULT_BLOCK = 'latest'

attr_reader :eth, :connect_options
attr_accessor :block

def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_CONNECT_OPTIONS
def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_CONNECT_OPTIONS, block: DEFAULT_BLOCK

@client_id = Random.rand 10000000

@uri = URI((connect_options[:use_ssl] ? 'https' : 'http')+ "://#{host}:#{port}#{connect_options[:rpc_path]}")
@connect_options = connect_options

@eth = EthModule.new self

@block = block
end

def trace
Expand Down
5 changes: 1 addition & 4 deletions test/web3/eth_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'test_helper'
require_relative '../test_helper'

class Web3::EthTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::Web3::Eth::VERSION
end

def test_it_does_something_useful
assert false
end
end
2 changes: 1 addition & 1 deletion web3-eth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|

spec.add_dependency('rlp', '~> 0.7.3')
spec.add_dependency('digest-sha3', '~> 1.1.0')
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "bundler", "> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.0"
end