eth 0.5.13 → 0.5.14

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql.yml +1 -1
  3. data/.github/workflows/docs.yml +2 -2
  4. data/.github/workflows/spec.yml +1 -3
  5. data/LICENSE.txt +1 -1
  6. data/README.md +1 -3
  7. data/eth.gemspec +3 -0
  8. data/lib/eth/abi/decoder.rb +2 -2
  9. data/lib/eth/abi/encoder.rb +4 -5
  10. data/lib/eth/abi/event.rb +5 -1
  11. data/lib/eth/abi/packed/encoder.rb +196 -0
  12. data/lib/eth/abi/type.rb +12 -12
  13. data/lib/eth/abi.rb +27 -2
  14. data/lib/eth/address.rb +3 -1
  15. data/lib/eth/api.rb +1 -1
  16. data/lib/eth/chain.rb +6 -1
  17. data/lib/eth/client/http.rb +7 -3
  18. data/lib/eth/client/ipc.rb +1 -1
  19. data/lib/eth/client.rb +1 -1
  20. data/lib/eth/constant.rb +1 -1
  21. data/lib/eth/contract/event.rb +69 -16
  22. data/lib/eth/contract/function.rb +1 -1
  23. data/lib/eth/contract/function_input.rb +1 -1
  24. data/lib/eth/contract/function_output.rb +1 -1
  25. data/lib/eth/contract/initializer.rb +1 -1
  26. data/lib/eth/contract.rb +1 -1
  27. data/lib/eth/eip712.rb +3 -2
  28. data/lib/eth/ens/coin_type.rb +1 -1
  29. data/lib/eth/ens/resolver.rb +1 -1
  30. data/lib/eth/ens.rb +1 -1
  31. data/lib/eth/key/decrypter.rb +1 -1
  32. data/lib/eth/key/encrypter.rb +1 -1
  33. data/lib/eth/key.rb +1 -1
  34. data/lib/eth/rlp/decoder.rb +1 -1
  35. data/lib/eth/rlp/encoder.rb +1 -1
  36. data/lib/eth/rlp/sedes/big_endian_int.rb +1 -1
  37. data/lib/eth/rlp/sedes/binary.rb +1 -1
  38. data/lib/eth/rlp/sedes/list.rb +1 -1
  39. data/lib/eth/rlp/sedes.rb +1 -1
  40. data/lib/eth/rlp.rb +1 -1
  41. data/lib/eth/signature.rb +1 -1
  42. data/lib/eth/solidity.rb +1 -1
  43. data/lib/eth/tx/eip1559.rb +1 -1
  44. data/lib/eth/tx/eip2930.rb +1 -1
  45. data/lib/eth/tx/eip7702.rb +495 -0
  46. data/lib/eth/tx/legacy.rb +1 -1
  47. data/lib/eth/tx.rb +50 -1
  48. data/lib/eth/unit.rb +1 -1
  49. data/lib/eth/util.rb +1 -1
  50. data/lib/eth/version.rb +2 -2
  51. data/lib/eth.rb +1 -1
  52. metadata +19 -3
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -16,40 +16,93 @@
16
16
 
17
17
  # Provides the {Eth} module.
18
18
  module Eth
19
-
20
19
  # Provide classes for contract event.
21
20
  class Contract::Event
22
- attr_accessor :name, :signature, :input_types, :inputs, :event_string, :address
23
-
24
21
  # Constructor of the {Eth::Contract::Event} class.
25
22
  #
26
23
  # @param data [Hash] contract event data.
27
24
  def initialize(data)
