eth 0.5.8 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bb2370cb186c41e849c2949bbfcc1cb5cc6b2572064d8abba4631ed3ed3a692
4
- data.tar.gz: dabde7655f7d8921f05a1cdb5d860981c3ee4cced8e1a7b085482d01b14c24b1
3
+ metadata.gz: b38c43c0d7f3c1403c02e847d02623120bab91260ac0dc841f43719302413e1b
4
+ data.tar.gz: 41f4086d2911a30869c7cf5c4e63bfff54d618cb16756f5cbebc4f4accb4b26c
5
5
  SHA512:
6
- metadata.gz: 23a6ac9854368723b40fc0e46fed5e7ae90d1691358538f94cf8a9a43c333dc3e002e5d359513914440823501f882608d9e55e7a71a5a19ee88d38a57498a570
7
- data.tar.gz: 14f5f74ea076a2fbdd5b538521a2b4006e58bf9105e34f0a942560841371f69a48cf80e86c680228ee5253e9483c3d85a857aeea7f48e8f4c1698a0f5ae0236c
6
+ metadata.gz: 45549c5b9c4deace4df8bbcd34c2e4a02476a4175aa8ea865249bb01983c484d85d67954f3b7e68193b16425e8c83efcd4415cd7c2034730fcd8d0d1a324cf34
7
+ data.tar.gz: e1dc19f40eaa284ae09faa6fc70d510ae782b1014f95c0b490dfa8ad86dbf6c9f505b47b6c530217258c33279c204ac6be445fd11fe341bcb302492c95d7b69d
@@ -35,7 +35,7 @@ jobs:
35
35
  run: |
36
36
  sudo add-apt-repository -y ppa:ethereum/ethereum
37
37
  sudo apt-get update
38
- sudo apt-get install ethereum solc
38
+ sudo apt-get install ethereum solc libyaml-dev
39
39
  if: startsWith(matrix.os, 'Ubuntu')
40
40
  - name: Run Geth
