eth 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62da01e731dd3a73a356760ac971250f193142090876e62567d73cbb5664213d
4
- data.tar.gz: 8a951b1b585acd7b58dc327f122dbdd4787145fefbe09d71f1aa4d127787e99e
3
+ metadata.gz: aabc7ea4a3cd8e94e91e5e9d3bfb0600960079c72e9f99de61d721cae0a73feb
4
+ data.tar.gz: 04e28c96e36958ca58cd49e1e6182a17bf5bc56cab28bd0052f8881899250294
5
5
  SHA512:
6
- metadata.gz: fd1ca2d9f89a545f20cf23a9cff62a83bfe20514b69cb14aac88f08cd101a8bb9e26ba700539259c16d64ee2a3cbae46adf7bedd18b66835785ad701fd515681
7
- data.tar.gz: a1f51f0dac47d8ce7a4ccd3df0d3decfdb0847df36a4b16587b5dd9ae217aee7375e952207d00611bcb487647ff152d958d4709ebf8b429ec0235220f45d35bd
6
+ metadata.gz: 9e7413915597355913492ea5dc22167507ab4d75b3de8783b8c87fb0849e036316f33264053fd166ada749a08215d599197eb4b94d8c954c898aec80bb91f3d7
7
+ data.tar.gz: c8b0a8c288ffe282edbda04d73dff58baa66e9f50dba1998c2450b775ed27201b988048dcfd3b902ac81d19b6dfe9e73d60d86b0c300df7e0cddc301b14ec13c
data/lib/eth/abi.rb CHANGED
@@ -74,7 +74,7 @@ module Eth
74
74
  # @return [String] the encoded type.
75
75
  # @raise [EncodingError] if value does not match type.
76
76
  def encode_type(type, arg)
77
- if %w(string bytes).include? type.base_type and type.sub_type.empty?
77
+ if %w(string bytes).include? type.base_type and type.sub_type.empty? and type.dimensions.empty?
78
78
  raise EncodingError, "Argument must be a String" unless arg.instance_of? String
79
79
 
80
80
  # encodes strings and bytes
@@ -89,10 +89,24 @@ module Eth
89
89
  head += encode_type Type.size_type, arg.size
90
90
  nested_sub = type.nested_sub
91
91
  nested_sub_size = type.nested_sub.size
92
- arg.size.times do |i|
93
92
 
94
- # ref https://github.com/ethereum/tests/issues/691
95
- raise NotImplementedError, "Encoding dynamic arrays with nested dynamic sub-types is not implemented for ABI." if nested_sub.is_dynamic?
93
+ # calculate offsets
94
+ if %w(string bytes).include?(type.base_type) && type.sub_type.empty?
95
+ offset = 0
96
+ arg.size.times do |i|
97
+ if i == 0
98
+ offset = arg.size * 32
99
+ else
100
+ number_of_words = ((arg[i - 1].size + 32 - 1) / 32).floor
101
+ total_bytes_length = number_of_words * 32
102
+ offset += total_bytes_length + 32
103
+ end
104
+
105
+ head += encode_type Type.size_type, offset
106
+ end
107
+ end
108
+
109
+ arg.size.times do |i|
96
110
  head += encode_type nested_sub, arg[i]
97
111
  end
98
112
  return "#{head}#{tail}"
@@ -306,6 +320,7 @@ module Eth
306
320
 
307
321
  # Properly encodes unsigned integers.
308
322
  def encode_uint(arg, type)
323
+ raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
309
324
  raise ValueOutOfBounds, "Number out of range: #{arg}" if arg > Constant::UINT_MAX or arg < Constant::UINT_MIN
310
325
  real_size = type.sub_type.to_i
311
326
  i = arg.to_i
@@ -315,6 +330,7 @@ module Eth
315
330
 
316
331
  # Properly encodes signed integers.
317
332
  def encode_int(arg, type)