28
- @name = data["name"]
29
- @input_types = data["inputs"].collect do |x|
30
- type_name x
31
- end
32
- @inputs = data["inputs"].collect { |x| x["name"] }
33
- @event_string = Abi::Event.signature(data)
34
- @signature = Digest::Keccak.hexdigest(@event_string, 256)
25
+ @data = data
26
+ end
27
+
28
+ # Returns the name of the event.
29
+ #
30
+ # @return [String] The event name.
31
+ def name
32
+ @data["name"]
33
+ end
34
+
35
+ # Returns the input types for the event.
36
+ #
37
+ # @return [Array<String>] An array of input type names.
38
+ def input_types
39
+ @input_types ||= @data["inputs"].map { |x| type_name(x) }
40
+ end
41
+
42
+ # Returns the names of input parameters.
43
+ #
44
+ # @return [Array<String>] An array of input parameter names.
45
+ def inputs
46
+ @inputs ||= @data["inputs"].map { |x| x["name"] }
47
+ end
48
+
49
+ # Returns the event signature string.
50
+ #
51
+ # @return [String] The event signature string, generated from ABI.
52
+ def event_string
53
+ @event_string ||= Abi::Event.signature(@data)
54
+ end
55
+
56
+ # Returns the Keccak-256 event signature hash.
57
+ #
58
+ # @return [String] The event signature hash in hexadecimal format.
59
+ def signature
60
+ @signature ||= Digest::Keccak.hexdigest(event_string, 256)
61
+ end
62
+
63
+ # Returns the Ethereum address associated with the event.
64
+ #
65
+ # @return [String, nil] The Ethereum address, or `nil` if not set.
66
+ def address
67
+ @address ||= nil
35
68
  end
36
69
 
37
70
  # Set the address of the smart contract
38
71
  #
39
72
  # @param address [String] contract address.
40
73
  def set_address(address)
41
- @address = address.nil? ? nil : Eth::Address.new(address).address
74
+ @address = address ? Eth::Address.new(address).address : nil
75
+ end
76
+
77
+ # Decodes event parameters from logs.
78
+ #
79
+ # @param topics [Array<String>] The list of log topics, including the event selector.
80
+ # @param data [String] The log data containing non-indexed parameters.
81
+ # @return [ActiveSupport::HashWithIndifferentAccess] A hash of decoded event parameters.
82
+ def decode_params(topics, data = "0x")
83
+ inputs = @data["inputs"]
84
+
85
+ indexed_inputs, non_indexed_inputs = inputs.partition { _1["indexed"] }
86
+
87
+ {
88
+ **indexed_inputs.each_with_index.inject({}) do |result, (input, index)|
89
+ result[input["name"]] = Eth::Abi.decode([input["type"]], topics[index + 1])[0]
90
+ result
91
+ end,
92
+ **Hash[non_indexed_inputs.map { _1["name"] }.zip(
93
+ Eth::Abi.decode(non_indexed_inputs.map { |i| i["type"] }, data)
94
+ )],
95
+ }
42
96
  end
43
97
 
44
98
  private
45
99
 
46
100
  def type_name(x)
47
- type = x["type"]
48
- case type
101
+ case x["type"]
49
102
  when "tuple"
50
- "(#{x["components"].collect { |c| type_name(c) }.join(",")})"
103
+ "(#{x["components"].map { |c| type_name(c) }.join(",")})"
51
104
  else
52
- type
105
+ x["type"]
53
106
  end
54
107
  end
55
108
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/contract.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/eip712.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -113,7 +113,6 @@ module Eth
113
113
  types[primary_type.to_sym].each do |field|
114
114
  value = data[field[:name].to_sym]
115
115
  type = field[:type]
116
- raise NotImplementedError, "Arrays currently unimplemented for EIP-712." if type.end_with? "]"
117
116
  if type == "string"
118
117
  encoded_types.push "bytes32"
119
118
  encoded_values.push Util.keccak256 value
@@ -125,6 +124,8 @@ module Eth
125
124
  encoded_types.push "bytes32"
126
125
  value = encode_data type, value, types
127
126
  encoded_values.push Util.keccak256 value
127
+ elsif type.end_with? "]"
128
+ raise NotImplementedError, "Arrays currently unimplemented for EIP-712."
128
129
  else
129
130
  encoded_types.push type
130
131
  encoded_values.push value
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/ens.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/key.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/rlp/sedes.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/rlp.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/signature.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/lib/eth/solidity.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2025 The Ruby-Eth Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.