eth 0.5.9 → 0.5.11
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/docs.yml +1 -1
- data/.github/workflows/spec.yml +9 -3
- data/CHANGELOG.md +34 -0
- data/CODE_OF_CONDUCT.md +122 -0
- data/CONTRIBUTING.md +61 -0
- data/README.md +5 -1
- data/SECURITY.md +24 -0
- data/abi/ens_registry.json +436 -0
- data/abi/ens_resolver.json +885 -0
- data/eth.gemspec +4 -1
- data/lib/eth/abi/decoder.rb +135 -0
- data/lib/eth/abi/encoder.rb +304 -0
- data/lib/eth/abi/event.rb +13 -2
- data/lib/eth/abi/type.rb +1 -1
- data/lib/eth/abi.rb +10 -385
- data/lib/eth/api.rb +45 -51
- data/lib/eth/chain.rb +9 -0
- data/lib/eth/client/http.rb +18 -4
- data/lib/eth/client/ipc.rb +2 -2
- data/lib/eth/client.rb +120 -113
- data/lib/eth/contract.rb +11 -1
- data/lib/eth/ens/coin_type.rb +50 -0
- data/lib/eth/ens/resolver.rb +67 -23
- data/lib/eth/ens.rb +28 -0
- data/lib/eth/solidity.rb +7 -4
- data/lib/eth/tx/eip1559.rb +10 -5
- data/lib/eth/tx/eip2930.rb +10 -5
- data/lib/eth/tx/legacy.rb +0 -2
- data/lib/eth/tx.rb +9 -2
- data/lib/eth/util.rb +1 -0
- data/lib/eth/version.rb +11 -2
- data/lib/eth.rb +1 -1
- metadata +28 -7
- data/abis/ens.json +0 -422
- data/lib/eth/client/http_auth.rb +0 -73
data/lib/eth/abi.rb
CHANGED
@@ -16,9 +16,6 @@
|
|
16
16
|
|
17
17
|
require "konstructor"
|
18
18
|
|
19
|
-
require "eth/abi/event"
|
20
|
-
require "eth/abi/type"
|
21
|
-
|
22
19
|
# Provides the {Eth} module.
|
23
20
|
module Eth
|
24
21
|
|
@@ -56,110 +53,15 @@ module Eth
|
|
56
53
|
# encode types and arguments
|
57
54
|
args.each_with_index do |arg, i|
|
58
55
|
if parsed_types[i].dynamic?
|
59
|
-
head +=
|
60
|
-
tail +=
|
56
|
+
head += Abi::Encoder.type(Type.size_type, head_size + tail.size)
|
57
|
+
tail += Abi::Encoder.type(parsed_types[i], arg)
|
61
58
|
else
|
62
|
-
head +=
|
59
|
+
head += Abi::Encoder.type(parsed_types[i], arg)
|
63
60
|
end
|
64
61
|
end
|
65
62
|
|
66
63
|
# return the encoded ABI blob
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
# Encodes a specific value, either static or dynamic.
|
71
|
-
#
|
72
|
-
# @param type [Eth::Abi::Type] type to be encoded.
|
73
|
-
# @param arg [String|Number] value to be encoded.
|
74
|
-
# @return [String] the encoded type.
|
75
|
-
# @raise [EncodingError] if value does not match type.
|
76
|
-
def encode_type(type, arg)
|
77
|
-
if %w(string bytes).include? type.base_type and type.sub_type.empty? and type.dimensions.empty?
|
78
|
-
raise EncodingError, "Argument must be a String" unless arg.instance_of? String
|
79
|
-
|
80
|
-
# encodes strings and bytes
|
81
|
-
size = encode_type Type.size_type, arg.size
|
82
|
-
padding = Constant::BYTE_ZERO * (Util.ceil32(arg.size) - arg.size)
|
83
|
-
return "#{size}#{arg}#{padding}"
|
84
|
-
elsif type.base_type == "tuple" && type.dimensions.size == 1 && type.dimensions[0] != 0
|
85
|
-
result = ""
|
86
|
-
result += encode_struct_offsets(type.nested_sub, arg)
|
87
|
-
result += arg.map { |x| encode_type(type.nested_sub, x) }.join
|
88
|
-
result
|
89
|
-
elsif type.dynamic? && arg.is_a?(Array)
|
90
|
-
|
91
|
-
# encodes dynamic-sized arrays
|
92
|
-
head, tail = "", ""
|
93
|
-
head += encode_type(Type.size_type, arg.size)
|
94
|
-
nested_sub = type.nested_sub
|
95
|
-
nested_sub_size = type.nested_sub.size
|
96
|
-
|
97
|
-
# calculate offsets
|
98
|
-
if %w(string bytes).include?(type.base_type) && type.sub_type.empty?
|
99
|
-
offset = 0
|
100
|
-
arg.size.times do |i|
|
101
|
-
if i == 0
|
102
|
-
offset = arg.size * 32
|
103
|
-
else
|
104
|
-
number_of_words = ((arg[i - 1].size + 32 - 1) / 32).floor
|
105
|
-
total_bytes_length = number_of_words * 32
|
106
|
-
offset += total_bytes_length + 32
|
107
|
-
end
|
108
|
-
|
109
|
-
head += encode_type(Type.size_type, offset)
|
110
|
-
end
|
111
|
-
elsif nested_sub.base_type == "tuple" && nested_sub.dynamic?
|
112
|
-
head += encode_struct_offsets(nested_sub, arg)
|
113
|
-
end
|
114
|
-
|
115
|
-
arg.size.times do |i|
|
116
|
-
head += encode_type nested_sub, arg[i]
|
117
|
-
end
|
118
|
-
return "#{head}#{tail}"
|
119
|
-
else
|
120
|
-
if type.dimensions.empty?
|
121
|
-
|
122
|
-
# encode a primitive type
|
123
|
-
return encode_primitive_type type, arg
|
124
|
-
else
|
125
|
-
|
126
|
-
# encode static-size arrays
|
127
|
-
return arg.map { |x| encode_type(type.nested_sub, x) }.join
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# Encodes primitive types.
|
133
|
-
#
|
134
|
-
# @param type [Eth::Abi::Type] type to be encoded.
|
135
|
-
# @param arg [String|Number] value to be encoded.
|
136
|
-
# @return [String] the encoded primitive type.
|
137
|
-
# @raise [EncodingError] if value does not match type.
|
138
|
-
# @raise [ValueOutOfBounds] if value is out of bounds for type.
|
139
|
-
# @raise [EncodingError] if encoding fails for type.
|
140
|
-
def encode_primitive_type(type, arg)
|
141
|
-
case type.base_type
|
142
|
-
when "uint"
|
143
|
-
return encode_uint arg, type
|
144
|
-
when "bool"
|
145
|
-
return encode_bool arg
|
146
|
-
when "int"
|
147
|
-
return encode_int arg, type
|
148
|
-
when "ureal", "ufixed"
|
149
|
-
return encode_ufixed arg, type
|
150
|
-
when "real", "fixed"
|
151
|
-
return encode_fixed arg, type
|
152
|
-
when "string", "bytes"
|
153
|
-
return encode_bytes arg, type
|
154
|
-
when "tuple"
|
155
|
-
return encode_tuple arg, type
|
156
|
-
when "hash"
|
157
|
-
return encode_hash arg, type
|
158
|
-
when "address"
|
159
|
-
return encode_address arg
|
160
|
-
else
|
161
|
-
raise EncodingError, "Unhandled type: #{type.base_type} #{type.sub_type}"
|
162
|
-
end
|
64
|
+
"#{head}#{tail}"
|
163
65
|
end
|
164
66
|
|
165
67
|
# Decodes Application Binary Interface (ABI) data. It accepts multiple
|
@@ -216,289 +118,12 @@ module Eth
|
|
216
118
|
end
|
217
119
|
|
218
120
|
# return the decoded ABI types and data
|
219
|
-
|
220
|
-
end
|
221
|
-
|
222
|
-
# Decodes a specific value, either static or dynamic.
|
223
|
-
#
|
224
|
-
# @param type [Eth::Abi::Type] type to be decoded.
|
225
|
-
# @param arg [String] encoded type data string.
|
226
|
-
# @return [String] the decoded data for the type.
|
227
|
-
# @raise [DecodingError] if decoding fails for type.
|
228
|
-
def decode_type(type, arg)
|
229
|
-
if %w(string bytes).include?(type.base_type) and type.sub_type.empty?
|
230
|
-
l = Util.deserialize_big_endian_to_int arg[0, 32]
|
231
|
-
data = arg[32..-1]
|
232
|
-
raise DecodingError, "Wrong data size for string/bytes object" unless data.size == Util.ceil32(l)
|
233
|
-
|
234
|
-
# decoded strings and bytes
|
235
|
-
return data[0, l]
|
236
|
-
elsif type.dynamic?
|
237
|
-
l = Util.deserialize_big_endian_to_int arg[0, 32]
|
238
|
-
nested_sub = type.nested_sub
|
239
|
-
|
240
|
-
# ref https://github.com/ethereum/tests/issues/691
|
241
|
-
raise NotImplementedError, "Decoding dynamic arrays with nested dynamic sub-types is not implemented for ABI." if nested_sub.dynamic?
|
242
|
-
|
243
|
-
# decoded dynamic-sized arrays
|
244
|
-
return (0...l).map { |i| decode_type(nested_sub, arg[32 + nested_sub.size * i, nested_sub.size]) }
|
245
|
-
elsif !type.dimensions.empty?
|
246
|
-
l = type.dimensions.last[0]
|
247
|
-
nested_sub = type.nested_sub
|
248
|
-
|
249
|
-
# decoded static-size arrays
|
250
|
-
return (0...l).map { |i| decode_type(nested_sub, arg[nested_sub.size * i, nested_sub.size]) }
|
251
|
-
else
|
252
|
-
|
253
|
-
# decoded primitive types
|
254
|
-
return decode_primitive_type type, arg
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
# Decodes primitive types.
|
259
|
-
#
|
260
|
-
# @param type [Eth::Abi::Type] type to be decoded.
|
261
|
-
# @param data [String] encoded primitive type data string.
|
262
|
-
# @return [String] the decoded data for the type.
|
263
|
-
# @raise [DecodingError] if decoding fails for type.
|
264
|
-
def decode_primitive_type(type, data)
|
265
|
-
case type.base_type
|
266
|
-
when "address"
|
267
|
-
|
268
|
-
# decoded address with 0x-prefix
|
269
|
-
return "0x#{Util.bin_to_hex data[12..-1]}"
|
270
|
-
when "string", "bytes"
|
271
|
-
if type.sub_type.empty?
|
272
|
-
size = Util.deserialize_big_endian_to_int data[0, 32]
|
273
|
-
|
274
|
-
# decoded dynamic-sized array
|
275
|
-
return data[32..-1][0, size]
|
276
|
-
else
|
277
|
-
|
278
|
-
# decoded static-sized array
|
279
|
-
return data[0, type.sub_type.to_i]
|
280
|
-
end
|
281
|
-
when "hash"
|
282
|
-
|
283
|
-
# decoded hash
|
284
|
-
return data[(32 - type.sub_type.to_i), type.sub_type.to_i]
|
285
|
-
when "uint"
|
286
|
-
|
287
|
-
# decoded unsigned integer
|
288
|
-
return Util.deserialize_big_endian_to_int data
|
289
|
-
when "int"
|
290
|
-
u = Util.deserialize_big_endian_to_int data
|
291
|
-
i = u >= 2 ** (type.sub_type.to_i - 1) ? (u - 2 ** type.sub_type.to_i) : u
|
292
|
-
|
293
|
-
# decoded integer
|
294
|
-
return i
|
295
|
-
when "ureal", "ufixed"
|
296
|
-
high, low = type.sub_type.split("x").map(&:to_i)
|
297
|
-
|
298
|
-
# decoded unsigned fixed point numeric
|
299
|
-
return Util.deserialize_big_endian_to_int(data) * 1.0 / 2 ** low
|
300
|
-
when "real", "fixed"
|
301
|
-
high, low = type.sub_type.split("x").map(&:to_i)
|
302
|
-
u = Util.deserialize_big_endian_to_int data
|
303
|
-
i = u >= 2 ** (high + low - 1) ? (u - 2 ** (high + low)) : u
|
304
|
-
|
305
|
-
# decoded fixed point numeric
|
306
|
-
return i * 1.0 / 2 ** low
|
307
|
-
when "bool"
|
308
|
-
|
309
|
-
# decoded boolean
|
310
|
-
return data[-1] == Constant::BYTE_ONE
|
311
|
-
else
|
312
|
-
raise DecodingError, "Unknown primitive type: #{type.base_type}"
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
# Build event signature string from ABI interface.
|
317
|
-
#
|
318
|
-
# @param interface [Hash] ABI event interface.
|
319
|
-
# @return [String] interface signature string.
|
320
|
-
def signature(interface)
|
321
|
-
name = interface.fetch("name")
|
322
|
-
inputs = interface.fetch("inputs", [])
|
323
|
-
types = inputs.map { |i| i.fetch("type") }
|
324
|
-
"#{name}(#{types.join(",")})"
|
325
|
-
end
|
326
|
-
|
327
|
-
private
|
328
|
-
|
329
|
-
# Properly encodes unsigned integers.
|
330
|
-
def encode_uint(arg, type)
|
331
|
-
raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
|
332
|
-
raise ValueOutOfBounds, "Number out of range: #{arg}" if arg > Constant::UINT_MAX or arg < Constant::UINT_MIN
|
333
|
-
real_size = type.sub_type.to_i
|
334
|
-
i = arg.to_i
|
335
|
-
raise ValueOutOfBounds, arg unless i >= 0 and i < 2 ** real_size
|
336
|
-
return Util.zpad_int i
|
337
|
-
end
|
338
|
-
|
339
|
-
# Properly encodes signed integers.
|
340
|
-
def encode_int(arg, type)
|
341
|
-
raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
|
342
|
-
raise ValueOutOfBounds, "Number out of range: #{arg}" if arg > Constant::INT_MAX or arg < Constant::INT_MIN
|
343
|
-
real_size = type.sub_type.to_i
|
344
|
-
i = arg.to_i
|
345
|
-
raise ValueOutOfBounds, arg unless i >= -2 ** (real_size - 1) and i < 2 ** (real_size - 1)
|
346
|
-
return Util.zpad_int(i % 2 ** type.sub_type.to_i)
|
347
|
-
end
|
348
|
-
|
349
|
-
# Properly encodes booleans.
|
350
|
-
def encode_bool(arg)
|
351
|
-
raise EncodingError, "Argument is not bool: #{arg}" unless arg.instance_of? TrueClass or arg.instance_of? FalseClass
|
352
|
-
return Util.zpad_int(arg ? 1 : 0)
|
353
|
-
end
|
354
|
-
|
355
|
-
# Properly encodes unsigned fixed-point numbers.
|
356
|
-
def encode_ufixed(arg, type)
|
357
|
-
raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
|
358
|
-
high, low = type.sub_type.split("x").map(&:to_i)
|
359
|
-
raise ValueOutOfBounds, arg unless arg >= 0 and arg < 2 ** high
|
360
|
-
return Util.zpad_int((arg * 2 ** low).to_i)
|
361
|
-
end
|
362
|
-
|
363
|
-
# Properly encodes signed fixed-point numbers.
|
364
|
-
def encode_fixed(arg, type)
|
365
|
-
raise ArgumentError, "Don't know how to handle this input." unless arg.is_a? Numeric
|
366
|
-
high, low = type.sub_type.split("x").map(&:to_i)
|
367
|
-
raise ValueOutOfBounds, arg unless arg >= -2 ** (high - 1) and arg < 2 ** (high - 1)
|
368
|
-
i = (arg * 2 ** low).to_i
|
369
|
-
return Util.zpad_int(i % 2 ** (high + low))
|
370
|
-
end
|
371
|
-
|
372
|
-
# Properly encodes byte-strings.
|
373
|
-
def encode_bytes(arg, type)
|
374
|
-
raise EncodingError, "Expecting String: #{arg}" unless arg.instance_of? String
|
375
|
-
arg = handle_hex_string arg, type
|
376
|
-
|
377
|
-
if type.sub_type.empty?
|
378
|
-
size = Util.zpad_int arg.size
|
379
|
-
padding = Constant::BYTE_ZERO * (Util.ceil32(arg.size) - arg.size)
|
380
|
-
|
381
|
-
# variable length string/bytes
|
382
|
-
return "#{size}#{arg}#{padding}"
|
383
|
-
else
|
384
|
-
raise ValueOutOfBounds, arg unless arg.size <= type.sub_type.to_i
|
385
|
-
padding = Constant::BYTE_ZERO * (32 - arg.size)
|
386
|
-
|
387
|
-
# fixed length string/bytes
|
388
|
-
return "#{arg}#{padding}"
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
# Properly encodes tuples.
|
393
|
-
def encode_tuple(arg, type)
|
394
|
-
raise EncodingError, "Expecting Hash: #{arg}" unless arg.instance_of? Hash
|
395
|
-
raise EncodingError, "Expecting #{type.components.size} elements: #{arg}" unless arg.size == type.components.size
|
396
|
-
|
397
|
-
static_size = 0
|
398
|
-
type.components.each_with_index do |component, i|
|
399
|
-
if type.components[i].dynamic?
|
400
|
-
static_size += 32
|
401
|
-
else
|
402
|
-
static_size += Util.ceil32(type.components[i].size || 0)
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
dynamic_offset = static_size
|
407
|
-
offsets_and_static_values = []
|
408
|
-
dynamic_values = []
|
409
|
-
|
410
|
-
type.components.each_with_index do |component, i|
|
411
|
-
component_type = type.components[i]
|
412
|
-
if component_type.dynamic?
|
413
|
-
offsets_and_static_values << encode_type(Type.size_type, dynamic_offset)
|
414
|
-
dynamic_value = encode_type(component_type, arg.is_a?(Array) ? arg[i] : arg[component_type.name])
|
415
|
-
dynamic_values << dynamic_value
|
416
|
-
dynamic_offset += dynamic_value.size
|
417
|
-
else
|
418
|
-
offsets_and_static_values << encode_type(component_type, arg.is_a?(Array) ? arg[i] : arg[component_type.name])
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
offsets_and_static_values.join + dynamic_values.join
|
423
|
-
end
|
424
|
-
|
425
|
-
# Properly encode struct offsets.
|
426
|
-
def encode_struct_offsets(type, arg)
|
427
|
-
result = ""
|
428
|
-
offset = arg.size
|
429
|
-
tails_encoding = arg.map { |a| encode_type(type, a) }
|
430
|
-
arg.size.times do |i|
|
431
|
-
if i == 0
|
432
|
-
offset *= 32
|
433
|
-
else
|
434
|
-
offset += tails_encoding[i - 1].size
|
435
|
-
end
|
436
|
-
offset_string = encode_type(Type.size_type, offset)
|
437
|
-
result += offset_string
|
438
|
-
end
|
439
|
-
result
|
440
|
-
end
|
441
|
-
|
442
|
-
# Properly encodes hash-strings.
|
443
|
-
def encode_hash(arg, type)
|
444
|
-
size = type.sub_type.to_i
|
445
|
-
raise EncodingError, "Argument too long: #{arg}" unless size > 0 and size <= 32
|
446
|
-
if arg.is_a? Integer
|
447
|
-
|
448
|
-
# hash from integer
|
449
|
-
return Util.zpad_int arg
|
450
|
-
elsif arg.size == size
|
451
|
-
|
452
|
-
# hash from encoded hash
|
453
|
-
return Util.zpad arg, 32
|
454
|
-
elsif arg.size == size * 2
|
455
|
-
|
456
|
-
# hash from hexa-decimal hash
|
457
|
-
return Util.zpad_hex arg
|
458
|
-
else
|
459
|
-
raise EncodingError, "Could not parse hash: #{arg}"
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
# Properly encodes addresses.
|
464
|
-
def encode_address(arg)
|
465
|
-
if arg.is_a? Integer
|
466
|
-
|
467
|
-
# address from integer
|
468
|
-
return Util.zpad_int arg
|
469
|
-
elsif arg.size == 20
|
470
|
-
|
471
|
-
# address from encoded address
|
472
|
-
return Util.zpad arg, 32
|
473
|
-
elsif arg.size == 40
|
474
|
-
|
475
|
-
# address from hexa-decimal address with 0x prefix
|
476
|
-
return Util.zpad_hex arg
|
477
|
-
elsif arg.size == 42 and arg[0, 2] == "0x"
|
478
|
-
|
479
|
-
# address from hexa-decimal address
|
480
|
-
return Util.zpad_hex arg[2..-1]
|
481
|
-
else
|
482
|
-
raise EncodingError, "Could not parse address: #{arg}"
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
# The ABI encoder needs to be able to determine between a hex `"123"`
|
487
|
-
# and a binary `"123"` string.
|
488
|
-
def handle_hex_string(arg, type)
|
489
|
-
if Util.prefixed? arg or
|
490
|
-
(arg.size === type.sub_type.to_i * 2 and Util.hex? arg)
|
491
|
-
|
492
|
-
# There is no way telling whether a string is hex or binary with certainty
|
493
|
-
# in Ruby. Therefore, we assume a `0x` prefix to indicate a hex string.
|
494
|
-
# Additionally, if the string size is exactly the double of the expected
|
495
|
-
# binary size, we can assume a hex value.
|
496
|
-
return Util.hex_to_bin arg
|
497
|
-
else
|
498
|
-
|
499
|
-
# Everything else will be assumed binary or raw string.
|
500
|
-
return arg.b
|
501
|
-
end
|
121
|
+
parsed_types.zip(outputs).map { |(type, out)| Abi::Decoder.type(type, out) }
|
502
122
|
end
|
503
123
|
end
|
504
124
|
end
|
125
|
+
|
126
|
+
require "eth/abi/decoder"
|
127
|
+
require "eth/abi/encoder"
|
128
|
+
require "eth/abi/event"
|
129
|
+
require "eth/abi/type"
|
data/lib/eth/api.rb
CHANGED
@@ -18,31 +18,31 @@ module Eth
|
|
18
18
|
# Provides the `Eth::Api` module grouping known RPC commands.
|
19
19
|
module Api
|
20
20
|
|
21
|
-
# Implements the available RPC-APIs provided by Geth version 1.10.
|
21
|
+
# Implements the available RPC-APIs provided by Geth version 1.10.26.
|
22
22
|
COMMANDS = [
|
23
|
+
"account_ecRecover",
|
24
|
+
"account_new",
|
25
|
+
"account_signData",
|
26
|
+
"account_signTransaction",
|
27
|
+
"account_signTypedData",
|
23
28
|
"admin_addPeer",
|
24
29
|
"admin_addTrustedPeer",
|
25
|
-
"admin_clearHistory",
|
26
30
|
"admin_datadir",
|
27
31
|
"admin_exportChain",
|
28
|
-
"admin_getDatadir",
|
29
|
-
"admin_getNodeInfo",
|
30
|
-
"admin_getPeers",
|
31
32
|
"admin_importChain",
|
32
33
|
"admin_nodeInfo",
|
34
|
+
"admin_peerEvents",
|
33
35
|
"admin_peers",
|
34
36
|
"admin_removePeer",
|
35
37
|
"admin_removeTrustedPeer",
|
36
|
-
"admin_sleep",
|
37
|
-
"admin_sleepBlocks",
|
38
38
|
"admin_startHTTP",
|
39
|
-
"admin_startRPC",
|
40
39
|
"admin_startWS",
|
41
40
|
"admin_stopHTTP",
|
42
|
-
"admin_stopRPC",
|
43
41
|
"admin_stopWS",
|
42
|
+
"clef_deriveAccount",
|
43
|
+
"clef_listWallets",
|
44
|
+
"clef_openWallet",
|
44
45
|
"clique_discard",
|
45
|
-
"clique_getProposals",
|
46
46
|
"clique_getSigner",
|
47
47
|
"clique_getSigners",
|
48
48
|
"clique_getSignersAtHash",
|
@@ -51,12 +51,19 @@ module Eth
|
|
51
51
|
"clique_proposals",
|
52
52
|
"clique_propose",
|
53
53
|
"clique_status",
|
54
|
+
"db_getHex",
|
55
|
+
"db_getString",
|
56
|
+
"db_putHex",
|
57
|
+
"db_putString",
|
54
58
|
"debug_accountRange",
|
55
59
|
"debug_backtraceAt",
|
56
60
|
"debug_blockProfile",
|
57
61
|
"debug_chaindbCompact",
|
58
62
|
"debug_chaindbProperty",
|
59
63
|
"debug_cpuProfile",
|
64
|
+
"debug_dbAncient",
|
65
|
+
"debug_dbAncients",
|
66
|
+
"debug_dbGet",
|
60
67
|
"debug_dumpBlock",
|
61
68
|
"debug_freeOSMemory",
|
62
69
|
"debug_freezeClient",
|
@@ -67,6 +74,10 @@ module Eth
|
|
67
74
|
"debug_getHeaderRlp",
|
68
75
|
"debug_getModifiedAccountsByHash",
|
69
76
|
"debug_getModifiedAccountsByNumber",
|
77
|
+
"debug_getRawBlock",
|
78
|
+
"debug_getRawHeader",
|
79
|
+
"debug_getRawReceipts",
|
80
|
+
"debug_getRawTransaction",
|
70
81
|
"debug_goTrace",
|
71
82
|
"debug_intermediateRoots",
|
72
83
|
"debug_memStats",
|
@@ -86,13 +97,14 @@ module Eth
|
|
86
97
|
"debug_stopCPUProfile",
|
87
98
|
"debug_stopGoTrace",
|
88
99
|
"debug_storageRangeAt",
|
89
|
-
"
|
100
|
+
"debug_subscribe",
|
90
101
|
"debug_traceBadBlock",
|
91
102
|
"debug_traceBlock",
|
92
103
|
"debug_traceBlockByHash",
|
93
104
|
"debug_traceBlockByNumber",
|
94
105
|
"debug_traceBlockFromFile",
|
95
106
|
"debug_traceCall",
|
107
|
+
"debug_traceChain",
|
96
108
|
"debug_traceTransaction",
|
97
109
|
"debug_verbosity",
|
98
110
|
"debug_vmodule",
|
@@ -104,78 +116,48 @@ module Eth
|
|
104
116
|
"eth_call",
|
105
117
|
"eth_chainId",
|
106
118
|
"eth_coinbase",
|
107
|
-
"
|
108
|
-
"
|
119
|
+
"eth_compileLLL",
|
120
|
+
"eth_compileSerpent",
|
121
|
+
"eth_compileSolidity",
|
109
122
|
"eth_createAccessList",
|
110
|
-
"eth_defaultAccount",
|
111
|
-
"eth_defaultBlock",
|
112
123
|
"eth_estimateGas",
|
113
124
|
"eth_feeHistory",
|
114
|
-
"eth_fillTransaction",
|
115
|
-
"eth_filter",
|
116
125
|
"eth_gasPrice",
|
117
|
-
"eth_getAccounts",
|
118
126
|
"eth_getBalance",
|
119
|
-
"eth_getBlock",
|
120
127
|
"eth_getBlockByHash",
|
121
128
|
"eth_getBlockByNumber",
|
122
|
-
"eth_getBlockNumber",
|
123
|
-
"eth_getBlockTransactionCount",
|
124
129
|
"eth_getBlockTransactionCountByHash",
|
125
130
|
"eth_getBlockTransactionCountByNumber",
|
126
|
-
"eth_getBlockUncleCount",
|
127
131
|
"eth_getCode",
|
128
|
-
"eth_getCoinbase",
|
129
132
|
"eth_getCompilers",
|
130
133
|
"eth_getFilterChanges",
|
131
134
|
"eth_getFilterLogs",
|
132
|
-
"eth_getGasPrice",
|
133
|
-
"eth_getHashrate",
|
134
|
-
"eth_getHeaderByHash",
|
135
|
-
"eth_getHeaderByNumber",
|
136
135
|
"eth_getLogs",
|
137
|
-
"eth_getMaxPriorityFeePerGas",
|
138
|
-
"eth_getMining",
|
139
|
-
"eth_getPendingTransactions",
|
140
136
|
"eth_getProof",
|
141
|
-
"eth_getProtocolVersion",
|
142
|
-
"eth_getRawTransaction",
|
143
|
-
"eth_getRawTransactionFromBlock",
|
144
137
|
"eth_getStorageAt",
|
145
|
-
"eth_getSyncing",
|
146
|
-
"eth_getTransaction",
|
147
138
|
"eth_getTransactionByBlockHashAndIndex",
|
148
139
|
"eth_getTransactionByBlockNumberAndIndex",
|
149
140
|
"eth_getTransactionByHash",
|
150
141
|
"eth_getTransactionCount",
|
151
|
-
"eth_getTransactionFromBlock",
|
152
142
|
"eth_getTransactionReceipt",
|
153
|
-
"
|
143
|
+
"eth_getUncleByBlockHashAndIndex",
|
144
|
+
"eth_getUncleByBlockNumberAndIndex",
|
154
145
|
"eth_getUncleCountByBlockHash",
|
155
146
|
"eth_getUncleCountByBlockNumber",
|
156
147
|
"eth_getWork",
|
157
148
|
"eth_hashrate",
|
158
|
-
"eth_iban",
|
159
|
-
"eth_icapNamereg",
|
160
|
-
"eth_isSyncing",
|
161
149
|
"eth_maxPriorityFeePerGas",
|
162
150
|
"eth_mining",
|
163
|
-
"eth_namereg",
|
164
151
|
"eth_newBlockFilter",
|
165
152
|
"eth_newFilter",
|
166
153
|
"eth_newPendingTransactionFilter",
|
167
|
-
"eth_pendingTransactions",
|
168
154
|
"eth_protocolVersion",
|
169
|
-
"eth_resend",
|
170
|
-
"eth_sendIBANTransaction",
|
171
155
|
"eth_sendRawTransaction",
|
172
156
|
"eth_sendTransaction",
|
173
157
|
"eth_sign",
|
174
158
|
"eth_signTransaction",
|
175
159
|
"eth_submitHashrate",
|
176
|
-
"eth_submitTransaction",
|
177
160
|
"eth_submitWork",
|
178
|
-
"eth_subscribe",
|
179
161
|
"eth_syncing",
|
180
162
|
"eth_uninstallFilter",
|
181
163
|
"eth_unsubscribe",
|
@@ -193,14 +175,17 @@ module Eth
|
|
193
175
|
"miner_setExtra",
|
194
176
|
"miner_setGasLimit",
|
195
177
|
"miner_setGasPrice",
|
178
|
+
"miner_setRecommitInterval",
|
196
179
|
"miner_start",
|
197
180
|
"miner_stop",
|
181
|
+
"net_listening",
|
182
|
+
"net_peerCount",
|
183
|
+
"net_version",
|
198
184
|
"personal_deriveAccount",
|
199
185
|
"personal_ecRecover",
|
200
|
-
"personal_getListAccounts",
|
201
|
-
"personal_getListWallets",
|
202
186
|
"personal_importRawKey",
|
203
187
|
"personal_initializeWallet",
|
188
|
+
"personal_initializeWallets",
|
204
189
|
"personal_listAccounts",
|
205
190
|
"personal_listWallets",
|
206
191
|
"personal_lockAccount",
|
@@ -211,13 +196,22 @@ module Eth
|
|
211
196
|
"personal_signTransaction",
|
212
197
|
"personal_unlockAccount",
|
213
198
|
"personal_unpair",
|
199
|
+
"shh_addToGroup",
|
200
|
+
"shh_getFilterChanges",
|
201
|
+
"shh_getMessages",
|
202
|
+
"shh_hasIdentity",
|
203
|
+
"shh_newFilter",
|
204
|
+
"shh_newGroup",
|
205
|
+
"shh_newIdentity",
|
206
|
+
"shh_post",
|
207
|
+
"shh_uninstallFilter",
|
208
|
+
"shh_version",
|
214
209
|
"txpool_content",
|
215
210
|
"txpool_contentFrom",
|
216
|
-
"txpool_getContent",
|
217
|
-
"txpool_getInspect",
|
218
|
-
"txpool_getStatus",
|
219
211
|
"txpool_inspect",
|
220
212
|
"txpool_status",
|
213
|
+
"web3_clientVersion",
|
214
|
+
"web3_sha3",
|
221
215
|
]
|
222
216
|
end
|
223
217
|
end
|
data/lib/eth/chain.rb
CHANGED
@@ -104,6 +104,15 @@ module Eth
|
|
104
104
|
# Chain ID for the geth private network preset.
|
105
105
|
PRIVATE_GETH = 1337.freeze
|
106
106
|
|
107
|
+
# Chain ID for Moonbase
|
108
|
+
MOONBASE = 1287.freeze
|
109
|
+
|
110
|
+
# Chain ID for Moonriver
|
111
|
+
MOONRIVER = 1285.freeze
|
112
|
+
|
113
|
+
# Chain ID for Moonbeam
|
114
|
+
MOONBEAM = 1284.freeze
|
115
|
+
|
107
116
|
# Indicates wether the given `v` indicates a legacy chain value
|
108
117
|
# used by ledger wallets without EIP-155 replay protection.
|
109
118
|
#
|
data/lib/eth/client/http.rb
CHANGED
@@ -17,7 +17,7 @@ require "net/http"
|
|
17
17
|
# Provides the {Eth} module.
|
18
18
|
module Eth
|
19
19
|
|
20
|
-
# Provides an HTTP/S-RPC client.
|
20
|
+
# Provides an HTTP/S-RPC client with basic authentication.
|
21
21
|
class Client::Http < Client
|
22
22
|
|
23
23
|
# The host of the HTTP endpoint.
|
@@ -32,8 +32,11 @@ module Eth
|
|
32
32
|
# Attribute indicator for SSL.
|
33
33
|
attr_reader :ssl
|
34
34
|
|
35
|
+
# Attribute for user.
|
36
|
+
attr_reader :user
|
37
|
+
|
35
38
|
# Constructor for the HTTP Client. Should not be used; use
|
36
|
-
# {Client.create}
|
39
|
+
# {Client.create} instead.
|
37
40
|
#
|
38
41
|
# @param host [String] an URI pointing to an HTTP RPC-API.
|
39
42
|
def initialize(host)
|
@@ -43,14 +46,20 @@ module Eth
|
|
43
46
|
@host = uri.host
|
44
47
|
@port = uri.port
|
45
48
|
@ssl = uri.scheme == "https"
|
46
|
-
|
49
|
+
if !(uri.user.nil? && uri.password.nil?)
|
50
|
+
@user = uri.user
|
51
|
+
@password = uri.password
|
52
|
+
@uri = URI("#{uri.scheme}://#{uri.user}:#{uri.password}@#{@host}:#{@port}#{uri.path}")
|
53
|
+
else
|
54
|
+
@uri = URI("#{uri.scheme}://#{@host}:#{@port}#{uri.path}")
|
55
|
+
end
|
47
56
|
end
|
48
57
|
|
49
58
|
# Sends an RPC request to the connected HTTP client.
|
50
59
|
#
|
51
60
|
# @param payload [Hash] the RPC request parameters.
|
52
61
|
# @return [String] a JSON-encoded response.
|
53
|
-
def
|
62
|
+
def send_request(payload)
|
54
63
|
http = Net::HTTP.new(@host, @port)
|
55
64
|
http.use_ssl = @ssl
|
56
65
|
header = { "Content-Type" => "application/json" }
|
@@ -60,4 +69,9 @@ module Eth
|
|
60
69
|
response.body
|
61
70
|
end
|
62
71
|
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# Attribute for password.
|
76
|
+
attr_reader :password
|
63
77
|
end
|