eth 0.5.1 → 0.5.4
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/spec.yml +3 -3
- data/AUTHORS.txt +10 -2
- data/CHANGELOG.md +29 -6
- data/README.md +94 -23
- data/codecov.yml +6 -0
- data/eth.gemspec +1 -1
- data/lib/eth/abi/event.rb +137 -0
- data/lib/eth/abi/type.rb +1 -1
- data/lib/eth/abi.rb +14 -2
- data/lib/eth/chain.rb +1 -1
- data/lib/eth/client/ipc.rb +3 -0
- data/lib/eth/client.rb +240 -1
- data/lib/eth/contract/event.rb +41 -0
- data/lib/eth/contract/function.rb +56 -0
- data/lib/eth/contract/function_input.rb +36 -0
- data/lib/eth/contract/function_output.rb +32 -0
- data/lib/eth/contract/initializer.rb +46 -0
- data/lib/eth/contract.rb +135 -0
- data/lib/eth/rlp/decoder.rb +7 -2
- data/lib/eth/rlp/sedes/binary.rb +2 -2
- data/lib/eth/solidity.rb +75 -0
- data/lib/eth/tx/eip1559.rb +1 -0
- data/lib/eth/tx/eip2930.rb +1 -0
- data/lib/eth/tx/legacy.rb +1 -0
- data/lib/eth/tx.rb +24 -29
- data/lib/eth/version.rb +1 -1
- data/lib/eth.rb +7 -0
- metadata +20 -5
data/lib/eth/solidity.rb
ADDED
@@ -0,0 +1,75 @@
|
|
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
|
+
require "open3"
|
16
|
+
|
17
|
+
# Provides the {Eth} module.
|
18
|
+
module Eth
|
19
|
+
|
20
|
+
# Class to create {Solidity} compiler bingings for Ruby.
|
21
|
+
class Solidity
|
22
|
+
|
23
|
+
# Provides a Compiler Error in case the contract does not compile.
|
24
|
+
class CompilerError < StandardError; end
|
25
|
+
|
26
|
+
# Solidity compiler binary path.
|
27
|
+
attr_reader :compiler
|
28
|
+
|
29
|
+
# Instantiates a Solidity `solc` system compiler binding that can be
|
30
|
+
# used to compile Solidity contracts.
|
31
|
+
def initialize
|
32
|
+
|
33
|
+
# Currently only supports `solc`.
|
34
|
+
solc = get_compiler_path
|
35
|
+
raise SystemCallError, "Unable to find the solc compiler path!" if solc.nil?
|
36
|
+
@compiler = solc
|
37
|
+
end
|
38
|
+
|
39
|
+
# Use the bound Solidity executable to compile the given contract.
|
40
|
+
#
|
41
|
+
# @param contract [String] path of the contract to compile.
|
42
|
+
# @return [Array] JSON containing the compiled contract and ABI for all contracts.
|
43
|
+
def compile(contract)
|
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
|
47
|
+
raise SystemCallError, "Unable to run solc compiler!" if status.exitstatus === 127
|
48
|
+
raise CompilerError, error unless status.success?
|
49
|
+
json = JSON.parse output
|
50
|
+
result = {}
|
51
|
+
json["contracts"].each do |key, value|
|
52
|
+
_file, name = key.split ":"
|
53
|
+
result[name] = {}
|
54
|
+
result[name]["abi"] = value["abi"]
|
55
|
+
result[name]["bin"] = value["bin"]
|
56
|
+
end
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# Tries to find a system executable path for the given compiler binary name.
|
63
|
+
def get_compiler_path(name = "solc")
|
64
|
+
extensions = [""]
|
65
|
+
extensions = ENV["PATHEXT"].split(";") unless ENV["PATHEXT"].nil?
|
66
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
67
|
+
extensions.each do |ext|
|
68
|
+
executable = File.join path, "#{name}#{ext}"
|
69
|
+
return executable if File.executable? executable and !File.directory? executable
|
70
|
+
end
|
71
|
+
end
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/eth/tx/eip1559.rb
CHANGED
data/lib/eth/tx/eip2930.rb
CHANGED
@@ -92,6 +92,7 @@ module Eth
|
|
92
92
|
fields[:data] = Tx.sanitize_data fields[:data]
|
93
93
|
|
94
94
|
# ensure sane values for all mandatory fields
|
95
|
+
fields = Tx.validate_params fields
|
95
96
|
fields = Tx.validate_legacy_params fields
|
96
97
|
fields[:access_list] = Tx.sanitize_list fields[:access_list]
|
97
98
|
|
data/lib/eth/tx/legacy.rb
CHANGED
data/lib/eth/tx.rb
CHANGED
@@ -69,13 +69,16 @@ module Eth
|
|
69
69
|
# The zero byte is 0x00.
|
70
70
|
ZERO_BYTE = "\x00".freeze
|
71
71
|
|
72
|
+
# Smart contract transaction gas cost
|
73
|
+
CREATE_GAS = 32_000.freeze
|
74
|
+
|
72
75
|
# Creates a new transaction of any type for given parameters and chain ID.
|
73
76
|
# Required parameters are (optional in brackets):
|
74
77
|
# - EIP-1559: chain_id, nonce, priority_fee, max_gas_fee, gas_limit(, from, to,
|
75
78
|
# value, data, access_list)
|
76
79
|
# - EIP-2930: chain_id, nonce, gas_price, gas_limit, access_list(, from, to,
|
77
80
|
# value, data)
|
78
|
-
# - Legacy: nonce, gas_price,
|
81
|
+
# - Legacy: nonce, gas_price, gas_limit(, from, to, value, data)
|
79
82
|
#
|
80
83
|
# @param params [Hash] all necessary transaction fields.
|
81
84
|
# @param chain_id [Integer] the EIP-155 Chain ID (legacy transactions only).
|
@@ -184,14 +187,12 @@ module Eth
|
|
184
187
|
return gas
|
185
188
|
end
|
186
189
|
|
187
|
-
# Validates the common
|
188
|
-
#
|
190
|
+
# Validates the common transaction fields such as nonce, gas limit,
|
191
|
+
# amount, and access list.
|
189
192
|
#
|
190
193
|
# @param fields [Hash] the transaction fields.
|
191
194
|
# @return [Hash] the validated transaction fields.
|
192
195
|
# @raise [ParameterError] if nonce is an invalid integer.
|
193
|
-
# @raise [ParameterError] if priority fee is invalid.
|
194
|
-
# @raise [ParameterError] if max gas fee is invalid.
|
195
196
|
# @raise [ParameterError] if gas limit is invalid.
|
196
197
|
# @raise [ParameterError] if amount is invalid.
|
197
198
|
# @raise [ParameterError] if access list is invalid.
|
@@ -199,12 +200,6 @@ module Eth
|
|
199
200
|
if fields[:nonce].nil? or fields[:nonce] < 0
|
200
201
|
raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!"
|
201
202
|
end
|
202
|
-
if fields[:priority_fee].nil? or fields[:priority_fee] < 0
|
203
|
-
raise ParameterError, "Invalid gas priority fee #{fields[:priority_fee]}!"
|
204
|
-
end
|
205
|
-
if fields[:max_gas_fee].nil? or fields[:max_gas_fee] < 0
|
206
|
-
raise ParameterError, "Invalid max gas fee #{fields[:max_gas_fee]}!"
|
207
|
-
end
|
208
203
|
if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT
|
209
204
|
raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!"
|
210
205
|
end
|
@@ -217,32 +212,32 @@ module Eth
|
|
217
212
|
return fields
|
218
213
|
end
|
219
214
|
|
220
|
-
# Validates the common
|
221
|
-
#
|
215
|
+
# Validates the common type-2 transaction fields such as priority
|
216
|
+
# fee and max gas fee.
|
217
|
+
#
|
218
|
+
# @param fields [Hash] the transaction fields.
|
219
|
+
# @return [Hash] the validated transaction fields.
|
220
|
+
# @raise [ParameterError] if priority fee is invalid.
|
221
|
+
# @raise [ParameterError] if max gas fee is invalid.
|
222
|
+
def validate_eip1559_params(fields)
|
223
|
+
if fields[:priority_fee].nil? or fields[:priority_fee] < 0
|
224
|
+
raise ParameterError, "Invalid gas priority fee #{fields[:priority_fee]}!"
|
225
|
+
end
|
226
|
+
if fields[:max_gas_fee].nil? or fields[:max_gas_fee] < 0
|
227
|
+
raise ParameterError, "Invalid max gas fee #{fields[:max_gas_fee]}!"
|
228
|
+
end
|
229
|
+
return fields
|
230
|
+
end
|
231
|
+
|
232
|
+
# Validates the common legacy transaction fields such as gas price.
|
222
233
|
#
|
223
234
|
# @param fields [Hash] the transaction fields.
|
224
235
|
# @return [Hash] the validated transaction fields.
|
225
|
-
# @raise [ParameterError] if nonce is an invalid integer.
|
226
236
|
# @raise [ParameterError] if gas price is invalid.
|
227
|
-
# @raise [ParameterError] if gas limit is invalid.
|
228
|
-
# @raise [ParameterError] if amount is invalid.
|
229
|
-
# @raise [ParameterError] if access list is invalid.
|
230
237
|
def validate_legacy_params(fields)
|
231
|
-
if fields[:nonce].nil? or fields[:nonce] < 0
|
232
|
-
raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!"
|
233
|
-
end
|
234
238
|
if fields[:gas_price].nil? or fields[:gas_price] < 0
|
235
239
|
raise ParameterError, "Invalid gas price #{fields[:gas_price]}!"
|
236
240
|
end
|
237
|
-
if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT
|
238
|
-
raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!"
|
239
|
-
end
|
240
|
-
unless fields[:value] >= 0
|
241
|
-
raise ParameterError, "Invalid transaction value #{fields[:value]}!"
|
242
|
-
end
|
243
|
-
unless fields[:access_list].nil? or fields[:access_list].is_a? Array
|
244
|
-
raise ParameterError, "Invalid access list #{fields[:access_list]}!"
|
245
|
-
end
|
246
241
|
return fields
|
247
242
|
end
|
248
243
|
|
data/lib/eth/version.rb
CHANGED
data/lib/eth.rb
CHANGED
@@ -22,6 +22,12 @@ require "eth/api"
|
|
22
22
|
require "eth/address"
|
23
23
|
require "eth/chain"
|
24
24
|
require "eth/constant"
|
25
|
+
require "eth/contract"
|
26
|
+
require "eth/contract/event"
|
27
|
+
require "eth/contract/function"
|
28
|
+
require "eth/contract/function_input"
|
29
|
+
require "eth/contract/function_output"
|
30
|
+
require "eth/contract/initializer"
|
25
31
|
require "eth/client"
|
26
32
|
require "eth/client/http"
|
27
33
|
require "eth/client/ipc"
|
@@ -29,6 +35,7 @@ require "eth/eip712"
|
|
29
35
|
require "eth/key"
|
30
36
|
require "eth/rlp"
|
31
37
|
require "eth/signature"
|
38
|
+
require "eth/solidity"
|
32
39
|
require "eth/tx"
|
33
40
|
require "eth/unit"
|
34
41
|
require "eth/util"
|
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.4
|
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-
|
12
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keccak
|
@@ -57,16 +57,22 @@ dependencies:
|
|
57
57
|
name: openssl
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '2.2'
|
63
|
+
- - "<"
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '4.0'
|
63
66
|
type: :runtime
|
64
67
|
prerelease: false
|
65
68
|
version_requirements: !ruby/object:Gem::Requirement
|
66
69
|
requirements:
|
67
|
-
- - "
|
70
|
+
- - ">="
|
68
71
|
- !ruby/object:Gem::Version
|
69
72
|
version: '2.2'
|
73
|
+
- - "<"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
70
76
|
- !ruby/object:Gem::Dependency
|
71
77
|
name: scrypt
|
72
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,9 +110,11 @@ files:
|
|
104
110
|
- Rakefile
|
105
111
|
- bin/console
|
106
112
|
- bin/setup
|
113
|
+
- codecov.yml
|
107
114
|
- eth.gemspec
|
108
115
|
- lib/eth.rb
|
109
116
|
- lib/eth/abi.rb
|
117
|
+
- lib/eth/abi/event.rb
|
110
118
|
- lib/eth/abi/type.rb
|
111
119
|
- lib/eth/address.rb
|
112
120
|
- lib/eth/api.rb
|
@@ -115,6 +123,12 @@ files:
|
|
115
123
|
- lib/eth/client/http.rb
|
116
124
|
- lib/eth/client/ipc.rb
|
117
125
|
- lib/eth/constant.rb
|
126
|
+
- lib/eth/contract.rb
|
127
|
+
- lib/eth/contract/event.rb
|
128
|
+
- lib/eth/contract/function.rb
|
129
|
+
- lib/eth/contract/function_input.rb
|
130
|
+
- lib/eth/contract/function_output.rb
|
131
|
+
- lib/eth/contract/initializer.rb
|
118
132
|
- lib/eth/eip712.rb
|
119
133
|
- lib/eth/key.rb
|
120
134
|
- lib/eth/key/decrypter.rb
|
@@ -127,6 +141,7 @@ files:
|
|
127
141
|
- lib/eth/rlp/sedes/binary.rb
|
128
142
|
- lib/eth/rlp/sedes/list.rb
|
129
143
|
- lib/eth/signature.rb
|
144
|
+
- lib/eth/solidity.rb
|
130
145
|
- lib/eth/tx.rb
|
131
146
|
- lib/eth/tx/eip1559.rb
|
132
147
|
- lib/eth/tx/eip2930.rb
|
@@ -161,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
176
|
- !ruby/object:Gem::Version
|
162
177
|
version: '0'
|
163
178
|
requirements: []
|
164
|
-
rubygems_version: 3.3.
|
179
|
+
rubygems_version: 3.3.8
|
165
180
|
signing_key:
|
166
181
|
specification_version: 4
|
167
182
|
summary: Ruby Ethereum library.
|