333
+ raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
318
334
  raise ValueOutOfBounds, "Number out of range: #{arg}" if arg > Constant::INT_MAX or arg < Constant::INT_MIN
319
335
  real_size = type.sub_type.to_i
320
336
  i = arg.to_i
@@ -330,6 +346,7 @@ module Eth
330
346
 
331
347
  # Properly encodes unsigned fixed-point numbers.
332
348
  def encode_ufixed(arg, type)
349
+ raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
333
350
  high, low = type.sub_type.split("x").map(&:to_i)
334
351
  raise ValueOutOfBounds, arg unless arg >= 0 and arg < 2 ** high
335
352
  return Util.zpad_int((arg * 2 ** low).to_i)
@@ -337,6 +354,7 @@ module Eth
337
354
 
338
355
  # Properly encodes signed fixed-point numbers.
339
356
  def encode_fixed(arg, type)
357
+ raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
340
358
  high, low = type.sub_type.split("x").map(&:to_i)
341
359
  raise ValueOutOfBounds, arg unless arg >= -2 ** (high - 1) and arg < 2 ** (high - 1)
342
360
  i = (arg * 2 ** low).to_i
data/lib/eth/client.rb CHANGED
@@ -159,6 +159,7 @@ module Eth
159
159
  # *args Optional variable constructor parameter list
160
160
  # **sender_key [Eth::Key] the sender private key.
161
161
  # **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
162
+ # **gas_limit [Integer] optional gas limit override for deploying the contract.
162
163
  # @return [String] the contract address.
163
164
  def deploy_and_wait(contract, *args, **kwargs)
164
165
  hash = wait_for_tx(deploy(contract, *args, **kwargs))
@@ -176,16 +177,21 @@ module Eth
176
177
  # *args Optional variable constructor parameter list
177
178
  # **sender_key [Eth::Key] the sender private key.
178
179
  # **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
180
+ # **gas_limit [Integer] optional gas limit override for deploying the contract.
179
181
  # @return [String] the transaction hash.
180
182
  # @raise [ArgumentError] in case the contract does not have any source.
181
183
  def deploy(contract, *args, **kwargs)
182
184
  raise ArgumentError, "Cannot deploy contract without source or binary!" if contract.bin.nil?
183
185
  raise ArgumentError, "Missing contract constructor params!" if contract.constructor_inputs.length != args.length
184
- gas_limit = Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
185
186
  data = contract.bin
186
187
  unless args.empty?
187
188
  data += encode_constructor_params(contract, args)
188
189
  end
