eth 0.5.13 → 0.5.15
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 +4 -4
- data/.github/workflows/codeql.yml +1 -1
- data/.github/workflows/docs.yml +2 -2
- data/.github/workflows/spec.yml +1 -3
- data/CHANGELOG.md +33 -0
- data/CODE_OF_CONDUCT.md +3 -5
- data/Gemfile +3 -3
- data/LICENSE.txt +1 -1
- data/README.md +6 -6
- data/SECURITY.md +2 -2
- data/eth.gemspec +4 -1
- data/lib/eth/abi/decoder.rb +18 -7
- data/lib/eth/abi/encoder.rb +14 -26
- data/lib/eth/abi/event.rb +5 -1
- data/lib/eth/abi/function.rb +124 -0
- data/lib/eth/abi/packed/encoder.rb +196 -0
- data/lib/eth/abi/type.rb +77 -16
- data/lib/eth/abi.rb +29 -2
- data/lib/eth/address.rb +3 -1
- data/lib/eth/api.rb +1 -1
- data/lib/eth/chain.rb +9 -1
- data/lib/eth/client/http.rb +7 -3
- data/lib/eth/client/ipc.rb +1 -1
- data/lib/eth/client.rb +38 -37
- data/lib/eth/constant.rb +1 -1
- data/lib/eth/contract/error.rb +62 -0
- data/lib/eth/contract/event.rb +69 -16
- data/lib/eth/contract/function.rb +22 -1
- data/lib/eth/contract/function_input.rb +1 -1
- data/lib/eth/contract/function_output.rb +12 -4
- data/lib/eth/contract/initializer.rb +1 -1
- data/lib/eth/contract.rb +56 -5
- data/lib/eth/eip712.rb +49 -13
- data/lib/eth/ens/coin_type.rb +1 -1
- data/lib/eth/ens/resolver.rb +1 -1
- data/lib/eth/ens.rb +1 -1
- data/lib/eth/key/decrypter.rb +1 -1
- data/lib/eth/key/encrypter.rb +1 -1
- data/lib/eth/key.rb +2 -2
- data/lib/eth/rlp/decoder.rb +1 -1
- data/lib/eth/rlp/encoder.rb +1 -1
- data/lib/eth/rlp/sedes/big_endian_int.rb +1 -1
- data/lib/eth/rlp/sedes/binary.rb +1 -1
- data/lib/eth/rlp/sedes/list.rb +1 -1
- data/lib/eth/rlp/sedes.rb +1 -1
- data/lib/eth/rlp.rb +1 -1
- data/lib/eth/signature.rb +1 -1
- data/lib/eth/solidity.rb +1 -1
- data/lib/eth/tx/eip1559.rb +33 -8
- data/lib/eth/tx/eip2930.rb +32 -7
- data/lib/eth/tx/eip4844.rb +389 -0
- data/lib/eth/tx/eip7702.rb +520 -0
- data/lib/eth/tx/legacy.rb +31 -7
- data/lib/eth/tx.rb +88 -1
- data/lib/eth/unit.rb +1 -1
- data/lib/eth/util.rb +20 -8
- data/lib/eth/version.rb +2 -2
- data/lib/eth.rb +1 -1
- metadata +26 -16
data/lib/eth/tx.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-
|
1
|
+
# Copyright (c) 2016-2025 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.
|
@@ -17,6 +17,8 @@ require "konstructor"
|
|
17
17
|
require "eth/chain"
|
18
18
|
require "eth/tx/eip1559"
|
19
19
|
require "eth/tx/eip2930"
|
20
|
+
require "eth/tx/eip4844"
|
21
|
+
require "eth/tx/eip7702"
|
20
22
|
require "eth/tx/legacy"
|
21
23
|
require "eth/unit"
|
22
24
|
|
@@ -72,6 +74,12 @@ module Eth
|
|
72
74
|
# The EIP-1559 transaction type is 2.
|
73
75
|
TYPE_1559 = 0x02.freeze
|
74
76
|
|
77
|
+
# The EIP-4844 transaction type is 3.
|
78
|
+
TYPE_4844 = 0x03.freeze
|
79
|
+
|
80
|
+
# The EIP-7702 transaction type is 4.
|
81
|
+
TYPE_7702 = 0x04.freeze
|
82
|
+
|
75
83
|
# The zero byte is 0x00.
|
76
84
|
ZERO_BYTE = "\x00".freeze
|
77
85
|
|
@@ -80,16 +88,32 @@ module Eth
|
|
80
88
|
|
81
89
|
# Creates a new transaction of any type for given parameters and chain ID.
|
82
90
|
# Required parameters are (optional in brackets):
|
91
|
+
# - EIP-4844: chain_id, nonce, priority_fee, max_gas_fee, gas_limit, max_fee_per_blob_gas, blob_versioned_hashes(, from, to,
|
92
|
+
# value, data, access_list)
|
83
93
|
# - EIP-1559: chain_id, nonce, priority_fee, max_gas_fee, gas_limit(, from, to,
|
84
94
|
# value, data, access_list)
|
85
95
|
# - EIP-2930: chain_id, nonce, gas_price, gas_limit, access_list(, from, to,
|
86
96
|
# value, data)
|
97
|
+
# - EIP-7702: chain_id, nonce, priority_fee, max_gas_fee, gas_limit, authorizations(, from, to,
|
98
|
+
# value, data, access_list)
|
87
99
|
# - Legacy: nonce, gas_price, gas_limit(, from, to, value, data)
|
88
100
|
#
|
89
101
|
# @param params [Hash] all necessary transaction fields.
|
90
102
|
# @param chain_id [Integer] the EIP-155 Chain ID (legacy transactions only).
|
91
103
|
def new(params, chain_id = Chain::ETHEREUM)
|
92
104
|
|
105
|
+
# if we deal with blobs, attempt EIP-4844
|
106
|
+
unless params[:max_fee_per_blob_gas].nil?
|
107
|
+
params[:chain_id] = chain_id if params[:chain_id].nil?
|
108
|
+
return Tx::Eip4844.new params
|
109
|
+
end
|
110
|
+
|
111
|
+
# if we deal with authorizations, attempt EIP-7702
|
112
|
+
unless params[:authorization_list].nil?
|
113
|
+
params[:chain_id] = chain_id if params[:chain_id].nil?
|
114
|
+
return Tx::Eip7702.new params
|
115
|
+
end
|
116
|
+
|
93
117
|
# if we deal with max gas fee parameter, attempt EIP-1559
|
94
118
|
unless params[:max_gas_fee].nil?
|
95
119
|
params[:chain_id] = chain_id if params[:chain_id].nil?
|
@@ -115,6 +139,7 @@ module Eth
|
|
115
139
|
def decode(hex)
|
116
140
|
hex = Util.remove_hex_prefix hex
|
117
141
|
type = hex[0, 2].to_i(16)
|
142
|
+
|
118
143
|
case type
|
119
144
|
when TYPE_1559
|
120
145
|
|
@@ -124,6 +149,14 @@ module Eth
|
|
124
149
|
|
125
150
|
# EIP-2930 transaction (type 1)
|
126
151
|
return Tx::Eip2930.decode hex
|
152
|
+
when TYPE_4844
|
153
|
+
|
154
|
+
# EIP-4844 transaction (type 3)
|
155
|
+
return Tx::Eip4844.decode hex
|
156
|
+
when TYPE_7702
|
157
|
+
|
158
|
+
# EIP-7702 transaction (type 4)
|
159
|
+
return Tx::Eip7702.decode hex
|
127
160
|
else
|
128
161
|
|
129
162
|
# Legacy transaction if first byte is RLP (>= 192)
|
@@ -150,6 +183,14 @@ module Eth
|
|
150
183
|
|
151
184
|
# EIP-2930 transaction (type 1)
|
152
185
|
return Tx::Eip2930.unsigned_copy tx
|
186
|
+
when TYPE_4844
|
187
|
+
|
188
|
+
# EIP-4844 transaction (type 3)
|
189
|
+
return Tx::Eip4844.unsigned_copy tx
|
190
|
+
when TYPE_7702
|
191
|
+
|
192
|
+
# EIP-7702 transaction (type 4)
|
193
|
+
return Tx::Eip7702.unsigned_copy tx
|
153
194
|
when TYPE_LEGACY
|
154
195
|
|
155
196
|
# Legacy transaction ("type 0")
|
@@ -241,6 +282,36 @@ module Eth
|
|
241
282
|
return fields
|
242
283
|
end
|
243
284
|
|
285
|
+
# Validates that the type-3 transaction blob fields are present
|
286
|
+
#
|
287
|
+
# @param fields [Hash] the transaction fields.
|
288
|
+
# @return [Hash] the validated transaction fields.
|
289
|
+
# @raise [ParameterError] if max blob fee or blob hashes are invalid.
|
290
|
+
def validate_eip4844_params(fields)
|
291
|
+
if fields[:max_fee_per_blob_gas].nil? or fields[:max_fee_per_blob_gas] < 0
|
292
|
+
raise ParameterError, "Invalid max blob fee #{fields[:max_fee_per_blob_gas]}!"
|
293
|
+
end
|
294
|
+
if fields[:blob_versioned_hashes].nil? or !fields[:blob_versioned_hashes].is_a? Array or fields[:blob_versioned_hashes].empty?
|
295
|
+
raise ParameterError, "Invalid blob versioned hashes #{fields[:blob_versioned_hashes]}!"
|
296
|
+
end
|
297
|
+
if fields[:to].nil? or fields[:to].empty?
|
298
|
+
raise ParameterError, "Invalid destination address #{fields[:to]}!"
|
299
|
+
end
|
300
|
+
return fields
|
301
|
+
end
|
302
|
+
|
303
|
+
# Validates that the type-4 transaction field authorization list is present
|
304
|
+
#
|
305
|
+
# @param fields [Hash] the transaction fields.
|
306
|
+
# @return [Hash] the validated transaction fields.
|
307
|
+
# @raise [ParameterError] if authorization list is missing.
|
308
|
+
def validate_eip7702_params(fields)
|
309
|
+
unless fields[:authorization_list].nil? or fields[:authorization_list].is_a? Array
|
310
|
+
raise ParameterError, "Invalid authorization list #{fields[:authorization_list]}!"
|
311
|
+
end
|
312
|
+
return fields
|
313
|
+
end
|
314
|
+
|
244
315
|
# Validates the common legacy transaction fields such as gas price.
|
245
316
|
#
|
246
317
|
# @param fields [Hash] the transaction fields.
|
@@ -323,6 +394,22 @@ module Eth
|
|
323
394
|
return list
|
324
395
|
end
|
325
396
|
|
397
|
+
# Populates the blob versioned hashes field with a serializable empty
|
398
|
+
# array in case it is undefined; also ensures the hashes are binary
|
399
|
+
# not hex.
|
400
|
+
#
|
401
|
+
# @param list [Array] the blob versioned hashes.
|
402
|
+
# @return [Array] the sanitized blob versioned hashes.
|
403
|
+
def sanitize_hashes(list)
|
404
|
+
list = [] if list.nil?
|
405
|
+
list.each_with_index do |value, index|
|
406
|
+
if Util.hex? value
|
407
|
+
list[index] = Util.hex_to_bin value
|
408
|
+
end
|
409
|
+
end
|
410
|
+
return list
|
411
|
+
end
|
412
|
+
|
326
413
|
# Allows to check wether a transaction is signed already.
|
327
414
|
#
|
328
415
|
# @return [Bool] true if transaction is already signed.
|
data/lib/eth/unit.rb
CHANGED
data/lib/eth/util.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-
|
1
|
+
# Copyright (c) 2016-2025 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.
|
@@ -72,8 +72,7 @@ module Eth
|
|
72
72
|
# @param hex [String] a hex-string to be prefixed.
|
73
73
|
# @return [String] a prefixed hex-string.
|
74
74
|
def prefix_hex(hex)
|
75
|
-
|
76
|
-
return "0x#{hex}"
|
75
|
+
"0x#{remove_hex_prefix hex}"
|
77
76
|
end
|
78
77
|
|
79
78
|
# Removes the `0x` prefix of a hexa-decimal string.
|
@@ -93,12 +92,12 @@ module Eth
|
|
93
92
|
prefix_hex bin_to_hex bin
|
94
93
|
end
|
95
94
|
|
96
|
-
# Checks if a string is
|
95
|
+
# Checks if a string is hexadecimal.
|
97
96
|
#
|
98
97
|
# @param str [String] a string to be checked.
|
99
|
-
# @return [
|
98
|
+
# @return [MatchData, nil] a match if true; `nil` if not.
|
100
99
|
def hex?(str)
|
101
|
-
return
|
100
|
+
return unless str.is_a? String
|
102
101
|
str = remove_hex_prefix str
|
103
102
|
str.match /\A[0-9a-fA-F]*\z/
|
104
103
|
end
|
@@ -108,7 +107,7 @@ module Eth
|
|
108
107
|
# @param hex [String] a string to be checked.
|
109
108
|
# @return [String] a match if true; `nil` if not.
|
110
109
|
def prefixed?(hex)
|
111
|
-
hex.match /\A0x/
|
110
|
+
hex.match /\A0x/i
|
112
111
|
end
|
113
112
|
|
114
113
|
# Serializes an unsigned integer to big endian.
|
@@ -129,7 +128,11 @@ module Eth
|
|
129
128
|
# @param num [Integer] integer to be converted.
|
130
129
|
# @return [String] packed, big-endian integer string.
|
131
130
|
def int_to_big_endian(num)
|
132
|
-
hex =
|
131
|
+
hex = if hex? num
|
132
|
+
remove_hex_prefix num
|
133
|
+
else
|
134
|
+
num.to_s(16)
|
135
|
+
end
|
133
136
|
hex = "0#{hex}" if hex.size.odd?
|
134
137
|
hex_to_bin hex
|
135
138
|
end
|
@@ -142,6 +145,15 @@ module Eth
|
|
142
145
|
Rlp::Sedes.big_endian_int.deserialize str.sub(/\A(\x00)+/, "")
|
143
146
|
end
|
144
147
|
|
148
|
+
# Deserializes an RLP integer, enforcing minimal encoding.
|
149
|
+
#
|
150
|
+
# @param str [String] serialized big endian integer string.
|
151
|
+
# @return [Integer] a deserialized unsigned integer.
|
152
|
+
# @raise [Rlp::DeserializationError] if encoding is not minimal.
|
153
|
+
def deserialize_rlp_int(str)
|
154
|
+
Rlp::Sedes.big_endian_int.deserialize str
|
155
|
+
end
|
156
|
+
|
145
157
|
# Converts a big endian to an interger.
|
146
158
|
#
|
147
159
|
# @param str [String] big endian to be converted.
|
data/lib/eth/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-
|
1
|
+
# Copyright (c) 2016-2025 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.
|
@@ -22,7 +22,7 @@ module Eth
|
|
22
22
|
MINOR = 5.freeze
|
23
23
|
|
24
24
|
# Defines the patch version of the {Eth} module.
|
25
|
-
PATCH =
|
25
|
+
PATCH = 15.freeze
|
26
26
|
|
27
27
|
# Defines the version string of the {Eth} module.
|
28
28
|
VERSION = [MAJOR, MINOR, PATCH].join(".").freeze
|
data/lib/eth.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Ellis
|
8
8
|
- Afri Schoedon
|
9
|
-
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bigdecimal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: forwardable
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,22 +84,16 @@ dependencies:
|
|
71
84
|
name: openssl
|
72
85
|
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- - "
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '2.2'
|
77
|
-
- - "<"
|
87
|
+
- - "~>"
|
78
88
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
89
|
+
version: '3.3'
|
80
90
|
type: :runtime
|
81
91
|
prerelease: false
|
82
92
|
version_requirements: !ruby/object:Gem::Requirement
|
83
93
|
requirements:
|
84
|
-
- - "
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: '2.2'
|
87
|
-
- - "<"
|
94
|
+
- - "~>"
|
88
95
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
96
|
+
version: '3.3'
|
90
97
|
- !ruby/object:Gem::Dependency
|
91
98
|
name: scrypt
|
92
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +144,8 @@ files:
|
|
137
144
|
- lib/eth/abi/decoder.rb
|
138
145
|
- lib/eth/abi/encoder.rb
|
139
146
|
- lib/eth/abi/event.rb
|
147
|
+
- lib/eth/abi/function.rb
|
148
|
+
- lib/eth/abi/packed/encoder.rb
|
140
149
|
- lib/eth/abi/type.rb
|
141
150
|
- lib/eth/address.rb
|
142
151
|
- lib/eth/api.rb
|
@@ -146,6 +155,7 @@ files:
|
|
146
155
|
- lib/eth/client/ipc.rb
|
147
156
|
- lib/eth/constant.rb
|
148
157
|
- lib/eth/contract.rb
|
158
|
+
- lib/eth/contract/error.rb
|
149
159
|
- lib/eth/contract/event.rb
|
150
160
|
- lib/eth/contract/function.rb
|
151
161
|
- lib/eth/contract/function_input.rb
|
@@ -170,6 +180,8 @@ files:
|
|
170
180
|
- lib/eth/tx.rb
|
171
181
|
- lib/eth/tx/eip1559.rb
|
172
182
|
- lib/eth/tx/eip2930.rb
|
183
|
+
- lib/eth/tx/eip4844.rb
|
184
|
+
- lib/eth/tx/eip7702.rb
|
173
185
|
- lib/eth/tx/legacy.rb
|
174
186
|
- lib/eth/unit.rb
|
175
187
|
- lib/eth/util.rb
|
@@ -183,7 +195,6 @@ metadata:
|
|
183
195
|
documentation_uri: https://q9f.github.io/eth.rb/
|
184
196
|
github_repo: https://github.com/q9f/eth.rb
|
185
197
|
source_code_uri: https://github.com/q9f/eth.rb
|
186
|
-
post_install_message:
|
187
198
|
rdoc_options: []
|
188
199
|
require_paths:
|
189
200
|
- lib
|
@@ -202,8 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
213
|
- !ruby/object:Gem::Version
|
203
214
|
version: '0'
|
204
215
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
206
|
-
signing_key:
|
216
|
+
rubygems_version: 3.6.7
|
207
217
|
specification_version: 4
|
208
218
|
summary: Ruby Ethereum library.
|
209
219
|
test_files: []
|