41
41
  run: |
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.5.8]
5
+ ### Added
6
+ * Client: ability to manual set nonce of tx for transfer, deploy, transact methods was added. [#169](https://github.com/q9f/eth.rb/pull/169)
7
+ * Client: ability for call contract methods with specific transaction value was added [#168](https://github.com/q9f/eth.rb/pull/168)
8
+ * Client: add ENS resolve support [#150](https://github.com/q9f/eth.rb/pull/150)
9
+
10
+ ### Changed
11
+ * Client: satisfy yard docs for transfer kwargs [#170](https://github.com/q9f/eth.rb/pull/170)
12
+ * Client: remove invalid parameters from call_raw method [#166](https://github.com/q9f/eth.rb/pull/166)
13
+ * Gem: bump required ruby version to 3 [#165](https://github.com/q9f/eth.rb/pull/165)
14
+ * Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.0 to 4.4.1 [#162](https://github.com/q9f/eth.rb/pull/162)
15
+ * Gem: bump version to 0.5.8 [#161](https://github.com/q9f/eth.rb/pull/161)
16
+ * Docs: update changelog [#160](https://github.com/q9f/eth.rb/pull/160)
17
+
4
18
  ## [0.5.7]
5
19
  ### Added
6
20
  * Eth/client: add http basic support auth ([#151](https://github.com/q9f/eth.rb/pull/151))
data/LICENSE.txt CHANGED
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright (c) 2016-2022 The Ruby-Eth Contributors
190
+ Copyright (c) 2016-2023 The Ruby-Eth Contributors
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Ethereum for Ruby
8
8
 
9
- [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/q9f/eth.rb/Spec)](https://github.com/q9f/eth.rb/actions)
9
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/q9f/eth.rb/spec.yml?branch=main)](https://github.com/q9f/eth.rb/actions)
10
10
  [![GitHub release (latest by date)](https://img.shields.io/github/v/release/q9f/eth.rb)](https://github.com/q9f/eth.rb/releases)
11
11
  [![Gem](https://img.shields.io/gem/v/eth)](https://rubygems.org/gems/eth)
12
12
  [![Gem](https://img.shields.io/gem/dt/eth)](https://rubygems.org/gems/eth)
data/lib/eth/abi/event.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/abi/type.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -35,18 +35,28 @@ module Eth
35
35
  # The dimension attribute, e.g., `[10]` for an array of size 10.
36
36
  attr :dimensions
37
37
 
38
+ # The components of a tuple type.
39
+ attr :components
40
+
41
+ # The name of tuple component.
42
+ attr :name
43
+
38
44
  # Create a new Type object for base types, sub types, and dimensions.
39
45
  # Should not be used; use {Type.parse} instead.
40
46
  #
41
47
  # @param base_type [String] the base-type attribute.
42
48
  # @param sub_type [String] the sub-type attribute.
43
49
  # @param dimensions [Array] the dimension attribute.
50
+ # @param components [Array] the components attribute.
51
+ # @param component_name [String] the tuple component's name.
44
52
  # @return [Eth::Abi::Type] an ABI type object.
45
- def initialize(base_type, sub_type, dimensions)
53
+ def initialize(base_type, sub_type, dimensions, components = nil, component_name = nil)
46
54
  sub_type = sub_type.to_s
47
55
  @base_type = base_type
48
56
  @sub_type = sub_type
49
57
  @dimensions = dimensions
58
+ @components = components
59
+ @name = component_name
50
60
  end
51
61
 
52
62
  # Converts the self.parse method into a constructor.
@@ -56,9 +66,12 @@ module Eth
56
66
  # Creates a new Type upon success (using konstructor).
57
67
  #
58
68
  # @param type [String] a common Solidity type.
69
+ # @param components [Array] the components attribute.
70
+ # @param component_name [String] the tuple component's name.
59
71
  # @return [Eth::Abi::Type] a parsed Type object.
60
72
  # @raise [ParseError] if it fails to parse the type.
61
- def parse(type)
73
+ def parse(type, components = nil, component_name = nil)
74
+ return type if type.is_a?(Type)
62
75
  _, base_type, sub_type, dimension = /([a-z]*)([0-9]*x?[0-9]*)((\[[0-9]*\])*)/.match(type).to_a
63
76
 
64
77
  # type dimension can only be numeric
@@ -73,6 +86,8 @@ module Eth
73
86
  @base_type = base_type
74
87
  @sub_type = sub_type
75
88
  @dimensions = dims.map { |x| x[1...-1].to_i }
89
+ @components = components.map { |component| Eth::Abi::Type.parse(component["type"], component.dig("components"), component.dig("name")) } unless components.nil?
90
+ @name = component_name
76
91
  end
77
92
 
78
93
  # Creates a new uint256 type used for size.
@@ -98,15 +113,13 @@ module Eth
98
113
  def size
99
114
  s = nil
100
115
  if dimensions.empty?
101
- unless ["string", "bytes"].include?(base_type) and sub_type.empty?
116
+ if !(["string", "bytes", "tuple"].include?(base_type) and sub_type.empty?)
102
117
  s = 32
118
+ elsif base_type == "tuple" && components.none?(&:dynamic?)
119
+ s = components.sum(&:size)
103
120
  end
104
- else
105
- unless dimensions.last == 0
106
- unless nested_sub.is_dynamic?
107
- s = dimensions.last * nested_sub.size
108
- end
109
- end
121
+ elsif dimensions.last != 0 && !nested_sub.dynamic?
122
+ s = dimensions.last * nested_sub.size
110
123
  end
111
124
  @size ||= s
112
125
  end
@@ -114,7 +127,7 @@ module Eth
114
127
  # Helpes to determine whether array is of dynamic size.
115
128
  #
116
129
  # @return [Boolean] true if array is of dynamic size.
117
- def is_dynamic?
130
+ def dynamic?
118
131
  size.nil?
119
132
  end
120
133
 
@@ -122,7 +135,24 @@ module Eth
122
135
  #
123
136
  # @return [Eth::Abi::Type] nested sub-type.
124
137
  def nested_sub
125
- @nested_sub ||= self.class.new(base_type, sub_type, dimensions[0...-1])
138
+ @nested_sub ||= self.class.new(base_type, sub_type, dimensions[0...-1], components, name)
139
+ end
140
+
141
+ # Allows exporting the type as string.
142
+ #
143
+ # @return [String] the type string.
144
+ def to_s
145
+ if base_type == "tuple"
146
+ "(" + components.map(&:to_s).join(",") + ")" + (dimensions.size > 0 ? dimensions.map { |x| "[#{x == 0 ? "" : x}]" }.join : "")
147
+ elsif dimensions.empty?
148
+ if %w[string bytes].include?(base_type) && sub_type.empty?
149
+ base_type
150
+ else
151
+ "#{base_type}#{sub_type}"
152
+ end
153
+ else
154
+ "#{base_type}#{sub_type}#{dimensions.map { |x| "[#{x == 0 ? "" : x}]" }.join}"
155
+ end
126
156
  end
127
157
 
128
158
  private
@@ -138,6 +168,10 @@ module Eth
138
168
 
139
169
  # bytes can be no longer than 32 bytes
140
170
  raise ParseError, "Maximum 32 bytes for fixed-length string or bytes" unless sub_type.empty? || sub_type.to_i <= 32
171
+ when "tuple"
172
+
173
+ # tuples can not have any suffix
174
+ raise ParseError, "Tuple type must have no suffix or numerical suffix" unless sub_type.empty?
141
175
  when "uint", "int"
142
176
 
143
177
  # integers must have a numerical suffix
data/lib/eth/abi.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ module Eth
45
45
  def encode(types, args)
46
46
 
47
47
  # parse all types
48
- parsed_types = types.map { |t| Type.parse(t) }
48
+ parsed_types = types.map { |t| Type === t ? t : Type.parse(t) }
49
49
 
50
50
  # prepare the "head"
51
51
  head_size = (0...args.size)
@@ -55,7 +55,7 @@ module Eth
55
55
 
56
56
  # encode types and arguments
57
57
  args.each_with_index do |arg, i|
58
- if parsed_types[i].is_dynamic?
58
+ if parsed_types[i].dynamic?
59
59
  head += encode_type Type.size_type, head_size + tail.size
60
60
  tail += encode_type parsed_types[i], arg
61
61
  else
@@ -81,12 +81,16 @@ module Eth
81
81
  size = encode_type Type.size_type, arg.size
82
82
  padding = Constant::BYTE_ZERO * (Util.ceil32(arg.size) - arg.size)
83
83
  return "#{size}#{arg}#{padding}"
84
- elsif type.is_dynamic?
85
- raise EncodingError, "Argument must be an Array" unless arg.instance_of? Array
84
+ elsif type.base_type == "tuple" && type.dimensions.size == 1 && type.dimensions[0] != 0
85
+ result = ""
86
+ result += encode_struct_offsets(type.nested_sub, arg)
87
+ result += arg.map { |x| encode_type(type.nested_sub, x) }.join
88
+ result
89
+ elsif type.dynamic? && arg.is_a?(Array)
86
90
 
87
91
  # encodes dynamic-sized arrays
88
92
  head, tail = "", ""
89
- head += encode_type Type.size_type, arg.size
93
+ head += encode_type(Type.size_type, arg.size)
90
94
  nested_sub = type.nested_sub
91
95
  nested_sub_size = type.nested_sub.size
92
96
 
@@ -102,8 +106,10 @@ module Eth
102
106
  offset += total_bytes_length + 32
103
107
  end
104
108
 
105
- head += encode_type Type.size_type, offset
109
+ head += encode_type(Type.size_type, offset)
106
110
  end
111
+ elsif nested_sub.base_type == "tuple" && nested_sub.dynamic?
112
+ head += encode_struct_offsets(nested_sub, arg)
107
113
  end
108
114
 
109
115
  arg.size.times do |i|
@@ -145,6 +151,8 @@ module Eth
145
151
  return encode_fixed arg, type
146
152
  when "string", "bytes"
147
153
  return encode_bytes arg, type
154
+ when "tuple"
155
+ return encode_tuple arg, type
148
156
  when "hash"
149
157
  return encode_hash arg, type
150
158
  when "address"
@@ -163,7 +171,7 @@ module Eth
163
171
  def decode(types, data)
164
172
 
165
173
  # accept hex abi but decode it first
166
- data = Util.hex_to_bin data if Util.is_hex? data
174
+ data = Util.hex_to_bin data if Util.hex? data
167
175
 
168
176
  # parse all types
169
177
  parsed_types = types.map { |t| Type.parse(t) }
@@ -173,7 +181,7 @@ module Eth
173
181
  start_positions = [nil] * types.size + [data.size]
174
182
  pos = 0
175
183
  parsed_types.each_with_index do |t, i|
176
- if t.is_dynamic?
184
+ if t.dynamic?
177
185
 
178
186
  # record start position for dynamic type
179
187
  start_positions[i] = Util.deserialize_big_endian_to_int(data[pos, 32])
@@ -201,7 +209,7 @@ module Eth
201
209
 
202
210
  # add dynamic types
203
211
  parsed_types.each_with_index do |t, i|
204
- if t.is_dynamic?
212
+ if t.dynamic?
205
213
  offset, next_offset = start_positions[i, 2]
206
214
  outputs[i] = data[offset...next_offset]
207
215
  end
@@ -225,12 +233,12 @@ module Eth
225
233
 
226
234
  # decoded strings and bytes
227
235
  return data[0, l]
228
- elsif type.is_dynamic?
236
+ elsif type.dynamic?
229
237
  l = Util.deserialize_big_endian_to_int arg[0, 32]
230
238
  nested_sub = type.nested_sub
231
239
 
232
240
  # ref https://github.com/ethereum/tests/issues/691
233
- raise NotImplementedError, "Decoding dynamic arrays with nested dynamic sub-types is not implemented for ABI." if nested_sub.is_dynamic?
241
+ raise NotImplementedError, "Decoding dynamic arrays with nested dynamic sub-types is not implemented for ABI." if nested_sub.dynamic?
234
242
 
235
243
  # decoded dynamic-sized arrays
236
244
  return (0...l).map { |i| decode_type(nested_sub, arg[32 + nested_sub.size * i, nested_sub.size]) }
@@ -381,6 +389,56 @@ module Eth
381
389
  end
382
390
  end
383
391
 
392
+ # Properly encodes tuples.
393
+ def encode_tuple(arg, type)
394
+ raise EncodingError, "Expecting Hash: #{arg}" unless arg.instance_of? Hash
395
+ raise EncodingError, "Expecting #{type.components.size} elements: #{arg}" unless arg.size == type.components.size
396
+
397
+ static_size = 0
398
+ type.components.each_with_index do |component, i|
399
+ if type.components[i].dynamic?
400
+ static_size += 32
401
+ else
402
+ static_size += Util.ceil32(type.components[i].size || 0)
403
+ end
404
+ end
405
+
406
+ dynamic_offset = static_size
407
+ offsets_and_static_values = []
408
+ dynamic_values = []
409
+
410
+ type.components.each_with_index do |component, i|
411
+ component_type = type.components[i]
412
+ if component_type.dynamic?
413
+ offsets_and_static_values << encode_type(Type.size_type, dynamic_offset)
414
+ dynamic_value = encode_type(component_type, arg.is_a?(Array) ? arg[i] : arg[component_type.name])
415
+ dynamic_values << dynamic_value
416
+ dynamic_offset += dynamic_value.size
417
+ else
418
+ offsets_and_static_values << encode_type(component_type, arg.is_a?(Array) ? arg[i] : arg[component_type.name])
419
+ end
420
+ end
421
+
422
+ offsets_and_static_values.join + dynamic_values.join
423
+ end
424
+
425
+ # Properly encode struct offsets.
426
+ def encode_struct_offsets(type, arg)
427
+ result = ""
428
+ offset = arg.size
429
+ tails_encoding = arg.map { |a| encode_type(type, a) }
430
+ arg.size.times do |i|
431
+ if i == 0
432
+ offset *= 32
433
+ else
434
+ offset += tails_encoding[i - 1].size
435
+ end
436
+ offset_string = encode_type(Type.size_type, offset)
437
+ result += offset_string
438
+ end
439
+ result
440
+ end
441
+
384
442
  # Properly encodes hash-strings.
385
443
  def encode_hash(arg, type)
386
444
  size = type.sub_type.to_i
@@ -428,8 +486,8 @@ module Eth
428
486
  # The ABI encoder needs to be able to determine between a hex `"123"`
429
487
  # and a binary `"123"` string.
430
488
  def handle_hex_string(arg, type)
431
- if Util.is_prefixed? arg or
432
- (arg.size === type.sub_type.to_i * 2 and Util.is_hex? arg)
489
+ if Util.prefixed? arg or
490
+ (arg.size === type.sub_type.to_i * 2 and Util.hex? arg)
433
491
 
434
492
  # There is no way telling whether a string is hex or binary with certainty
435
493
  # in Ruby. Therefore, we assume a `0x` prefix to indicate a hex string.
data/lib/eth/address.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ module Eth
29
29
  #
30
30
  # @param address [String] hex string representing an ethereum address.
31
31
  def initialize(address)
32
- unless Util.is_hex? address
32
+ unless Util.hex? address
33
33
  raise CheckSumError, "Unknown address type #{address}!"
34
34
  end
35
35
  @address = Util.prefix_hex address
data/lib/eth/api.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/chain.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -38,12 +38,18 @@ module Eth
38
38
  # Chain ID for POA Network mainnet.
39
39
  POA_NET = 99.freeze
40
40
 
41
- # Chain ID for Gnosis mainnet.
41
+ # Chain ID for xDAI mainnet (now Gnosis Chain).
42
42
  XDAI = 100.freeze
43
43
 
44
- # Chain ID for the Polygon Matic mainnet.
44
+ # Chain ID for Gnosis mainnet (formerly xDAI).
45
+ GNOSIS = XDAI.freeze
46
+
47
+ # Chain ID for the Matic mainnet (now Polygon).
45
48
  MATIC = 137.freeze
46
49
 
50
+ # Chain ID for the Polygon mainnet (formerly Matic).
51
+ POLYGON = MATIC.freeze
52
+
47
53
  # Chain ID for Arbitrum mainnet.
48
54
  ARBITRUM = 42161.freeze
49
55
 
@@ -86,9 +92,15 @@ module Eth
86
92
  # Chain ID for Arbitrum Rinkeby testnet.
87
93
  RINKEBY_ARBITRUM = 421611.freeze
88
94
 
95
+ # Chain ID for Arbitrum Goerli testnet.
96
+ GOERLI_ARBITRUM = 421613.freeze
97
+
89
98
  # Chain ID for Sepolia testnet.
90
99
  SEPOLIA = 11155111.freeze
91
100
 
101
+ # Chain ID for Holesovice testnet.
102
+ HOLESOVICE = 11166111.freeze
103
+
92
104
  # Chain ID for the geth private network preset.
93
105
  PRIVATE_GETH = 1337.freeze
94
106
 
@@ -97,7 +109,7 @@ module Eth
97
109
  #
98
110
  # @param v [Integer] the signature's `v` value.
99
111
  # @return [Boolean] true if ledger's legacy value.
100
- def is_ledger?(v)
112
+ def ledger?(v)
101
113
  [0, 1].include? v
102
114
  end
103
115
 
@@ -106,7 +118,7 @@ module Eth
106
118
  #
107
119
  # @param v [Integer] the signature's `v` value.
108
120
  # @return [Boolean] true if legacy value.
109
- def is_legacy?(v)
121
+ def legacy?(v)
110
122
  [27, 28].include? v
111
123
  end
112
124
 
@@ -120,11 +132,11 @@ module Eth
120
132
  def to_recovery_id(v, chain_id = ETHEREUM)
121
133
  e = 0 + 2 * chain_id + 35
122
134
  i = 1 + 2 * chain_id + 35
123
- if [0, 1].include? v
135
+ if ledger? v
124
136
 
125
137
  # some wallets are using a `v` of 0 or 1 (ledger)
126
138
  return v
127
- elsif is_legacy? v
139
+ elsif legacy? v
128
140
 
129
141
  # this is the pre-EIP-155 legacy case
130
142
  return v - 27
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/client.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -37,6 +37,9 @@ module Eth
37
37
  # The default gas limit for the transaction, defaults to {Tx::DEFAULT_GAS_LIMIT}.
38
38
  attr_accessor :gas_limit
39
39
 
40
+ # A custom error type if a contract interaction fails.
41
+ class ContractExecutionError < StandardError; end
42
+
40
43
  # Creates a new RPC-Client, either by providing an HTTP/S host or
41
44
  # an IPC path. Supports basic authentication with username and password.
42
45
  #
@@ -345,9 +348,15 @@ module Eth
345
348
  #
346
349
  # See {#transact} for params and overloads.
347
350
  #
351
+ # @raise [Client::ContractExecutionError] if the execution fails.
348
352
  # @return [Object] returns the result of the transaction.
349
353
  def transact_and_wait(contract, function, *args, **kwargs)
350
- wait_for_tx(transact(contract, function, *args, **kwargs))
354
+ begin
355
+ hash = wait_for_tx(transact(contract, function, *args, **kwargs))
356
+ return hash if tx_succeeded? hash
357
+ rescue IOError => e
358
+ raise ContractExecutionError, e
359
+ end
351
360
  end
352
361
 
353
362
  # Provides an interface to call `isValidSignature` as per EIP-1271 on a given
@@ -362,9 +371,9 @@ module Eth
362
371
  # @raise [ArgumentError] in case the contract cannot be called yet.
363
372
  def is_valid_signature(contract, hash, signature, magic = "1626ba7e")
364
373
  raise ArgumentError, "Contract not deployed yet." if contract.address.nil?
365
- hash = Util.hex_to_bin hash if Util.is_hex? hash
366
- signature = Util.hex_to_bin signature if Util.is_hex? signature
367
- magic = Util.hex_to_bin magic if Util.is_hex? magic
374
+ hash = Util.hex_to_bin hash if Util.hex? hash
375
+ signature = Util.hex_to_bin signature if Util.hex? signature
376
+ magic = Util.hex_to_bin magic if Util.hex? magic
368
377
  result = call(contract, "isValidSignature", hash, signature)
369
378
  return result === magic
370
379
  end
@@ -377,15 +386,24 @@ module Eth
377
386
  @id = 0
378
387
  end
379
388
 
380
- # Checkes wether a transaction is mined or not.
389
+ # Checks whether a transaction is mined or not.
381
390
  #
382
391
  # @param hash [String] the transaction hash.
383
392
  # @return [Boolean] true if included in a block.
384
- def is_mined_tx?(hash)
393
+ def tx_mined?(hash)
385
394
  mined_tx = eth_get_transaction_by_hash hash
386
395
  !mined_tx.nil? && !mined_tx["result"].nil? && !mined_tx["result"]["blockNumber"].nil?
387
396
  end
388
397
 
398
+ # Checks whether a contract transaction succeeded or not.
399
+ #
400
+ # @param hash [String] the transaction hash.
401
+ # @return [Boolean] true if status is success.
402
+ def tx_succeeded?(hash)
403
+ tx_receipt = eth_get_transaction_receipt(hash)
404
+ !tx_receipt.nil? && !tx_receipt["result"].nil? && tx_receipt["result"]["status"] == "0x1"
405
+ end
406
+
389
407
  # Waits for an transaction to be mined by the connected chain.
390
408
  #
391
409
  # @param hash [String] the transaction hash.
@@ -397,7 +415,7 @@ module Eth
397
415
  retry_rate = 0.1
398
416
  loop do
399
417
  raise Timeout::Error if ((Time.now - start_time) > timeout)
400
- return hash if is_mined_tx? hash
418
+ return hash if tx_mined? hash
401
419
  sleep retry_rate
402
420
  end
403
421
  end
@@ -430,7 +448,7 @@ module Eth
430
448
 
431
449
  # Encodes function call payloads.
432
450
  def call_payload(fun, args)
433
- types = fun.inputs.map { |i| i.type }
451
+ types = fun.inputs.map(&:parsed_type)
434
452
  encoded_str = Util.bin_to_hex(Eth::Abi.encode(types, args))
435
453
  Util.prefix_hex(fun.signature + (encoded_str.empty? ? "0" * 64 : encoded_str))
436
454
  end
@@ -460,17 +478,28 @@ module Eth
460
478
  @id += 1
461
479
  end
462
480
 
481
+ # expects Hash object
482
+ def camelize!(params)
483
+ params.transform_keys! do |k|
484
+ k = k.to_s.split(/_/).map(&:capitalize).join
485
+ k[0] = k[0].downcase
486
+ k.to_sym
487
+ end
488
+ end
489
+
463
490
  # Recursively marshals all request parameters.
464
491
  def marshal(params)
492
+ params = params.dup
465
493
  if params.is_a? Array
466
494
  return params.map! { |param| marshal(param) }
467
495
  elsif params.is_a? Hash
496
+ params = camelize!(params)
468
497
  return params.transform_values! { |param| marshal(param) }
469
498
  elsif params.is_a? Numeric
470
499
  return Util.prefix_hex "#{params.to_i.to_s(16)}"
471
500
  elsif params.is_a? Address
472
501
  return params.to_s
473
- elsif Util.is_hex? params
502
+ elsif Util.hex? params
474
503
  return Util.prefix_hex params
475
504
  else
476
505
  return params
data/lib/eth/constant.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -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.raw_type }.join(",")})"
46
+ "#{name}(#{inputs.map { |x| x.parsed_type.to_s }.join(",")})"
47
47
  end
48
48
 
49
49
  # Encodes a function signature.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ module Eth
26
26
  # @param data [Hash] contract abi data.
27
27
  def initialize(data)
28
28
  @raw_type = data["type"]
29
- @type = Eth::Abi::Type.parse(data["type"])
29
+ @type = Eth::Abi::Type.parse(data["type"], data["components"])
30
30
  @name = data["name"]
31
31
  end
32
32
 
@@ -34,5 +34,10 @@ module Eth
34
34
  def type
35
35
  @type.base_type + @type.sub_type + @type.dimensions.map { |dimension| "[#{dimension > 0 ? dimension : ""}]" }.join("")
36
36
  end
37
+
38
+ # Returns parsed types.
39
+ def parsed_type
40
+ @type
41
+ end
37
42
  end
38
43
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/contract.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/eip712.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -149,7 +149,7 @@ module Eth
149
149
  # @return [Array] the data in the data structure we want to hash.
150
150
  # @raise [TypedDataError] if the data fails validation.
151
151
  def enforce_typed_data(data)
152
- data = JSON.parse data if Util.is_hex? data
152
+ data = JSON.parse data if Util.hex? data
153
153
  raise TypedDataError, "Data is missing, try again with data." if data.nil? or data.empty?
154
154
  raise TypedDataError, "Data types are missing." if data[:types].nil? or data[:types].empty?
155
155
  raise TypedDataError, "Data primaryType is missing." if data[:primaryType].nil? or data[:primaryType].empty?
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/key.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ module Eth
51
51
  unless priv.nil?
52
52
 
53
53
  # Converts hex private keys to binary strings.
54
- priv = Util.hex_to_bin priv if Util.is_hex? priv
54
+ priv = Util.hex_to_bin priv if Util.hex? priv
55
55
 
56
56
  # Creates a keypair from existing private key data.
57
57
  key = ctx.key_pair_from_private_key priv
@@ -74,10 +74,10 @@ module Eth
74
74
  compact, recovery_id = context.sign_recoverable(@private_key, blob).compact
75
75
  signature = compact.bytes
76
76
  v = Chain.to_v recovery_id, chain_id
77
- is_leading_zero = true
77
+ leading_zero = true
78
78
  [v].pack("N").unpack("C*").each do |byte|
79
- is_leading_zero = false if byte > 0 and is_leading_zero
80
- signature.append byte unless is_leading_zero and byte === 0
79
+ leading_zero = false if byte > 0 and leading_zero
80
+ signature.append byte unless leading_zero and byte === 0
81
81
  end
82
82
  Util.bin_to_hex signature.pack "c*"
83
83
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ module Eth
31
31
  # @raise [Eth::Rlp::DecodingError] if the input string does not end after
32
32
  # the root item.
33
33
  def perform(rlp)
34
- rlp = Util.hex_to_bin rlp if Util.is_hex? rlp
34
+ rlp = Util.hex_to_bin rlp if Util.hex? rlp
35
35
  rlp = Util.str_to_bytes rlp
36
36
  begin
37
37
  item, next_start = consume_item rlp, 0
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -41,8 +41,8 @@ module Eth
41
41
  # Encodes the raw item.
42
42
  def encode_raw(item)
43
43
  return item if item.instance_of? Rlp::Data
44
- return encode_primitive item if Util.is_primitive? item
45
- return encode_list item if Util.is_list? item
44
+ return encode_primitive item if Util.primitive? item
45
+ return encode_list item if Util.list? item
46
46
  raise EncodingError "Cannot encode object of type #{item.class.name}"
47
47
  end
48
48
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ module Eth
78
78
  # @raise [DeserializationError] if provided serial is of wrong type.
79
79
  # @raise [DeserializationError] if provided serial is of wrong length.
80
80
  def deserialize(serial)
81
- raise DeserializationError, "Objects of type #{serial.class} cannot be deserialized" unless Util.is_primitive? serial
81
+ raise DeserializationError, "Objects of type #{serial.class} cannot be deserialized" unless Util.primitive? serial
82
82
  raise DeserializationError, "#{serial.class} has invalid length" unless valid_length? serial.size
83
83
  serial
84
84
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -34,9 +34,9 @@ module Eth
34
34
  super()
35
35
  @strict = strict
36
36
  elements.each do |e|
37
- if Sedes.is_sedes?(e)
37
+ if Sedes.sedes?(e)
38
38
  push e
39
- elsif Util.is_list?(e)
39
+ elsif Util.list?(e)
40
40
  push List.new(elements: e)
41
41
  else
42
42
  raise TypeError, "Instances of List must only contain sedes objects or nested sequences thereof."
@@ -51,7 +51,7 @@ module Eth
51
51
  # @raise [SerializationError] if provided array is not a sequence.
52
52
  # @raise [SerializationError] if provided array is of wrong length.
53
53
  def serialize(obj)
54
- raise SerializationError, "Can only serialize sequences" unless Util.is_list?(obj)
54
+ raise SerializationError, "Can only serialize sequences" unless Util.list?(obj)
55
55
  raise SerializationError, "List has wrong length" if (@strict && self.size != obj.size) || self.size < obj.size
56
56
  result = []
57
57
  obj.zip(self).each_with_index do |(element, sedes), i|
@@ -67,7 +67,7 @@ module Eth
67
67
  # @raise [DeserializationError] if provided serial is not a sequence.
68
68
  # @raise [DeserializationError] if provided serial is of wrong length.
69
69
  def deserialize(serial)
70
- raise DeserializationError, "Can only deserialize sequences" unless Util.is_list?(serial)
70
+ raise DeserializationError, "Can only deserialize sequences" unless Util.list?(serial)
71
71
  raise DeserializationError, "List has wrong length" if @strict && serial.size != self.size
72
72
  result = []
73
73
  len = [serial.size, self.size].min
data/lib/eth/rlp/sedes.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -39,10 +39,10 @@ module Eth
39
39
  # @param obj [Object] the Ruby object for which to find a sedes object.
40
40
  # @raise [TypeError] if no appropriate sedes could be found.
41
41
  def infer(obj)
42
- return obj.class if is_sedes? obj.class
42
+ return obj.class if sedes? obj.class
43
43
  return big_endian_int if obj.is_a?(Integer) && obj >= 0
44
44
  return binary if Binary.valid_type? obj
45
- return List.new(elements: obj.map { |item| infer item }) if Util.is_list? obj
45
+ return List.new(elements: obj.map { |item| infer item }) if Util.list? obj
46
46
  raise TypeError, "Did not find sedes handling type #{obj.class.name}"
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ module Eth
50
50
  #
51
51
  # @param obj [Object] the object to check.
52
52
  # @return [Boolean] true if it's serializable and deserializable.
53
- def is_sedes?(obj)
53
+ def sedes?(obj)
54
54
  obj.respond_to?(:serialize) && obj.respond_to?(:deserialize)
55
55
  end
56
56
 
data/lib/eth/rlp.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/signature.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ module Eth
48
48
  # @return [String, String, String] the `r`, `s`, and `v` values.
49
49
  # @raise [SignatureError] if signature is of unknown size.
50
50
  def dissect(signature)
51
- signature = Util.bin_to_hex signature unless Util.is_hex? signature
51
+ signature = Util.bin_to_hex signature unless Util.hex? signature
52
52
  signature = Util.remove_hex_prefix signature
53
53
  if signature.size < 130
54
54
  raise SignatureError, "Unknown signature length #{signature.size}!"
@@ -70,7 +70,7 @@ module Eth
70
70
  context = Secp256k1::Context.new
71
71
  r, s, v = dissect signature
72
72
  v = v.to_i(16)
73
- if !Chain.is_ledger? v and !Chain.is_legacy? v
73
+ if !Chain.ledger? v and !Chain.legacy? v
74
74
  min_v = 2 * chain_id + 35
75
75
  raise SignatureError, "Invalid signature v byte #{v} for chain ID #{chain_id}!" if v < min_v
76
76
  end
@@ -126,7 +126,7 @@ module Eth
126
126
 
127
127
  # recover message from personal_sign
128
128
  recovered_key = personal_recover blob, signature, chain_id
129
- elsif blob.instance_of? String and (Util.is_hex? blob or blob.encoding == Encoding::ASCII_8BIT)
129
+ elsif blob.instance_of? String and (Util.hex? blob or blob.encoding == Encoding::ASCII_8BIT)
130
130
 
131
131
  # if nothing else, recover from arbitrary signature
132
132
  recovered_key = recover blob, signature, chain_id
data/lib/eth/solidity.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -42,8 +42,10 @@ module Eth
42
42
  # @return [Array] JSON containing the compiled contract and ABI for all contracts.
43
43
  def compile(contract)
44
44
  raise Errno::ENOENT, "Contract file not found: #{contract}" unless File.exist? contract
45
- command = "#{@compiler} --optimize --combined-json bin,abi #{contract}"
46
- output, error, status = Open3.capture3 command
45
+ flag_opt = "--optimize"
46
+ flag_json = "--combined-json=bin,abi"
47
+ path = File.realpath contract
48
+ output, error, status = Open3.capture3 @compiler, flag_opt, flag_json, path
47
49
  raise SystemCallError, "Unable to run solc compiler!" if status.exitstatus === 127
48
50
  raise CompilerError, error unless status.success?
49
51
  json = JSON.parse output
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -231,7 +231,7 @@ module Eth
231
231
  # @raise [Signature::SignatureError] if transaction is already signed.
232
232
  # @raise [Signature::SignatureError] if sender address does not match signing key.
233
233
  def sign(key)
234
- if Tx.is_signed? self
234
+ if Tx.signed? self
235
235
  raise Signature::SignatureError, "Transaction is already signed!"
236
236
  end
237
237
 
@@ -258,7 +258,7 @@ module Eth
258
258
  # @return [String] a raw, RLP-encoded EIP-1559 type transaction object.
259
259
  # @raise [Signature::SignatureError] if the transaction is not yet signed.
260
260
  def encoded
261
- unless Tx.is_signed? self
261
+ unless Tx.signed? self
262
262
  raise Signature::SignatureError, "Transaction is not signed!"
263
263
  end
264
264
  tx_data = []
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -225,7 +225,7 @@ module Eth
225
225
  # @raise [Signature::SignatureError] if transaction is already signed.
226
226
  # @raise [Signature::SignatureError] if sender address does not match signing key.
227
227
  def sign(key)
228
- if Tx.is_signed? self
228
+ if Tx.signed? self
229
229
  raise Signature::SignatureError, "Transaction is already signed!"
230
230
  end
231
231
 
@@ -252,7 +252,7 @@ module Eth
252
252
  # @return [String] a raw, RLP-encoded EIP-2930 type transaction object.
253
253
  # @raise [Signature::SignatureError] if the transaction is not yet signed.
254
254
  def encoded
255
- unless Tx.is_signed? self
255
+ unless Tx.signed? self
256
256
  raise Signature::SignatureError, "Transaction is not signed!"
257
257
  end
258
258
  tx_data = []
data/lib/eth/tx/legacy.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -205,7 +205,7 @@ module Eth
205
205
  # @raise [Signature::SignatureError] if transaction is already signed.
206
206
  # @raise [Signature::SignatureError] if sender address does not match signing key.
207
207
  def sign(key)
208
- if Tx.is_signed? self
208
+ if Tx.signed? self
209
209
  raise Signature::SignatureError, "Transaction is already signed!"
210
210
  end
211
211
 
@@ -230,7 +230,7 @@ module Eth
230
230
  # @return [String] a raw, RLP-encoded legacy transaction.
231
231
  # @raise [Signature::SignatureError] if the transaction is not yet signed.
232
232
  def encoded
233
- unless Tx.is_signed? self
233
+ unless Tx.signed? self
234
234
  raise Signature::SignatureError, "Transaction is not signed!"
235
235
  end
236
236
  tx_data = []
data/lib/eth/tx.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -164,7 +164,7 @@ module Eth
164
164
  def estimate_intrinsic_gas(data = "", list = [])
165
165
  gas = DEFAULT_GAS_LIMIT
166
166
  unless data.nil? or data.empty?
167
- data = Util.hex_to_bin data if Util.is_hex? data
167
+ data = Util.hex_to_bin data if Util.hex? data
168
168
 
169
169
  # count zero bytes
170
170
  zero = data.count ZERO_BYTE
@@ -288,7 +288,7 @@ module Eth
288
288
  data = "" if data.nil?
289
289
 
290
290
  # ensure payload to be binary if it's hex, otherwise we'll treat it raw
291
- data = Util.hex_to_bin data if Util.is_hex? data
291
+ data = Util.hex_to_bin data if Util.hex? data
292
292
  return data
293
293
  end
294
294
 
@@ -305,7 +305,7 @@ module Eth
305
305
 
306
306
  # recursively check the entire array
307
307
  list[index] = sanitize_list value
308
- elsif Util.is_hex? value
308
+ elsif Util.hex? value
309
309
 
310
310
  # only modify if we find a hex value
311
311
  list[index] = Util.hex_to_bin value
@@ -317,7 +317,7 @@ module Eth
317
317
  # Allows to check wether a transaction is signed already.
318
318
  #
319
319
  # @return [Bool] true if transaction is already signed.
320
- def is_signed?(tx)
320
+ def signed?(tx)
321
321
  !tx.signature_r.nil? and tx.signature_r != 0 and
322
322
  !tx.signature_s.nil? and tx.signature_s != 0
323
323
  end
data/lib/eth/unit.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/util.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ module Eth
27
27
  # @param str [String] the public key to be converted.
28
28
  # @return [Eth::Address] an Ethereum address.
29
29
  def public_key_to_address(str)
30
- str = hex_to_bin str if is_hex? str
30
+ str = hex_to_bin str if hex? str
31
31
  bytes = keccak256(str[1..-1])[-20..-1]
32
32
  Address.new bin_to_prefixed_hex bytes
33
33
  end
@@ -59,7 +59,7 @@ module Eth
59
59
  def hex_to_bin(hex)
60
60
  raise TypeError, "Value must be an instance of String" unless hex.instance_of? String
61
61
  hex = remove_hex_prefix hex
62
- raise TypeError, "Non-hexadecimal digit found" unless is_hex? hex
62
+ raise TypeError, "Non-hexadecimal digit found" unless hex? hex
63
63
  [hex].pack("H*")
64
64
  end
65
65
 
@@ -68,7 +68,7 @@ module Eth
68
68
  # @param hex [String] a hex-string to be prefixed.
69
69
  # @return [String] a prefixed hex-string.
70
70
  def prefix_hex(hex)
71
- return hex if is_prefixed? hex
71
+ return hex if prefixed? hex
72
72
  return "0x#{hex}"
73
73
  end
74
74
 
@@ -77,7 +77,7 @@ module Eth
77
77
  # @param hex [String] a prefixed hex-string.
78
78
  # @return [String] an unprefixed hex-string.
79
79
  def remove_hex_prefix(hex)
80
- return hex[2..-1] if is_prefixed? hex
80
+ return hex[2..-1] if prefixed? hex
81
81
  return hex
82
82
  end
83
83
 
@@ -93,7 +93,7 @@ module Eth
93
93
  #
94
94
  # @param str [String] a string to be checked.
95
95
  # @return [String] a match if true; `nil` if not.
96
- def is_hex?(str)
96
+ def hex?(str)
97
97
  return false unless str.is_a? String
98
98
  str = remove_hex_prefix str
99
99
  str.match /\A[0-9a-fA-F]*\z/
@@ -103,7 +103,7 @@ module Eth
103
103
  #
104
104
  # @param hex [String] a string to be checked.
105
105
  # @return [String] a match if true; `nil` if not.
106
- def is_prefixed?(hex)
106
+ def prefixed?(hex)
107
107
  hex.match /\A0x/
108
108
  end
109
109
 
@@ -113,7 +113,7 @@ module Eth
113
113
  # @return [String] serialized big endian integer string.
114
114
  # @raise [ArgumentError] if unsigned integer is out of bounds.
115
115
  def serialize_int_to_big_endian(num)
116
- num = num.to_i(16) if is_hex? num
116
+ num = num.to_i(16) if hex? num
117
117
  unless num.is_a? Integer and num >= 0 and num <= Constant::UINT_MAX
118
118
  raise ArgumentError, "Integer invalid or out of range: #{num}"
119
119
  end
@@ -125,7 +125,7 @@ module Eth
125
125
  # @param num [Integer] integer to be converted.
126
126
  # @return [String] packed, big-endian integer string.
127
127
  def int_to_big_endian(num)
128
- hex = num.to_s(16) unless is_hex? num
128
+ hex = num.to_s(16) unless hex? num
129
129
  hex = "0#{hex}" if hex.size.odd?
130
130
  hex_to_bin hex
131
131
  end
@@ -151,7 +151,7 @@ module Eth
151
151
  # @param str [String] binary string to be converted.
152
152
  # @return [Object] the string bytes.
153
153
  def str_to_bytes(str)
154
- is_bytes?(str) ? str : str.b
154
+ bytes?(str) ? str : str.b
155
155
  end
156
156
 
157
157
  # Converts bytes to a binary string.
@@ -166,7 +166,7 @@ module Eth
166
166
  #
167
167
  # @param str [String] a string to check.
168
168
  # @return [Boolean] true if it's an ASCII-8bit encoded byte-string.
169
- def is_bytes?(str)
169
+ def bytes?(str)
170
170
  str && str.instance_of?(String) && str.encoding.name == Constant::BINARY_ENCODING
171
171
  end
172
172
 
@@ -174,7 +174,7 @@ module Eth
174
174
  #
175
175
  # @param item [Object] the item to check.
176
176
  # @return [Boolean] true if it's a string primitive.
177
- def is_primitive?(item)
177
+ def primitive?(item)
178
178
  item.instance_of?(String)
179
179
  end
180
180
 
@@ -182,8 +182,8 @@ module Eth
182
182
  #
183
183
  # @param item [Object] the item to check.
184
184
  # @return [Boolean] true if it's a list.
185
- def is_list?(item)
186
- !is_primitive?(item) && item.respond_to?(:each)
185
+ def list?(item)
186
+ !primitive?(item) && item.respond_to?(:each)
187
187
  end
188
188
 
189
189
  # Ceil and integer to the next multiple of 32 bytes.
data/lib/eth/version.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -16,5 +16,5 @@
16
16
  module Eth
17
17
 
18
18
  # Defines the version of the {Eth} module.
19
- VERSION = "0.5.8".freeze
19
+ VERSION = "0.5.9".freeze
20
20
  end
data/lib/eth.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
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.8
4
+ version: 0.5.9
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-11-30 00:00:00.000000000 Z
12
+ date: 2022-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: keccak
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
- rubygems_version: 3.3.25
184
+ rubygems_version: 3.2.32
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Ruby Ethereum library.