190
+ gas_limit = if kwargs[:gas_limit]
191
+ kwargs[:gas_limit]
192
+ else
193
+ Tx.estimate_intrinsic_gas(data) + Tx::CREATE_GAS
194
+ end
189
195
  params = {
190
196
  value: 0,
191
197
  gas_limit: gas_limit,
@@ -231,12 +237,13 @@ module Eth
231
237
  # @param contract [Eth::Contract] subject contract to call.
232
238
  # @param function_name [String] method name to be called.
233
239
  # @param value [Integer|String] function arguments.
234
- # @overload call(contract, function_name, value, sender_key, legacy)
240
+ # @overload call(contract, function_name, value, sender_key, legacy, gas_limit)
235
241
  # @param contract [Eth::Contract] subject contract to call.
236
242
  # @param function_name [String] method name to be called.
237
243
  # @param value [Integer|String] function arguments.
238
244
  # @param sender_key [Eth::Key] the sender private key.
239
245
  # @param legacy [Boolean] enables legacy transactions (pre-EIP-1559).
246
+ # @param gas_limit [Integer] optional gas limit override for deploying the contract.
240
247
  # @return [Object] returns the result of the call.
241
248
  def call(contract, function_name, *args, **kwargs)
242
249
  func = contract.functions.select { |func| func.name == function_name }[0]
@@ -259,16 +266,21 @@ module Eth
259
266
  # @param contract [Eth::Contract] subject contract to call.
260
267
  # @param function_name [String] method name to be called.
261
268
  # @param value [Integer|String] function arguments.
262
- # @overload transact(contract, function_name, value, sender_key, legacy, address)
269
+ # @overload transact(contract, function_name, value, sender_key, legacy, address, gas_limit)
263
270
  # @param contract [Eth::Contract] subject contract to call.
264
271
  # @param function_name [String] method name to be called.
265
272
  # @param value [Integer|String] function arguments.
266
273
  # @param sender_key [Eth::Key] the sender private key.
267
274
  # @param legacy [Boolean] enables legacy transactions (pre-EIP-1559).
268
275
  # @param address [String] contract address.
276
+ # @param gas_limit [Integer] optional gas limit override for deploying the contract.
269
277
  # @return [Object] returns the result of the call.
270
278
  def transact(contract, function_name, *args, **kwargs)
271
- gas_limit = Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
279
+ gas_limit = if kwargs[:gas_limit]
280
+ kwargs[:gas_limit]
281
+ else
282
+ Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
283
+ end
272
284
  fun = contract.functions.select { |func| func.name == function_name }[0]
273
285
  params = {
274
286
  value: 0,
@@ -393,7 +405,11 @@ module Eth
393
405
 
394
406
  # Non-transactional function call called from call().
395
407
  def call_raw(contract, func, *args, **kwargs)
396
- gas_limit = Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
408
+ gas_limit = if kwargs[:gas_limit]
409
+ kwargs[:gas_limit]
410
+ else
411
+ Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
412
+ end
397
413
  params = {
398
414
  gas_limit: gas_limit,
399
415
  chain_id: chain_id,
@@ -43,7 +43,7 @@ module Eth
43
43
  # @param inputs [Array<Eth::Contract::FunctionInput>] function input class list.
44
44
  # @return [String] function string.
45
45
  def self.calc_signature(name, inputs)
46
- "#{name}(#{inputs.collect { |x| x.type }.join(",")})"
46
+ "#{name}(#{inputs.collect { |x| x.raw_type }.join(",")})"
47
47
  end
48
48
 
49
49
  # Encodes a function signature.
@@ -19,12 +19,13 @@ module Eth
19
19
 
20
20
  # Provide classes for contract function input.
21
21
  class Contract::FunctionInput
22
- attr_accessor :type, :name
22
+ attr_accessor :type, :raw_type, :name
23
23
 
24
24
  # Constructor of the {Eth::Contract::FunctionInput} class.
25
25
  #
26
26
  # @param data [Hash] contract abi data.
27
27
  def initialize(data)
28
+ @raw_type = data["type"]
28
29
  @type = Eth::Abi::Type.parse(data["type"])
29
30
  @name = data["name"]
30
31
  end
data/lib/eth/signature.rb CHANGED
@@ -38,7 +38,7 @@ module Eth
38
38
  # @param message [String] the message string to be prefixed.
39
39
  # @return [String] an EIP-191 prefixed string.
40
40
  def prefix_message(message)
41
- "#{EIP191_PREFIX_BYTE}Ethereum Signed Message:\n#{message.size}#{message}"
41
+ "#{EIP191_PREFIX_BYTE}Ethereum Signed Message:\n#{message.bytesize}#{message}"
42
42
  end
43
43
 
44
44
  # Dissects a signature blob of 65+ bytes into its `r`, `s`, and `v`
data/lib/eth/version.rb CHANGED
@@ -16,5 +16,5 @@
16
16
  module Eth
17
17
 
18
18
  # Defines the version of the {Eth} module.
19
- VERSION = "0.5.5".freeze
19
+ VERSION = "0.5.6".freeze
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Ellis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-05-30 00:00:00.000000000 Z
12
+ date: 2022-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: keccak
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 3.3.8
180
+ rubygems_version: 3.3.15
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: Ruby Ethereum library.