Skip to content

Commit 66d0ef6

Browse files
committed
set a block number to use in web3 rpc
1 parent 28f970b commit 66d0ef6

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

lib/web3/eth/contract.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ def parse_method_args transaction
9292
def do_call web3_rpc, contract_address, args
9393
data = '0x' + signature_hash + encode_hex(encode_abi(input_types, args) )
9494

95-
response = web3_rpc.eth.call [{ to: contract_address, data: data}, 'latest']
95+
block = @web3_rpc.block
96+
if block.is_a?(Numeric)
97+
block = "0x#{block.to_s(16)}"
98+
end
99+
response = web3_rpc.eth.call [{ to: contract_address, data: data}, block]
96100

97101
string_data = [remove_0x_head(response)].pack('H*')
98102
return nil if string_data.empty?

lib/web3/eth/rpc.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ class Rpc
1616

1717
DEFAULT_HOST = 'localhost'
1818
DEFAULT_PORT = 8545
19+
DEFAULT_BLOCK = 'latest'
1920

2021
attr_reader :eth, :connect_options
22+
attr_accessor :block
2123

22-
def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_CONNECT_OPTIONS
24+
def initialize host: DEFAULT_HOST, port: DEFAULT_PORT, connect_options: DEFAULT_CONNECT_OPTIONS, block: DEFAULT_BLOCK
2325

2426
@client_id = Random.rand 10000000
2527

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

2931
@eth = EthModule.new self
30-
32+
@block = block
3133
end
3234

3335
def trace

0 commit comments

Comments
 (0)