eth 0.5.7 → 0.5.8
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 +1 -1
- data/.github/workflows/docs.yml +2 -2
- data/.github/workflows/spec.yml +2 -2
- data/CHANGELOG.md +19 -0
- data/Gemfile +2 -2
- data/abis/ens.json +422 -0
- data/eth.gemspec +2 -2
- data/lib/eth/client.rb +31 -48
- data/lib/eth/ens/resolver.rb +77 -0
- data/lib/eth/version.rb +1 -1
- data/lib/eth.rb +1 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb2370cb186c41e849c2949bbfcc1cb5cc6b2572064d8abba4631ed3ed3a692
|
4
|
+
data.tar.gz: dabde7655f7d8921f05a1cdb5d860981c3ee4cced8e1a7b085482d01b14c24b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23a6ac9854368723b40fc0e46fed5e7ae90d1691358538f94cf8a9a43c333dc3e002e5d359513914440823501f882608d9e55e7a71a5a19ee88d38a57498a570
|
7
|
+
data.tar.gz: 14f5f74ea076a2fbdd5b538521a2b4006e58bf9105e34f0a942560841371f69a48cf80e86c680228ee5253e9483c3d85a857aeea7f48e8f4c1698a0f5ae0236c
|
data/.github/workflows/docs.yml
CHANGED
@@ -13,14 +13,14 @@ jobs:
|
|
13
13
|
- uses: actions/checkout@v3
|
14
14
|
- uses: ruby/setup-ruby@v1
|
15
15
|
with:
|
16
|
-
ruby-version: '
|
16
|
+
ruby-version: '3.0'
|
17
17
|
bundler-cache: true
|
18
18
|
- name: Run Yard Doc
|
19
19
|
run: |
|
20
20
|
gem install yard
|
21
21
|
yard doc
|
22
22
|
- name: Deploy GH Pages
|
23
|
-
uses: JamesIves/github-pages-deploy-action@v4.4.
|
23
|
+
uses: JamesIves/github-pages-deploy-action@v4.4.1
|
24
24
|
with:
|
25
25
|
branch: gh-pages
|
26
26
|
folder: doc/
|
data/.github/workflows/spec.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.5.7]
|
5
|
+
### Added
|
6
|
+
* Eth/client: add http basic support auth ([#151](https://github.com/q9f/eth.rb/pull/151))
|
7
|
+
* Chore: add polygon chain test case ([#146](https://github.com/q9f/eth.rb/pull/146))
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
* Docs: add readme header for yard ([#159](https://github.com/q9f/eth.rb/pull/159))
|
11
|
+
* Eth/client: fix api documentation ([#158](https://github.com/q9f/eth.rb/pull/158))
|
12
|
+
* Eth/client: update default fees ([#157](https://github.com/q9f/eth.rb/pull/157))
|
13
|
+
* Docs: move readme usage to wiki ([#156](https://github.com/q9f/eth.rb/pull/156))
|
14
|
+
* Eth/signature: fix allowing ledger v values of 0 ([#155](https://github.com/q9f/eth.rb/pull/155))
|
15
|
+
* Eth/client: rename http basic to http auth ([#154](https://github.com/q9f/eth.rb/pull/154))
|
16
|
+
* Fix Eth:Tx.decode for transaction with s length < 64 chars ([#148](https://github.com/q9f/eth.rb/pull/148))
|
17
|
+
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.3.4 to 4.4.0 ([#140](https://github.com/q9f/eth.rb/pull/140))
|
18
|
+
* Fixed to return uint256[] correctly when passed as type ([#147](https://github.com/q9f/eth.rb/pull/147))
|
19
|
+
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.3.3 to 4.3.4 ([#133](https://github.com/q9f/eth.rb/pull/133))
|
20
|
+
* Docs: update CHANGELOG ([#132](https://github.com/q9f/eth.rb/pull/132))
|
21
|
+
* Gem: bump version to 0.5.7 ([#131](https://github.com/q9f/eth.rb/pull/131))
|
22
|
+
|
4
23
|
## [0.5.6]
|
5
24
|
### Added
|
6
25
|
- Eth/client: Add gas limit override option for contract deployments ([#128](https://github.com/q9f/eth.rb/pull/128))
|
data/Gemfile
CHANGED
@@ -7,8 +7,8 @@ group :test, :development do
|
|
7
7
|
gem "codecov", "~> 0.6"
|
8
8
|
gem "pry", "~> 0.14"
|
9
9
|
gem "rake", "~> 13.0"
|
10
|
-
gem "rdoc", "~> 6.
|
11
|
-
gem "rspec", "~> 3.
|
10
|
+
gem "rdoc", "~> 6.4"
|
11
|
+
gem "rspec", "~> 3.11"
|
12
12
|
gem "rufo", "~> 0.13"
|
13
13
|
gem "simplecov", "~> 0.21"
|
14
14
|
gem "yard", "~> 0.9"
|
data/abis/ens.json
ADDED
@@ -0,0 +1,422 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"inputs": [
|
4
|
+
{
|
5
|
+
"internalType": "contract ENS",
|
6
|
+
"name": "_old",
|
7
|
+
"type": "address"
|
8
|
+
}
|
9
|
+
],
|
10
|
+
"payable": false,
|
11
|
+
"stateMutability": "nonpayable",
|
12
|
+
"type": "constructor"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"anonymous": false,
|
16
|
+
"inputs": [
|
17
|
+
{
|
18
|
+
"indexed": true,
|
19
|
+
"internalType": "address",
|
20
|
+
"name": "owner",
|
21
|
+
"type": "address"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"indexed": true,
|
25
|
+
"internalType": "address",
|
26
|
+
"name": "operator",
|
27
|
+
"type": "address"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"indexed": false,
|
31
|
+
"internalType": "bool",
|
32
|
+
"name": "approved",
|
33
|
+
"type": "bool"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"name": "ApprovalForAll",
|
37
|
+
"type": "event"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"anonymous": false,
|
41
|
+
"inputs": [
|
42
|
+
{
|
43
|
+
"indexed": true,
|
44
|
+
"internalType": "bytes32",
|
45
|
+
"name": "node",
|
46
|
+
"type": "bytes32"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"indexed": true,
|
50
|
+
"internalType": "bytes32",
|
51
|
+
"name": "label",
|
52
|
+
"type": "bytes32"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"indexed": false,
|
56
|
+
"internalType": "address",
|
57
|
+
"name": "owner",
|
58
|
+
"type": "address"
|
59
|
+
}
|
60
|
+
],
|
61
|
+
"name": "NewOwner",
|
62
|
+
"type": "event"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"anonymous": false,
|
66
|
+
"inputs": [
|
67
|
+
{
|
68
|
+
"indexed": true,
|
69
|
+
"internalType": "bytes32",
|
70
|
+
"name": "node",
|
71
|
+
"type": "bytes32"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"indexed": false,
|
75
|
+
"internalType": "address",
|
76
|
+
"name": "resolver",
|
77
|
+
"type": "address"
|
78
|
+
}
|
79
|
+
],
|
80
|
+
"name": "NewResolver",
|
81
|
+
"type": "event"
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"anonymous": false,
|
85
|
+
"inputs": [
|
86
|
+
{
|
87
|
+
"indexed": true,
|
88
|
+
"internalType": "bytes32",
|
89
|
+
"name": "node",
|
90
|
+
"type": "bytes32"
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"indexed": false,
|
94
|
+
"internalType": "uint64",
|
95
|
+
"name": "ttl",
|
96
|
+
"type": "uint64"
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"name": "NewTTL",
|
100
|
+
"type": "event"
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"anonymous": false,
|
104
|
+
"inputs": [
|
105
|
+
{
|
106
|
+
"indexed": true,
|
107
|
+
"internalType": "bytes32",
|
108
|
+
"name": "node",
|
109
|
+
"type": "bytes32"
|
110
|
+
},
|
111
|
+
{
|
112
|
+
"indexed": false,
|
113
|
+
"internalType": "address",
|
114
|
+
"name": "owner",
|
115
|
+
"type": "address"
|
116
|
+
}
|
117
|
+
],
|
118
|
+
"name": "Transfer",
|
119
|
+
"type": "event"
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"constant": true,
|
123
|
+
"inputs": [
|
124
|
+
{
|
125
|
+
"internalType": "address",
|
126
|
+
"name": "owner",
|
127
|
+
"type": "address"
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"internalType": "address",
|
131
|
+
"name": "operator",
|
132
|
+
"type": "address"
|
133
|
+
}
|
134
|
+
],
|
135
|
+
"name": "isApprovedForAll",
|
136
|
+
"outputs": [
|
137
|
+
{
|
138
|
+
"internalType": "bool",
|
139
|
+
"name": "",
|
140
|
+
"type": "bool"
|
141
|
+
}
|
142
|
+
],
|
143
|
+
"payable": false,
|
144
|
+
"stateMutability": "view",
|
145
|
+
"type": "function"
|
146
|
+
},
|
147
|
+
{
|
148
|
+
"constant": true,
|
149
|
+
"inputs": [],
|
150
|
+
"name": "old",
|
151
|
+
"outputs": [
|
152
|
+
{
|
153
|
+
"internalType": "contract ENS",
|
154
|
+
"name": "",
|
155
|
+
"type": "address"
|
156
|
+
}
|
157
|
+
],
|
158
|
+
"payable": false,
|
159
|
+
"stateMutability": "view",
|
160
|
+
"type": "function"
|
161
|
+
},
|
162
|
+
{
|
163
|
+
"constant": true,
|
164
|
+
"inputs": [
|
165
|
+
{
|
166
|
+
"internalType": "bytes32",
|
167
|
+
"name": "node",
|
168
|
+
"type": "bytes32"
|
169
|
+
}
|
170
|
+
],
|
171
|
+
"name": "owner",
|
172
|
+
"outputs": [
|
173
|
+
{
|
174
|
+
"internalType": "address",
|
175
|
+
"name": "",
|
176
|
+
"type": "address"
|
177
|
+
}
|
178
|
+
],
|
179
|
+
"payable": false,
|
180
|
+
"stateMutability": "view",
|
181
|
+
"type": "function"
|
182
|
+
},
|
183
|
+
{
|
184
|
+
"constant": true,
|
185
|
+
"inputs": [
|
186
|
+
{
|
187
|
+
"internalType": "bytes32",
|
188
|
+
"name": "node",
|
189
|
+
"type": "bytes32"
|
190
|
+
}
|
191
|
+
],
|
192
|
+
"name": "recordExists",
|
193
|
+
"outputs": [
|
194
|
+
{
|
195
|
+
"internalType": "bool",
|
196
|
+
"name": "",
|
197
|
+
"type": "bool"
|
198
|
+
}
|
199
|
+
],
|
200
|
+
"payable": false,
|
201
|
+
"stateMutability": "view",
|
202
|
+
"type": "function"
|
203
|
+
},
|
204
|
+
{
|
205
|
+
"constant": true,
|
206
|
+
"inputs": [
|
207
|
+
{
|
208
|
+
"internalType": "bytes32",
|
209
|
+
"name": "node",
|
210
|
+
"type": "bytes32"
|
211
|
+
}
|
212
|
+
],
|
213
|
+
"name": "resolver",
|
214
|
+
"outputs": [
|
215
|
+
{
|
216
|
+
"internalType": "address",
|
217
|
+
"name": "",
|
218
|
+
"type": "address"
|
219
|
+
}
|
220
|
+
],
|
221
|
+
"payable": false,
|
222
|
+
"stateMutability": "view",
|
223
|
+
"type": "function"
|
224
|
+
},
|
225
|
+
{
|
226
|
+
"constant": false,
|
227
|
+
"inputs": [
|
228
|
+
{
|
229
|
+
"internalType": "address",
|
230
|
+
"name": "operator",
|
231
|
+
"type": "address"
|
232
|
+
},
|
233
|
+
{
|
234
|
+
"internalType": "bool",
|
235
|
+
"name": "approved",
|
236
|
+
"type": "bool"
|
237
|
+
}
|
238
|
+
],
|
239
|
+
"name": "setApprovalForAll",
|
240
|
+
"outputs": [],
|
241
|
+
"payable": false,
|
242
|
+
"stateMutability": "nonpayable",
|
243
|
+
"type": "function"
|
244
|
+
},
|
245
|
+
{
|
246
|
+
"constant": false,
|
247
|
+
"inputs": [
|
248
|
+
{
|
249
|
+
"internalType": "bytes32",
|
250
|
+
"name": "node",
|
251
|
+
"type": "bytes32"
|
252
|
+
},
|
253
|
+
{
|
254
|
+
"internalType": "address",
|
255
|
+
"name": "owner",
|
256
|
+
"type": "address"
|
257
|
+
}
|
258
|
+
],
|
259
|
+
"name": "setOwner",
|
260
|
+
"outputs": [],
|
261
|
+
"payable": false,
|
262
|
+
"stateMutability": "nonpayable",
|
263
|
+
"type": "function"
|
264
|
+
},
|
265
|
+
{
|
266
|
+
"constant": false,
|
267
|
+
"inputs": [
|
268
|
+
{
|
269
|
+
"internalType": "bytes32",
|
270
|
+
"name": "node",
|
271
|
+
"type": "bytes32"
|
272
|
+
},
|
273
|
+
{
|
274
|
+
"internalType": "address",
|
275
|
+
"name": "owner",
|
276
|
+
"type": "address"
|
277
|
+
},
|
278
|
+
{
|
279
|
+
"internalType": "address",
|
280
|
+
"name": "resolver",
|
281
|
+
"type": "address"
|
282
|
+
},
|
283
|
+
{
|
284
|
+
"internalType": "uint64",
|
285
|
+
"name": "ttl",
|
286
|
+
"type": "uint64"
|
287
|
+
}
|
288
|
+
],
|
289
|
+
"name": "setRecord",
|
290
|
+
"outputs": [],
|
291
|
+
"payable": false,
|
292
|
+
"stateMutability": "nonpayable",
|
293
|
+
"type": "function"
|
294
|
+
},
|
295
|
+
{
|
296
|
+
"constant": false,
|
297
|
+
"inputs": [
|
298
|
+
{
|
299
|
+
"internalType": "bytes32",
|
300
|
+
"name": "node",
|
301
|
+
"type": "bytes32"
|
302
|
+
},
|
303
|
+
{
|
304
|
+
"internalType": "address",
|
305
|
+
"name": "resolver",
|
306
|
+
"type": "address"
|
307
|
+
}
|
308
|
+
],
|
309
|
+
"name": "setResolver",
|
310
|
+
"outputs": [],
|
311
|
+
"payable": false,
|
312
|
+
"stateMutability": "nonpayable",
|
313
|
+
"type": "function"
|
314
|
+
},
|
315
|
+
{
|
316
|
+
"constant": false,
|
317
|
+
"inputs": [
|
318
|
+
{
|
319
|
+
"internalType": "bytes32",
|
320
|
+
"name": "node",
|
321
|
+
"type": "bytes32"
|
322
|
+
},
|
323
|
+
{
|
324
|
+
"internalType": "bytes32",
|
325
|
+
"name": "label",
|
326
|
+
"type": "bytes32"
|
327
|
+
},
|
328
|
+
{
|
329
|
+
"internalType": "address",
|
330
|
+
"name": "owner",
|
331
|
+
"type": "address"
|
332
|
+
}
|
333
|
+
],
|
334
|
+
"name": "setSubnodeOwner",
|
335
|
+
"outputs": [
|
336
|
+
{
|
337
|
+
"internalType": "bytes32",
|
338
|
+
"name": "",
|
339
|
+
"type": "bytes32"
|
340
|
+
}
|
341
|
+
],
|
342
|
+
"payable": false,
|
343
|
+
"stateMutability": "nonpayable",
|
344
|
+
"type": "function"
|
345
|
+
},
|
346
|
+
{
|
347
|
+
"constant": false,
|
348
|
+
"inputs": [
|
349
|
+
{
|
350
|
+
"internalType": "bytes32",
|
351
|
+
"name": "node",
|
352
|
+
"type": "bytes32"
|
353
|
+
},
|
354
|
+
{
|
355
|
+
"internalType": "bytes32",
|
356
|
+
"name": "label",
|
357
|
+
"type": "bytes32"
|
358
|
+
},
|
359
|
+
{
|
360
|
+
"internalType": "address",
|
361
|
+
"name": "owner",
|
362
|
+
"type": "address"
|
363
|
+
},
|
364
|
+
{
|
365
|
+
"internalType": "address",
|
366
|
+
"name": "resolver",
|
367
|
+
"type": "address"
|
368
|
+
},
|
369
|
+
{
|
370
|
+
"internalType": "uint64",
|
371
|
+
"name": "ttl",
|
372
|
+
"type": "uint64"
|
373
|
+
}
|
374
|
+
],
|
375
|
+
"name": "setSubnodeRecord",
|
376
|
+
"outputs": [],
|
377
|
+
"payable": false,
|
378
|
+
"stateMutability": "nonpayable",
|
379
|
+
"type": "function"
|
380
|
+
},
|
381
|
+
{
|
382
|
+
"constant": false,
|
383
|
+
"inputs": [
|
384
|
+
{
|
385
|
+
"internalType": "bytes32",
|
386
|
+
"name": "node",
|
387
|
+
"type": "bytes32"
|
388
|
+
},
|
389
|
+
{
|
390
|
+
"internalType": "uint64",
|
391
|
+
"name": "ttl",
|
392
|
+
"type": "uint64"
|
393
|
+
}
|
394
|
+
],
|
395
|
+
"name": "setTTL",
|
396
|
+
"outputs": [],
|
397
|
+
"payable": false,
|
398
|
+
"stateMutability": "nonpayable",
|
399
|
+
"type": "function"
|
400
|
+
},
|
401
|
+
{
|
402
|
+
"constant": true,
|
403
|
+
"inputs": [
|
404
|
+
{
|
405
|
+
"internalType": "bytes32",
|
406
|
+
"name": "node",
|
407
|
+
"type": "bytes32"
|
408
|
+
}
|
409
|
+
],
|
410
|
+
"name": "ttl",
|
411
|
+
"outputs": [
|
412
|
+
{
|
413
|
+
"internalType": "uint64",
|
414
|
+
"name": "",
|
415
|
+
"type": "uint64"
|
416
|
+
}
|
417
|
+
],
|
418
|
+
"payable": false,
|
419
|
+
"stateMutability": "view",
|
420
|
+
"type": "function"
|
421
|
+
}
|
422
|
+
]
|
data/eth.gemspec
CHANGED
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
29
|
spec.bindir = "exe"
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
31
|
+
spec.require_paths = ["lib", "abis"]
|
32
32
|
spec.test_files = spec.files.grep %r{^(test|spec|features)/}
|
33
33
|
|
34
34
|
spec.platform = Gem::Platform::RUBY
|
35
|
-
spec.required_ruby_version = ">= 2.
|
35
|
+
spec.required_ruby_version = ">= 2.7", "< 4.0"
|
36
36
|
|
37
37
|
# keccak for hashing everything in ethereum
|
38
38
|
spec.add_dependency "keccak", "~> 1.3"
|
data/lib/eth/client.rb
CHANGED
@@ -106,8 +106,8 @@ module Eth
|
|
106
106
|
# See {#transfer} for params and overloads.
|
107
107
|
#
|
108
108
|
# @return [String] the transaction hash once it is mined.
|
109
|
-
def transfer_and_wait(destination, amount,
|
110
|
-
wait_for_tx(transfer(destination, amount,
|
109
|
+
def transfer_and_wait(destination, amount, **kwargs)
|
110
|
+
wait_for_tx(transfer(destination, amount, **kwargs))
|
111
111
|
end
|
112
112
|
|
113
113
|
# Simply transfer Ether to an account without any call data or
|
@@ -117,19 +117,24 @@ module Eth
|
|
117
117
|
# **Note**, that many remote providers (e.g., Infura) do not provide
|
118
118
|
# any accounts. Provide a `sender_key` if you experience issues.
|
119
119
|
#
|
120
|
-
# @
|
121
|
-
#
|
122
|
-
#
|
123
|
-
# @
|
120
|
+
# @overload transfer(destination, amount)
|
121
|
+
# @param destination [Eth::Address] the destination address.
|
122
|
+
# @param amount [Integer] the transfer amount in Wei.
|
123
|
+
# @overload transfer(destination, amount, **kwargs)
|
124
|
+
# @param destination [Eth::Address] the destination address.
|
125
|
+
# @param amount [Integer] the transfer amount in Wei.
|
126
|
+
# @param **sender_key [Eth::Key] the sender private key.
|
127
|
+
# @param **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
|
128
|
+
# @param **nonce [Integer] optional specific nonce for transaction.
|
124
129
|
# @return [String] the local transaction hash.
|
125
|
-
def transfer(destination, amount,
|
130
|
+
def transfer(destination, amount, **kwargs)
|
126
131
|
params = {
|
127
132
|
value: amount,
|
128
133
|
to: destination,
|
129
134
|
gas_limit: gas_limit,
|
130
135
|
chain_id: chain_id,
|
131
136
|
}
|
132
|
-
if legacy
|
137
|
+
if kwargs[:legacy]
|
133
138
|
params.merge!({
|
134
139
|
gas_price: max_fee_per_gas,
|
135
140
|
})
|
@@ -139,22 +144,22 @@ module Eth
|
|
139
144
|
max_gas_fee: max_fee_per_gas,
|
140
145
|
})
|
141
146
|
end
|
142
|
-
unless sender_key.nil?
|
147
|
+
unless kwargs[:sender_key].nil?
|
143
148
|
|
144
149
|
# use the provided key as sender and signer
|
145
150
|
params.merge!({
|
146
|
-
from: sender_key.address,
|
147
|
-
nonce: get_nonce(sender_key.address),
|
151
|
+
from: kwargs[:sender_key].address,
|
152
|
+
nonce: kwargs[:nonce] || get_nonce(kwargs[:sender_key].address),
|
148
153
|
})
|
149
154
|
tx = Eth::Tx.new(params)
|
150
|
-
tx.sign sender_key
|
155
|
+
tx.sign kwargs[:sender_key]
|
151
156
|
return eth_send_raw_transaction(tx.hex)["result"]
|
152
157
|
else
|
153
158
|
|
154
159
|
# use the default account as sender and external signer
|
155
160
|
params.merge!({
|
156
161
|
from: default_account,
|
157
|
-
nonce: get_nonce(default_account),
|
162
|
+
nonce: kwargs[:nonce] || get_nonce(default_account),
|
158
163
|
})
|
159
164
|
return eth_send_transaction(params)["result"]
|
160
165
|
end
|
@@ -189,6 +194,7 @@ module Eth
|
|
189
194
|
# @param **sender_key [Eth::Key] the sender private key.
|
190
195
|
# @param **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
|
191
196
|
# @param **gas_limit [Integer] optional gas limit override for deploying the contract.
|
197
|
+
# @param **nonce [Integer] optional specific nonce for transaction.
|
192
198
|
# @return [String] the transaction hash.
|
193
199
|
# @raise [ArgumentError] in case the contract does not have any source.
|
194
200
|
def deploy(contract, *args, **kwargs)
|
@@ -223,7 +229,7 @@ module Eth
|
|
223
229
|
# Uses the provided key as sender and signer
|
224
230
|
params.merge!({
|
225
231
|
from: kwargs[:sender_key].address,
|
226
|
-
nonce: get_nonce(kwargs[:sender_key].address),
|
232
|
+
nonce: kwargs[:nonce] || get_nonce(kwargs[:sender_key].address),
|
227
233
|
})
|
228
234
|
tx = Eth::Tx.new(params)
|
229
235
|
tx.sign kwargs[:sender_key]
|
@@ -232,7 +238,7 @@ module Eth
|
|
232
238
|
# Uses the default account as sender and external signer
|
233
239
|
params.merge!({
|
234
240
|
from: default_account,
|
235
|
-
nonce: get_nonce(default_account),
|
241
|
+
nonce: kwargs[:nonce] || get_nonce(default_account),
|
236
242
|
})
|
237
243
|
return eth_send_transaction(params)["result"]
|
238
244
|
end
|
@@ -288,6 +294,8 @@ module Eth
|
|
288
294
|
# @param **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
|
289
295
|
# @param **address [Eth::Address] contract address.
|
290
296
|
# @param **gas_limit [Integer] optional gas limit override for deploying the contract.
|
297
|
+
# @param **nonce [Integer] optional specific nonce for transaction.
|
298
|
+
# @param **tx_value [Integer] optional transaction value field filling.
|
291
299
|
# @return [Object] returns the result of the transaction.
|
292
300
|
def transact(contract, function, *args, **kwargs)
|
293
301
|
gas_limit = if kwargs[:gas_limit]
|
@@ -297,7 +305,7 @@ module Eth
|
|
297
305
|
end
|
298
306
|
fun = contract.functions.select { |func| func.name == function }[0]
|
299
307
|
params = {
|
300
|
-
value: 0,
|
308
|
+
value: kwargs[:tx_value] || 0,
|
301
309
|
gas_limit: gas_limit,
|
302
310
|
chain_id: chain_id,
|
303
311
|
to: kwargs[:address] || contract.address,
|
@@ -317,7 +325,7 @@ module Eth
|
|
317
325
|
# use the provided key as sender and signer
|
318
326
|
params.merge!({
|
319
327
|
from: kwargs[:sender_key].address,
|
320
|
-
nonce: get_nonce(kwargs[:sender_key].address),
|
328
|
+
nonce: kwargs[:nonce] || get_nonce(kwargs[:sender_key].address),
|
321
329
|
})
|
322
330
|
tx = Eth::Tx.new(params)
|
323
331
|
tx.sign kwargs[:sender_key]
|
@@ -326,7 +334,7 @@ module Eth
|
|
326
334
|
# use the default account as sender and external signer
|
327
335
|
params.merge!({
|
328
336
|
from: default_account,
|
329
|
-
nonce: get_nonce(default_account),
|
337
|
+
nonce: kwargs[:nonce] || get_nonce(default_account),
|
330
338
|
})
|
331
339
|
return eth_send_transaction(params)["result"]
|
332
340
|
end
|
@@ -406,39 +414,14 @@ module Eth
|
|
406
414
|
private
|
407
415
|
|
408
416
|
# Non-transactional function call called from call().
|
417
|
+
# @see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_call
|
409
418
|
def call_raw(contract, func, *args, **kwargs)
|
410
|
-
gas_limit = if kwargs[:gas_limit]
|
411
|
-
kwargs[:gas_limit]
|
412
|
-
else
|
413
|
-
Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
|
414
|
-
end
|
415
419
|
params = {
|
416
|
-
gas_limit: gas_limit,
|
417
|
-
chain_id: chain_id,
|
418
420
|
data: call_payload(func, args),
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
if kwargs[:legacy]
|
424
|
-
params.merge!({
|
425
|
-
gas_price: max_fee_per_gas,
|
426
|
-
})
|
427
|
-
else
|
428
|
-
params.merge!({
|
429
|
-
priority_fee: max_priority_fee_per_gas,
|
430
|
-
max_gas_fee: max_fee_per_gas,
|
431
|
-
})
|
432
|
-
end
|
433
|
-
unless kwargs[:sender_key].nil?
|
434
|
-
# Uses the provided key as sender and signer
|
435
|
-
params.merge!({
|
436
|
-
from: kwargs[:sender_key].address,
|
437
|
-
nonce: get_nonce(kwargs[:sender_key].address),
|
438
|
-
})
|
439
|
-
tx = Eth::Tx.new(params)
|
440
|
-
tx.sign kwargs[:sender_key]
|
441
|
-
end
|
421
|
+
to: kwargs[:address] || contract.address,
|
422
|
+
from: kwargs[:from],
|
423
|
+
}.compact
|
424
|
+
|
442
425
|
raw_result = eth_call(params)["result"]
|
443
426
|
types = func.outputs.map { |i| i.type }
|
444
427
|
return nil if raw_result == "0x"
|
@@ -0,0 +1,77 @@
|
|
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
|
+
# Provides ENS specific functionality
|
20
|
+
# ref: https://ens.domains
|
21
|
+
module Ens
|
22
|
+
|
23
|
+
# Utility class for resolving ENS names to Ethereum addresses
|
24
|
+
class Resolver
|
25
|
+
|
26
|
+
# The default address for ENS, which applies to most chains
|
27
|
+
DEFAULT_ADDRESS = "0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e".freeze
|
28
|
+
|
29
|
+
# Create an instance of the ENS Resolver
|
30
|
+
#
|
31
|
+
# @param client [Eth::Client] The client instance
|
32
|
+
# @param address [String] The address of the ENS contract
|
33
|
+
def initialize(client, address = DEFAULT_ADDRESS)
|
34
|
+
@client = client
|
35
|
+
@contract = Eth::Contract.from_abi(
|
36
|
+
name: "ENS",
|
37
|
+
address: address,
|
38
|
+
abi: JSON.parse(File.read(File.join(File.dirname(__FILE__), "../../../abis/ens.json"))),
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Resolve an ENS name to an address
|
43
|
+
#
|
44
|
+
# @param ens_name [String] The ENS name, eg: fancy.eth
|
45
|
+
# @return [String] The owner address of the name, as a hex string
|
46
|
+
def resolve(ens_name)
|
47
|
+
@client.call(@contract, "owner", namehash(ens_name))
|
48
|
+
end
|
49
|
+
|
50
|
+
# Generate node for the given domain name
|
51
|
+
# See: https://docs.ens.domains/contract-api-reference/name-processing
|
52
|
+
#
|
53
|
+
# @param ens_name [String] The ENS name, eg: fancy.eth
|
54
|
+
# @return [String] The node as a hex string
|
55
|
+
def namehash(ens_name)
|
56
|
+
node = ("0" * 64)
|
57
|
+
name = normalize(ens_name)
|
58
|
+
name.split(".").reverse.each do |label|
|
59
|
+
hash = Digest::Keccak.new(256).hexdigest(label)
|
60
|
+
node = Digest::Keccak.new(256).hexdigest([node + hash].pack("H*"))
|
61
|
+
end
|
62
|
+
"0x#{node}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Normalize a string as specified by http://unicode.org/reports/tr46/
|
66
|
+
#
|
67
|
+
# @param input [String] The input string
|
68
|
+
# @return [String] The normalized output string
|
69
|
+
def normalize(input)
|
70
|
+
# TODO: This is fairly complicated, and there doesn't seem to be a ruby
|
71
|
+
# library which can handle it perfectly.
|
72
|
+
# https://www.unicode.org/reports/tr46/tr46-27.html
|
73
|
+
input.downcase
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
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.8
|
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-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keccak
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- LICENSE.txt
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
|
+
- abis/ens.json
|
112
113
|
- bin/console
|
113
114
|
- bin/setup
|
114
115
|
- codecov.yml
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- lib/eth/contract/function_output.rb
|
133
134
|
- lib/eth/contract/initializer.rb
|
134
135
|
- lib/eth/eip712.rb
|
136
|
+
- lib/eth/ens/resolver.rb
|
135
137
|
- lib/eth/key.rb
|
136
138
|
- lib/eth/key/decrypter.rb
|
137
139
|
- lib/eth/key/encrypter.rb
|
@@ -164,11 +166,12 @@ post_install_message:
|
|
164
166
|
rdoc_options: []
|
165
167
|
require_paths:
|
166
168
|
- lib
|
169
|
+
- abis
|
167
170
|
required_ruby_version: !ruby/object:Gem::Requirement
|
168
171
|
requirements:
|
169
172
|
- - ">="
|
170
173
|
- !ruby/object:Gem::Version
|
171
|
-
version: '2.
|
174
|
+
version: '2.7'
|
172
175
|
- - "<"
|
173
176
|
- !ruby/object:Gem::Version
|
174
177
|
version: '4.0'
|
@@ -178,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
181
|
- !ruby/object:Gem::Version
|
179
182
|
version: '0'
|
180
183
|
requirements: []
|
181
|
-
rubygems_version: 3.3.
|
184
|
+
rubygems_version: 3.3.25
|
182
185
|
signing_key:
|
183
186
|
specification_version: 4
|
184
187
|
summary: Ruby Ethereum library.
|