eth 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/spec.yml +2 -2
- data/AUTHORS.txt +8 -2
- data/README.md +49 -19
- data/codecov.yml +6 -0
- data/lib/eth/client/ipc.rb +3 -0
- data/lib/eth/rlp/decoder.rb +7 -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 +20 -28
- data/lib/eth/version.rb +1 -1
- data/lib/eth.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16b9900b6e0bd1a0bb51d055b545980685416a1e079590196fa9637e1c3e758e
|
4
|
+
data.tar.gz: db3a4a72a0b14458dee3f4af836ac32bfc6ccf987b22e9f965551ddacecb09de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a00773ef20cdf765c19da284b09f20577fbaf26707d7b425f68109be9d559805603eabfd699c7ff68a56ac8d7619ecdaa841233a0d6af9bbd14521238a18e0
|
7
|
+
data.tar.gz: 80127ab21325d386fbef1e57b13a1a5e769882d174114255b938babfd35c9e84ae3515ae28ace04300dfa38eb2059cb4eb529699378e9c354c5ed73d2ae0c6ce
|
data/.github/workflows/spec.yml
CHANGED
@@ -29,13 +29,13 @@ jobs:
|
|
29
29
|
- name: MacOs Dependencies
|
30
30
|
run: |
|
31
31
|
brew tap ethereum/ethereum
|
32
|
-
brew install --verbose pkg-config automake autogen ethereum
|
32
|
+
brew install --verbose pkg-config automake autogen ethereum solidity
|
33
33
|
if: startsWith(matrix.os, 'macOS')
|
34
34
|
- name: Ubuntu Dependencies
|
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
|
38
|
+
sudo apt-get install ethereum solc
|
39
39
|
if: startsWith(matrix.os, 'Ubuntu')
|
40
40
|
- name: Run Geth
|
41
41
|
run: |
|
data/AUTHORS.txt
CHANGED
@@ -10,12 +10,18 @@ The Ruby-Eth project was maintained 2016-2020 in Steve Ellis's (@se3000)
|
|
10
10
|
repository licensed under MIT conditions:
|
11
11
|
* https://github.com/se3000/ruby-eth
|
12
12
|
|
13
|
-
The latest
|
13
|
+
The latest Ruby-Eth gem is not only a rewrite of the aforementioned gem
|
14
|
+
but also a partial merge of the Ethereum.rb Ruby Ethereum library by
|
15
|
+
Marek Kirejczyk (@marekkirejczyk) and Yuta Kurotaki (@kurotaky) licensed
|
16
|
+
under MIT conditions:
|
17
|
+
* https://github.com/EthWorks/ethereum.rb
|
18
|
+
|
19
|
+
The latest version of the Ruby-Eth gem includes a revised version of the
|
14
20
|
ABI gem by Jan Xie (@janx) and Zhang Yaning (@u2) licensed under MIT
|
15
21
|
conditions:
|
16
22
|
* https://github.com/cryptape/ruby-ethereum-abi
|
17
23
|
|
18
|
-
The latest version of the Ruby-Eth gem contains a
|
24
|
+
The latest version of the Ruby-Eth gem contains a condensed version of the
|
19
25
|
RLP gem by Jan Xie (@janx) and Zhang Yaning (@u2) licensed under MIT
|
20
26
|
conditions:
|
21
27
|
* https://github.com/cryptape/ruby-rlp
|
data/README.md
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# Ethereum for Ruby
|
2
2
|
|
3
3
|
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/q9f/eth.rb/Spec)](https://github.com/q9f/eth.rb/actions)
|
4
4
|
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/q9f/eth.rb)](https://github.com/q9f/eth.rb/releases)
|
5
5
|
[![Gem](https://img.shields.io/gem/v/eth)](https://rubygems.org/gems/eth)
|
6
6
|
[![Gem](https://img.shields.io/gem/dt/eth)](https://rubygems.org/gems/eth)
|
7
|
+
[![Visitors](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fq9f%2Feth.rb&count_bg=%2379C83D&title_bg=%23555555&icon=rubygems.svg&icon_color=%23FF0000&title=visitors&edge_flat=false)](https://hits.seeyoufarm.com)
|
7
8
|
[![codecov](https://codecov.io/gh/q9f/eth.rb/branch/main/graph/badge.svg?token=IK7USBPBZY)](https://codecov.io/gh/q9f/eth.rb)
|
8
9
|
[![Maintainability](https://api.codeclimate.com/v1/badges/469e6f66425198ad7614/maintainability)](https://codeclimate.com/github/q9f/eth.rb/maintainability)
|
9
|
-
[![
|
10
|
-
[![
|
11
|
-
[![
|
10
|
+
[![Top Language](https://img.shields.io/github/languages/top/q9f/eth.rb?color=red)](https://github.com/q9f/eth.rb/pulse)
|
11
|
+
[![Yard Doc API](https://img.shields.io/badge/documentation-API-blue)](https://q9f.github.io/eth.rb)
|
12
|
+
[![Usage Wiki](https://img.shields.io/badge/usage-WIKI-blue)](https://github.com/q9f/eth.rb/wiki)
|
13
|
+
[![Open-Source License](https://img.shields.io/github/license/q9f/eth.rb)](LICENSE)
|
14
|
+
[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/q9f/eth.rb/issues)
|
12
15
|
|
13
|
-
A
|
16
|
+
A straightforward library to build, sign, and broadcast Ethereum transactions. It allows the separation of key and node management. Sign transactions and handle keys anywhere you can run Ruby and broadcast transactions through any local or remote node. Sign messages and recover signatures for authentication.
|
14
17
|
|
15
18
|
What you get:
|
16
19
|
- [x] Secp256k1 Key-Pairs and Encrypted Ethereum Key-Stores (JSON)
|
@@ -25,9 +28,10 @@ What you get:
|
|
25
28
|
- [x] ABI-Encoder and Decoder (including type parser)
|
26
29
|
- [x] RLP-Encoder and Decoder (including sedes)
|
27
30
|
- [x] RPC-Client (IPC/HTTP) for Execution-Layer APIs
|
31
|
+
- [x] Solidity bindings (compile contracts from Ruby)
|
28
32
|
|
29
33
|
Soon (TM):
|
30
|
-
- [ ] Smart
|
34
|
+
- [ ] Smart Contract Support
|
31
35
|
- [ ] EIP-1271 Smart-Contract Authentification
|
32
36
|
- [ ] HD-Wallets (BIP-32) and Mnemonics (BIP-39)
|
33
37
|
|
@@ -41,13 +45,13 @@ Contents:
|
|
41
45
|
- [2.5. Ethereum ABI Encoder and Decoder](#25-ethereum-abi-encoder-and-decoder)
|
42
46
|
- [2.6. Ethereum RLP Encoder and Decoder](#26-ethereum-rlp-encoder-and-decoder)
|
43
47
|
- [2.7. Ethereum RPC-Client](#27-ethereum-rpc-client)
|
48
|
+
- [2.8 Solidity Compiler Bindings](#28-solidity-compiler-bindings)
|
44
49
|
- [3. Documentation](#3-documentation)
|
45
50
|
- [4. Testing](#4-testing)
|
46
51
|
- [5. Contributing](#5-contributing)
|
47
52
|
- [6. License and Credits](#6-license-and-credits)
|
48
53
|
|
49
54
|
## 1. Installation
|
50
|
-
|
51
55
|
Add this line to your application's Gemfile:
|
52
56
|
|
53
57
|
```ruby
|
@@ -61,9 +65,13 @@ gem install eth
|
|
61
65
|
```
|
62
66
|
|
63
67
|
## 2. Usage
|
68
|
+
Check out
|
69
|
+
[![Yard Doc API](https://img.shields.io/badge/documentation-API-blue)](https://q9f.github.io/eth.rb)
|
70
|
+
and
|
71
|
+
[![Usage Wiki](https://img.shields.io/badge/usage-WIKI-blue)](https://github.com/q9f/eth.rb/wiki)
|
72
|
+
for full details.
|
64
73
|
|
65
74
|
### 2.1. Ethereum Keys and Addresses (EIP-55)
|
66
|
-
|
67
75
|
Generate a random Secp256k1 key-pair.
|
68
76
|
|
69
77
|
```ruby
|
@@ -95,7 +103,6 @@ address.checksummed # EIP 55
|
|
95
103
|
See `/spec` or [Documentation](https://q9f.github.io/eth.rb/) for more details about key-pairs, encrypting/decrypting key-stores with a secret, and checksummed addresses.
|
96
104
|
|
97
105
|
### 2.2. Ethereum Signatures (EIP-191, EIP-712)
|
98
|
-
|
99
106
|
Manage keypairs to sign messages in EIP-191 (`personal_sign`) format or typed data in EIP-712 (`sign_typed_data`) format.
|
100
107
|
|
101
108
|
```ruby
|
@@ -127,7 +134,6 @@ Eth::Signature.verify "Hello World!", signature, address, Eth::Chain::GOERLI
|
|
127
134
|
See `/spec` or [Documentation](https://q9f.github.io/eth.rb/) for signing typed data as per EIP-712.
|
128
135
|
|
129
136
|
### 2.3. Ethereum Chains (EIP-155)
|
130
|
-
|
131
137
|
Manage Ethereum chain IDs for EIP-155 replay protection.
|
132
138
|
|
133
139
|
```ruby
|
@@ -142,7 +148,6 @@ chain_id = Eth::Chain.to_chain_id v
|
|
142
148
|
```
|
143
149
|
|
144
150
|
### 2.4. Ethereum Transactions (EIP-1559, EIP-2718, EIP-2930)
|
145
|
-
|
146
151
|
Create an EIP-1559-conform transaction:
|
147
152
|
|
148
153
|
```ruby
|
@@ -169,7 +174,6 @@ tx.hex
|
|
169
174
|
This gem also supports access lists and ABI-encoded data payloads. See `/spec` or [Documentation](https://q9f.github.io/eth.rb/) for more details about the various supported transaction types (legacy, type-1, type-2), payload parameters, and how to estimate intrinsic gas costs.
|
170
175
|
|
171
176
|
### 2.5. Ethereum ABI Encoder and Decoder
|
172
|
-
|
173
177
|
Encode and decode Ethereum application binary interface data (ABI).
|
174
178
|
|
175
179
|
```ruby
|
@@ -180,7 +184,6 @@ Eth::Abi.decode(["string", "address"], "0000000000000000000000000000000000000000
|
|
180
184
|
```
|
181
185
|
|
182
186
|
### 2.6. Ethereum RLP Encoder and Decoder
|
183
|
-
|
184
187
|
Serialize and deserialize Ethereum recursive-length prefix data (RLP).
|
185
188
|
|
186
189
|
```ruby
|
@@ -198,7 +201,6 @@ Eth::Rlp.decode "c7c0c1c0c3c0c1c0"
|
|
198
201
|
```
|
199
202
|
|
200
203
|
### 2.7. Ethereum RPC-Client
|
201
|
-
|
202
204
|
Create an IPC- or HTTP-RPC-API client to seamlessly query the chain state, e.g., Infura over HTTPS with access token:
|
203
205
|
|
204
206
|
```ruby
|
@@ -229,8 +231,29 @@ cli.get_nonce cli.eth_coinbase["result"]
|
|
229
231
|
|
230
232
|
Check out `Eth::Api` for a list of supported RPC-APIs or consult the [Documentation](https://q9f.github.io/eth.rb/) for more details.
|
231
233
|
|
232
|
-
|
234
|
+
### 2.8 Solidity Compiler Bindings
|
235
|
+
Link a system-level Solidity compiler (`solc`) to your Ruby library and compile contracts.
|
233
236
|
|
237
|
+
```ruby
|
238
|
+
solc = Eth::Solidity.new
|
239
|
+
# => #<Eth::Solidity:0x000055f05040c6d0 @compiler="/usr/bin/solc">
|
240
|
+
contract = solc.compile "spec/fixtures/contracts/greeter.sol"
|
241
|
+
# => {"Greeter"=>
|
242
|
+
# {"abi"=>
|
243
|
+
# [{"inputs"=>[{"internalType"=>"string", "name"=>"message", "type"=>"string"}], "stateMutability"=>"nonpayable", "type"=>"constructor"},
|
244
|
+
# {"inputs"=>[], "name"=>"greet", "outputs"=>[{"internalType"=>"string", "name"=>"", "type"=>"string"}], "stateMutability"=>"view", "type"=>"function"},
|
245
|
+
# {"inputs"=>[], "name"=>"kill", "outputs"=>[], "stateMutability"=>"nonpayable", "type"=>"function"}],
|
246
|
+
# "bin"=>
|
247
|
+
# "6080604052348015...6c634300080c0033"},
|
248
|
+
# "Mortal"=>
|
249
|
+
# {"abi"=>[{"inputs"=>[], "stateMutability"=>"nonpayable", "type"=>"constructor"}, {"inputs"=>[], "name"=>"kill", "outputs"=>[], "stateMutability"=>"nonpayable", "type"=>"function"}],
|
250
|
+
# "bin"=>
|
251
|
+
# "6080604052348015...6c634300080c0033"}}
|
252
|
+
```
|
253
|
+
|
254
|
+
The `contract["Greeter"]["bin"]` could be directly used to deploy the contract as `Eth::Tx` payload. Check out the [Documentation](https://q9f.github.io/eth.rb/) for more details.
|
255
|
+
|
256
|
+
## 3. Documentation
|
234
257
|
The documentation can be found at: https://q9f.github.io/eth.rb
|
235
258
|
|
236
259
|
For any specific version, docs can be generated by `yard`:
|
@@ -244,8 +267,13 @@ yard doc
|
|
244
267
|
The goal is to have 100% API documentation available.
|
245
268
|
|
246
269
|
## 4. Testing
|
270
|
+
The test suite expects working local HTTP and IPC endpoints with a prefunded developer account, e.g.:
|
247
271
|
|
248
|
-
|
272
|
+
```shell
|
273
|
+
geth --dev --http --ipcpath /tmp/geth.ipc &
|
274
|
+
```
|
275
|
+
|
276
|
+
To run tests, simply use `rspec`. Note, that the Ethereum test fixtures are also required.
|
249
277
|
|
250
278
|
```shell
|
251
279
|
git submodule update --init --recursive
|
@@ -256,7 +284,6 @@ rspec
|
|
256
284
|
The goal is to have 100% specification coverage for all code inside this gem.
|
257
285
|
|
258
286
|
## 5. Contributing
|
259
|
-
|
260
287
|
Pull requests are welcome! To contribute, please consider the following:
|
261
288
|
* Code should be fully documented. Run `yard doc` and make sure it does not yield any warnings or undocumented sets.
|
262
289
|
* Code should be fully covered by tests. Run `rspec` to make sure all tests pass. The CI has an integration that will assis you to identify uncovered lines of code and get coverage up to 100%.
|
@@ -269,8 +296,11 @@ The `eth` gem is licensed under the conditions of [Apache 2.0](./LICENSE.txt). P
|
|
269
296
|
This gem is a complete rewrite of the old `eth` gem by Steve Ellis.
|
270
297
|
* https://github.com/se3000/ruby-eth/ (MIT)
|
271
298
|
|
272
|
-
It
|
299
|
+
It is not only a rewrite of the `eth` gem but also a partial merge of the `ethereum` gem by Marek Kirejczyk and Yuta Kurotaki.
|
300
|
+
* https://github.com/EthWorks/ethereum.rb (MIT)
|
301
|
+
|
302
|
+
This gem also includes a revised version of the ABI gem by Jan Xie and Zhang Yaning.
|
273
303
|
* https://github.com/cryptape/ruby-ethereum-abi (MIT)
|
274
304
|
|
275
|
-
It also contains a
|
305
|
+
It also contains a condensed version of the RLP gem by Jan Xie and Zhang Yaning.
|
276
306
|
* https://github.com/cryptape/ruby-rlp (MIT)
|
data/codecov.yml
ADDED
data/lib/eth/client/ipc.rb
CHANGED
data/lib/eth/rlp/decoder.rb
CHANGED
@@ -63,7 +63,7 @@ module Eth
|
|
63
63
|
# short string
|
64
64
|
[:str, b0 - Constant::PRIMITIVE_PREFIX_OFFSET, start + 1]
|
65
65
|
elsif b0 < Constant::LIST_PREFIX_OFFSET
|
66
|
-
|
66
|
+
enforce_no_zero_bytes rlp, start
|
67
67
|
|
68
68
|
# long string
|
69
69
|
ll = b0 - Constant::PRIMITIVE_PREFIX_OFFSET - Constant::SHORT_LENGTH_LIMIT + 1
|
@@ -75,7 +75,7 @@ module Eth
|
|
75
75
|
# short list
|
76
76
|
[:list, b0 - Constant::LIST_PREFIX_OFFSET, start + 1]
|
77
77
|
else
|
78
|
-
|
78
|
+
enforce_no_zero_bytes rlp, start
|
79
79
|
|
80
80
|
# long list
|
81
81
|
ll = b0 - Constant::LIST_PREFIX_OFFSET - Constant::SHORT_LENGTH_LIMIT + 1
|
@@ -85,6 +85,11 @@ module Eth
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
# Enforce RLP slices to not start with empty bytes.
|
89
|
+
def enforce_no_zero_bytes(rlp, start)
|
90
|
+
raise DecodingError, "Length starts with zero bytes" if rlp.slice(start + 1) == Constant::BYTE_ZERO
|
91
|
+
end
|
92
|
+
|
88
93
|
# Consume an RLP payload at the given position of given type and size.
|
89
94
|
def consume_payload(rlp, start, type, length)
|
90
95
|
case type
|
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
@@ -184,14 +184,12 @@ module Eth
|
|
184
184
|
return gas
|
185
185
|
end
|
186
186
|
|
187
|
-
# Validates the common
|
188
|
-
#
|
187
|
+
# Validates the common transaction fields such as nonce, gas limit,
|
188
|
+
# amount, and access list.
|
189
189
|
#
|
190
190
|
# @param fields [Hash] the transaction fields.
|
191
191
|
# @return [Hash] the validated transaction fields.
|
192
192
|
# @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
193
|
# @raise [ParameterError] if gas limit is invalid.
|
196
194
|
# @raise [ParameterError] if amount is invalid.
|
197
195
|
# @raise [ParameterError] if access list is invalid.
|
@@ -199,12 +197,6 @@ module Eth
|
|
199
197
|
if fields[:nonce].nil? or fields[:nonce] < 0
|
200
198
|
raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!"
|
201
199
|
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
200
|
if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT
|
209
201
|
raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!"
|
210
202
|
end
|
@@ -217,32 +209,32 @@ module Eth
|
|
217
209
|
return fields
|
218
210
|
end
|
219
211
|
|
220
|
-
# Validates the common
|
221
|
-
#
|
212
|
+
# Validates the common type-2 transaction fields such as priority
|
213
|
+
# fee and max gas fee.
|
214
|
+
#
|
215
|
+
# @param fields [Hash] the transaction fields.
|
216
|
+
# @return [Hash] the validated transaction fields.
|
217
|
+
# @raise [ParameterError] if priority fee is invalid.
|
218
|
+
# @raise [ParameterError] if max gas fee is invalid.
|
219
|
+
def validate_eip1559_params(fields)
|
220
|
+
if fields[:priority_fee].nil? or fields[:priority_fee] < 0
|
221
|
+
raise ParameterError, "Invalid gas priority fee #{fields[:priority_fee]}!"
|
222
|
+
end
|
223
|
+
if fields[:max_gas_fee].nil? or fields[:max_gas_fee] < 0
|
224
|
+
raise ParameterError, "Invalid max gas fee #{fields[:max_gas_fee]}!"
|
225
|
+
end
|
226
|
+
return fields
|
227
|
+
end
|
228
|
+
|
229
|
+
# Validates the common legacy transaction fields such as gas price.
|
222
230
|
#
|
223
231
|
# @param fields [Hash] the transaction fields.
|
224
232
|
# @return [Hash] the validated transaction fields.
|
225
|
-
# @raise [ParameterError] if nonce is an invalid integer.
|
226
233
|
# @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
234
|
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
235
|
if fields[:gas_price].nil? or fields[:gas_price] < 0
|
235
236
|
raise ParameterError, "Invalid gas price #{fields[:gas_price]}!"
|
236
237
|
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
238
|
return fields
|
247
239
|
end
|
248
240
|
|
data/lib/eth/version.rb
CHANGED
data/lib/eth.rb
CHANGED
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.2
|
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-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keccak
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- Rakefile
|
105
105
|
- bin/console
|
106
106
|
- bin/setup
|
107
|
+
- codecov.yml
|
107
108
|
- eth.gemspec
|
108
109
|
- lib/eth.rb
|
109
110
|
- lib/eth/abi.rb
|
@@ -127,6 +128,7 @@ files:
|
|
127
128
|
- lib/eth/rlp/sedes/binary.rb
|
128
129
|
- lib/eth/rlp/sedes/list.rb
|
129
130
|
- lib/eth/signature.rb
|
131
|
+
- lib/eth/solidity.rb
|
130
132
|
- lib/eth/tx.rb
|
131
133
|
- lib/eth/tx/eip1559.rb
|
132
134
|
- lib/eth/tx/eip2930.rb
|
@@ -161,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
163
|
- !ruby/object:Gem::Version
|
162
164
|
version: '0'
|
163
165
|
requirements: []
|
164
|
-
rubygems_version: 3.3.
|
166
|
+
rubygems_version: 3.3.8
|
165
167
|
signing_key:
|
166
168
|
specification_version: 4
|
167
169
|
summary: Ruby Ethereum library.
|