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.
- checksums.yaml +4 -4
- data/.github/workflows/codeql.yml +1 -1
- data/.github/workflows/docs.yml +2 -2
- data/.github/workflows/spec.yml +1 -3
- data/LICENSE.txt +1 -1
- data/README.md +1 -3
- data/eth.gemspec +3 -0
- data/lib/eth/abi/decoder.rb +2 -2
- data/lib/eth/abi/encoder.rb +4 -5
- data/lib/eth/abi/event.rb +5 -1
- data/lib/eth/abi/packed/encoder.rb +196 -0
- data/lib/eth/abi/type.rb +12 -12
- data/lib/eth/abi.rb +27 -2
- data/lib/eth/address.rb +3 -1
- data/lib/eth/api.rb +1 -1
- data/lib/eth/chain.rb +6 -1
- data/lib/eth/client/http.rb +7 -3
- data/lib/eth/client/ipc.rb +1 -1
- data/lib/eth/client.rb +1 -1
- data/lib/eth/constant.rb +1 -1
- data/lib/eth/contract/event.rb +69 -16
- data/lib/eth/contract/function.rb +1 -1
- data/lib/eth/contract/function_input.rb +1 -1
- data/lib/eth/contract/function_output.rb +1 -1
- data/lib/eth/contract/initializer.rb +1 -1
- data/lib/eth/contract.rb +1 -1
- data/lib/eth/eip712.rb +3 -2
- data/lib/eth/ens/coin_type.rb +1 -1
- data/lib/eth/ens/resolver.rb +1 -1
- data/lib/eth/ens.rb +1 -1
- data/lib/eth/key/decrypter.rb +1 -1
- data/lib/eth/key/encrypter.rb +1 -1
- data/lib/eth/key.rb +1 -1
- data/lib/eth/rlp/decoder.rb +1 -1
- data/lib/eth/rlp/encoder.rb +1 -1
- data/lib/eth/rlp/sedes/big_endian_int.rb +1 -1
- data/lib/eth/rlp/sedes/binary.rb +1 -1
- data/lib/eth/rlp/sedes/list.rb +1 -1
- data/lib/eth/rlp/sedes.rb +1 -1
- data/lib/eth/rlp.rb +1 -1
- data/lib/eth/signature.rb +1 -1
- data/lib/eth/solidity.rb +1 -1
- data/lib/eth/tx/eip1559.rb +1 -1
- data/lib/eth/tx/eip2930.rb +1 -1
- data/lib/eth/tx/eip7702.rb +495 -0
- data/lib/eth/tx/legacy.rb +1 -1
- data/lib/eth/tx.rb +50 -1
- data/lib/eth/unit.rb +1 -1
- data/lib/eth/util.rb +1 -1
- data/lib/eth/version.rb +2 -2
- data/lib/eth.rb +1 -1
- metadata +19 -3
data/lib/eth/contract/event.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-
|
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
|
-
@
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
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
|
-
|
48
|
-
case type
|
101
|
+
case x["type"]
|
49
102
|
when "tuple"
|
50
|
-
"(#{x["components"].
|
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
|
data/lib/eth/contract.rb
CHANGED
data/lib/eth/eip712.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-
|
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
|
data/lib/eth/ens/coin_type.rb
CHANGED
data/lib/eth/ens/resolver.rb
CHANGED
data/lib/eth/ens.rb
CHANGED
data/lib/eth/key/decrypter.rb
CHANGED
data/lib/eth/key/encrypter.rb
CHANGED
data/lib/eth/key.rb
CHANGED
data/lib/eth/rlp/decoder.rb
CHANGED
data/lib/eth/rlp/encoder.rb
CHANGED
data/lib/eth/rlp/sedes/binary.rb
CHANGED
data/lib/eth/rlp/sedes/list.rb
CHANGED
data/lib/eth/rlp/sedes.rb
CHANGED
data/lib/eth/rlp.rb
CHANGED
data/lib/eth/signature.rb
CHANGED
data/lib/eth/solidity.rb
CHANGED
data/lib/eth/tx/eip1559.rb
CHANGED
data/lib/eth/tx/eip2930.rb
CHANGED