eth 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql.yml +4 -0
- data/.github/workflows/spec.yml +14 -3
- data/.yardopts +1 -0
- data/AUTHORS.txt +5 -0
- data/CHANGELOG.md +63 -13
- data/README.md +57 -2
- data/bin/console +2 -1
- data/bin/setup +3 -4
- data/eth.gemspec +5 -7
- data/lib/eth/abi/type.rb +8 -7
- data/lib/eth/abi.rb +17 -11
- data/lib/eth/address.rb +12 -5
- data/lib/eth/api.rb +223 -0
- data/lib/eth/chain.rb +31 -28
- data/lib/eth/client/http.rb +63 -0
- data/lib/eth/client/ipc.rb +47 -0
- data/lib/eth/client.rb +232 -0
- data/lib/eth/constant.rb +71 -0
- data/lib/eth/eip712.rb +2 -2
- data/lib/eth/key/decrypter.rb +16 -13
- data/lib/eth/key/encrypter.rb +27 -25
- data/lib/eth/key.rb +21 -16
- data/lib/eth/rlp/decoder.rb +109 -0
- data/lib/eth/rlp/encoder.rb +78 -0
- data/lib/eth/rlp/sedes/big_endian_int.rb +66 -0
- data/lib/eth/rlp/sedes/binary.rb +97 -0
- data/lib/eth/rlp/sedes/list.rb +84 -0
- data/lib/eth/rlp/sedes.rb +74 -0
- data/lib/eth/rlp.rb +63 -0
- data/lib/eth/signature.rb +11 -8
- data/lib/eth/tx/eip1559.rb +21 -14
- data/lib/eth/tx/eip2930.rb +22 -15
- data/lib/eth/tx/legacy.rb +13 -10
- data/lib/eth/tx.rb +9 -10
- data/lib/eth/unit.rb +1 -1
- data/lib/eth/util.rb +68 -11
- data/lib/eth/version.rb +3 -3
- data/lib/eth.rb +8 -2
- metadata +22 -23
- data/lib/eth/abi/constant.rb +0 -63
data/lib/eth/tx.rb
CHANGED
@@ -12,7 +12,6 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require "rlp"
|
16
15
|
require "konstructor"
|
17
16
|
|
18
17
|
require "eth/chain"
|
@@ -21,14 +20,14 @@ require "eth/tx/eip2930"
|
|
21
20
|
require "eth/tx/legacy"
|
22
21
|
require "eth/unit"
|
23
22
|
|
24
|
-
# Provides the
|
23
|
+
# Provides the {Eth} module.
|
25
24
|
module Eth
|
26
25
|
|
27
26
|
# Provides the `Tx` module supporting various transaction types.
|
28
27
|
module Tx
|
29
28
|
extend self
|
30
29
|
|
31
|
-
# Provides a special
|
30
|
+
# Provides a special transaction error if transaction type is unknown.
|
32
31
|
class TransactionTypeError < TypeError; end
|
33
32
|
|
34
33
|
# Provides an decoder error if transaction cannot be decoded.
|
@@ -197,16 +196,16 @@ module Eth
|
|
197
196
|
# @raise [ParameterError] if amount is invalid.
|
198
197
|
# @raise [ParameterError] if access list is invalid.
|
199
198
|
def validate_params(fields)
|
200
|
-
|
199
|
+
if fields[:nonce].nil? or fields[:nonce] < 0
|
201
200
|
raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!"
|
202
201
|
end
|
203
|
-
|
202
|
+
if fields[:priority_fee].nil? or fields[:priority_fee] < 0
|
204
203
|
raise ParameterError, "Invalid gas priority fee #{fields[:priority_fee]}!"
|
205
204
|
end
|
206
|
-
|
205
|
+
if fields[:max_gas_fee].nil? or fields[:max_gas_fee] < 0
|
207
206
|
raise ParameterError, "Invalid max gas fee #{fields[:max_gas_fee]}!"
|
208
207
|
end
|
209
|
-
|
208
|
+
if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT
|
210
209
|
raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!"
|
211
210
|
end
|
212
211
|
unless fields[:value] >= 0
|
@@ -229,13 +228,13 @@ module Eth
|
|
229
228
|
# @raise [ParameterError] if amount is invalid.
|
230
229
|
# @raise [ParameterError] if access list is invalid.
|
231
230
|
def validate_legacy_params(fields)
|
232
|
-
|
231
|
+
if fields[:nonce].nil? or fields[:nonce] < 0
|
233
232
|
raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!"
|
234
233
|
end
|
235
|
-
|
234
|
+
if fields[:gas_price].nil? or fields[:gas_price] < 0
|
236
235
|
raise ParameterError, "Invalid gas price #{fields[:gas_price]}!"
|
237
236
|
end
|
238
|
-
|
237
|
+
if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT
|
239
238
|
raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!"
|
240
239
|
end
|
241
240
|
unless fields[:value] >= 0
|
data/lib/eth/unit.rb
CHANGED
data/lib/eth/util.rb
CHANGED
@@ -13,12 +13,11 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require "digest/keccak"
|
16
|
-
require "rlp"
|
17
16
|
|
18
|
-
# Provides the
|
17
|
+
# Provides the {Eth} module.
|
19
18
|
module Eth
|
20
19
|
|
21
|
-
# Defines handy tools for the
|
20
|
+
# Defines handy tools for the {Eth} gem for convenience.
|
22
21
|
module Util
|
23
22
|
extend self
|
24
23
|
|
@@ -93,7 +92,7 @@ module Eth
|
|
93
92
|
# Checks if a string is hex-adecimal.
|
94
93
|
#
|
95
94
|
# @param str [String] a string to be checked.
|
96
|
-
# @return [String] a match if true; nil if not.
|
95
|
+
# @return [String] a match if true; `nil` if not.
|
97
96
|
def is_hex?(str)
|
98
97
|
return false unless str.is_a? String
|
99
98
|
str = remove_hex_prefix str
|
@@ -103,7 +102,7 @@ module Eth
|
|
103
102
|
# Checks if a string is prefixed with `0x`.
|
104
103
|
#
|
105
104
|
# @param hex [String] a string to be checked.
|
106
|
-
# @return [String] a match if true; nil if not.
|
105
|
+
# @return [String] a match if true; `nil` if not.
|
107
106
|
def is_prefixed?(hex)
|
108
107
|
hex.match /\A0x/
|
109
108
|
end
|
@@ -111,14 +110,24 @@ module Eth
|
|
111
110
|
# Serializes an unsigned integer to big endian.
|
112
111
|
#
|
113
112
|
# @param num [Integer] unsigned integer to be serialized.
|
114
|
-
# return [String] serialized big endian integer string.
|
115
|
-
#
|
113
|
+
# @return [String] serialized big endian integer string.
|
114
|
+
# @raise [ArgumentError] if unsigned integer is out of bounds.
|
116
115
|
def serialize_int_to_big_endian(num)
|
117
116
|
num = num.to_i(16) if is_hex? num
|
118
|
-
unless num.is_a? Integer and num >= 0 and num <=
|
117
|
+
unless num.is_a? Integer and num >= 0 and num <= Constant::UINT_MAX
|
119
118
|
raise ArgumentError, "Integer invalid or out of range: #{num}"
|
120
119
|
end
|
121
|
-
|
120
|
+
Rlp::Sedes.big_endian_int.serialize num
|
121
|
+
end
|
122
|
+
|
123
|
+
# Converts an integer to big endian.
|
124
|
+
#
|
125
|
+
# @param num [Integer] integer to be converted.
|
126
|
+
# @return [String] packed, big-endian integer string.
|
127
|
+
def int_to_big_endian(num)
|
128
|
+
hex = num.to_s(16) unless is_hex? num
|
129
|
+
hex = "0#{hex}" if hex.size.odd?
|
130
|
+
hex_to_bin hex
|
122
131
|
end
|
123
132
|
|
124
133
|
# Deserializes big endian data string to integer.
|
@@ -126,7 +135,55 @@ module Eth
|
|
126
135
|
# @param str [String] serialized big endian integer string.
|
127
136
|
# @return [Integer] an deserialized unsigned integer.
|
128
137
|
def deserialize_big_endian_to_int(str)
|
129
|
-
|
138
|
+
Rlp::Sedes.big_endian_int.deserialize str.sub(/\A(\x00)+/, "")
|
139
|
+
end
|
140
|
+
|
141
|
+
# Converts a big endian to an interger.
|
142
|
+
#
|
143
|
+
# @param str [String] big endian to be converted.
|
144
|
+
# @return [Integer] an unpacked integer number.
|
145
|
+
def big_endian_to_int(str)
|
146
|
+
str.unpack("H*").first.to_i(16)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Converts a binary string to bytes.
|
150
|
+
#
|
151
|
+
# @param str [String] binary string to be converted.
|
152
|
+
# @return [Object] the string bytes.
|
153
|
+
def str_to_bytes(str)
|
154
|
+
is_bytes?(str) ? str : str.b
|
155
|
+
end
|
156
|
+
|
157
|
+
# Converts bytes to a binary string.
|
158
|
+
#
|
159
|
+
# @param bin [Object] bytes to be converted.
|
160
|
+
# @return [String] a packed binary string.
|
161
|
+
def bytes_to_str(bin)
|
162
|
+
bin.unpack("U*").pack("U*")
|
163
|
+
end
|
164
|
+
|
165
|
+
# Checks if a string is a byte-string.
|
166
|
+
#
|
167
|
+
# @param str [String] a string to check.
|
168
|
+
# @return [Boolean] true if it's an ASCII-8bit encoded byte-string.
|
169
|
+
def is_bytes?(str)
|
170
|
+
str && str.instance_of?(String) && str.encoding.name == Constant::BINARY_ENCODING
|
171
|
+
end
|
172
|
+
|
173
|
+
# Checks if the given item is a string primitive.
|
174
|
+
#
|
175
|
+
# @param item [Object] the item to check.
|
176
|
+
# @return [Boolean] true if it's a string primitive.
|
177
|
+
def is_primitive?(item)
|
178
|
+
item.instance_of?(String)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Checks if the given item is a list.
|
182
|
+
#
|
183
|
+
# @param item [Object] the item to check.
|
184
|
+
# @return [Boolean] true if it's a list.
|
185
|
+
def is_list?(item)
|
186
|
+
!is_primitive?(item) && item.respond_to?(:each)
|
130
187
|
end
|
131
188
|
|
132
189
|
# Ceil and integer to the next multiple of 32 bytes.
|
@@ -154,7 +211,7 @@ module Eth
|
|
154
211
|
# @param len [Integer] number of symbols for the final string.
|
155
212
|
# @return [String] a zero-padded serialized string of wanted size.
|
156
213
|
def zpad(str, len)
|
157
|
-
lpad str,
|
214
|
+
lpad str, Constant::BYTE_ZERO, len
|
158
215
|
end
|
159
216
|
|
160
217
|
# Left-pad a hex number with zeros.
|
data/lib/eth/version.rb
CHANGED
@@ -12,9 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
# Provides the
|
15
|
+
# Provides the {Eth} module.
|
16
16
|
module Eth
|
17
17
|
|
18
|
-
# Defines the version of the
|
19
|
-
VERSION = "0.5.
|
18
|
+
# Defines the version of the {Eth} module.
|
19
|
+
VERSION = "0.5.1".freeze
|
20
20
|
end
|
data/lib/eth.rb
CHANGED
@@ -12,16 +12,22 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
# Provides the
|
15
|
+
# Provides the {Eth} module.
|
16
16
|
module Eth
|
17
17
|
end
|
18
18
|
|
19
|
-
# Loads the
|
19
|
+
# Loads the {Eth} module classes.
|
20
20
|
require "eth/abi"
|
21
|
+
require "eth/api"
|
21
22
|
require "eth/address"
|
22
23
|
require "eth/chain"
|
24
|
+
require "eth/constant"
|
25
|
+
require "eth/client"
|
26
|
+
require "eth/client/http"
|
27
|
+
require "eth/client/ipc"
|
23
28
|
require "eth/eip712"
|
24
29
|
require "eth/key"
|
30
|
+
require "eth/rlp"
|
25
31
|
require "eth/signature"
|
26
32
|
require "eth/tx"
|
27
33
|
require "eth/unit"
|
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.
|
4
|
+
version: 0.5.1
|
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-01-
|
12
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keccak
|
@@ -53,34 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '5.1'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rlp
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0.7'
|
63
|
-
type: :runtime
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0.7'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
57
|
name: openssl
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
73
59
|
requirements:
|
74
60
|
- - "~>"
|
75
61
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
62
|
+
version: '2.2'
|
77
63
|
type: :runtime
|
78
64
|
prerelease: false
|
79
65
|
version_requirements: !ruby/object:Gem::Requirement
|
80
66
|
requirements:
|
81
67
|
- - "~>"
|
82
68
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
69
|
+
version: '2.2'
|
84
70
|
- !ruby/object:Gem::Dependency
|
85
71
|
name: scrypt
|
86
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,6 +95,7 @@ files:
|
|
109
95
|
- ".gitignore"
|
110
96
|
- ".gitmodules"
|
111
97
|
- ".rspec"
|
98
|
+
- ".yardopts"
|
112
99
|
- AUTHORS.txt
|
113
100
|
- CHANGELOG.md
|
114
101
|
- Gemfile
|
@@ -120,14 +107,25 @@ files:
|
|
120
107
|
- eth.gemspec
|
121
108
|
- lib/eth.rb
|
122
109
|
- lib/eth/abi.rb
|
123
|
-
- lib/eth/abi/constant.rb
|
124
110
|
- lib/eth/abi/type.rb
|
125
111
|
- lib/eth/address.rb
|
112
|
+
- lib/eth/api.rb
|
126
113
|
- lib/eth/chain.rb
|
114
|
+
- lib/eth/client.rb
|
115
|
+
- lib/eth/client/http.rb
|
116
|
+
- lib/eth/client/ipc.rb
|
117
|
+
- lib/eth/constant.rb
|
127
118
|
- lib/eth/eip712.rb
|
128
119
|
- lib/eth/key.rb
|
129
120
|
- lib/eth/key/decrypter.rb
|
130
121
|
- lib/eth/key/encrypter.rb
|
122
|
+
- lib/eth/rlp.rb
|
123
|
+
- lib/eth/rlp/decoder.rb
|
124
|
+
- lib/eth/rlp/encoder.rb
|
125
|
+
- lib/eth/rlp/sedes.rb
|
126
|
+
- lib/eth/rlp/sedes/big_endian_int.rb
|
127
|
+
- lib/eth/rlp/sedes/binary.rb
|
128
|
+
- lib/eth/rlp/sedes/list.rb
|
131
129
|
- lib/eth/signature.rb
|
132
130
|
- lib/eth/tx.rb
|
133
131
|
- lib/eth/tx/eip1559.rb
|
@@ -140,10 +138,11 @@ homepage: https://github.com/q9f/eth.rb
|
|
140
138
|
licenses:
|
141
139
|
- Apache-2.0
|
142
140
|
metadata:
|
143
|
-
homepage_uri: https://github.com/q9f/eth.rb
|
144
|
-
source_code_uri: https://github.com/q9f/eth.rb
|
145
|
-
github_repo: https://github.com/q9f/eth.rb
|
146
141
|
bug_tracker_uri: https://github.com/q9f/eth.rb/issues
|
142
|
+
changelog_uri: https://github.com/q9f/eth.rb/blob/main/CHANGELOG.md
|
143
|
+
documentation_uri: https://q9f.github.io/eth.rb/
|
144
|
+
github_repo: https://github.com/q9f/eth.rb
|
145
|
+
source_code_uri: https://github.com/q9f/eth.rb
|
147
146
|
post_install_message:
|
148
147
|
rdoc_options: []
|
149
148
|
require_paths:
|
@@ -162,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
161
|
- !ruby/object:Gem::Version
|
163
162
|
version: '0'
|
164
163
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.3.5
|
166
165
|
signing_key:
|
167
166
|
specification_version: 4
|
168
167
|
summary: Ruby Ethereum library.
|
data/lib/eth/abi/constant.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-Eth Contributors
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
# -*- encoding : ascii-8bit -*-
|
16
|
-
|
17
|
-
# Provides the `Eth` module.
|
18
|
-
module Eth
|
19
|
-
|
20
|
-
# Provides a Ruby implementation of the Ethereum Applicatoin Binary Interface (ABI).
|
21
|
-
module Abi
|
22
|
-
|
23
|
-
# Provides commonly used constants, such as zero bytes or zero keys.
|
24
|
-
module Constant
|
25
|
-
|
26
|
-
# The empty byte is defined as "".
|
27
|
-
BYTE_EMPTY = "".freeze
|
28
|
-
|
29
|
-
# The zero byte is 0x00.
|
30
|
-
BYTE_ZERO = "\x00".freeze
|
31
|
-
|
32
|
-
# The byte one is 0x01.
|
33
|
-
BYTE_ONE = "\x01".freeze
|
34
|
-
|
35
|
-
# The size of a 32-bit number.
|
36
|
-
TT32 = (2 ** 32).freeze
|
37
|
-
|
38
|
-
# The size of a 256-bit number.
|
39
|
-
TT256 = (2 ** 256).freeze
|
40
|
-
|
41
|
-
# The maximum possible value of an UInt256.
|
42
|
-
UINT_MAX = (2 ** 256 - 1).freeze
|
43
|
-
|
44
|
-
# The minimum possible value of an UInt256.
|
45
|
-
UINT_MIN = 0.freeze
|
46
|
-
|
47
|
-
# The maximum possible value of an Int256.
|
48
|
-
INT_MAX = (2 ** 255 - 1).freeze
|
49
|
-
|
50
|
-
# The minimum possible value of an Int256.
|
51
|
-
INT_MIN = (-2 ** 255).freeze
|
52
|
-
|
53
|
-
# A hash containing only zeros.
|
54
|
-
HASH_ZERO = ("\x00" * 32).freeze
|
55
|
-
|
56
|
-
# A private key containing only zeros.
|
57
|
-
PRIVKEY_ZERO = ("\x00" * 32).freeze
|
58
|
-
|
59
|
-
# A private key containing only zeros (hex).
|
60
|
-
PRIVKEY_ZERO_HEX = ("0" * 64).freeze
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|