Class: Eth::Contract::Error
- Inherits:
-
Object
- Object
- Eth::Contract::Error
- Defined in:
- lib/eth/contract/error.rb
Overview
Provide classes for contract custom errors.
Instance Attribute Summary collapse
-
#error_string ⇒ Object
Returns the value of attribute error_string.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#signature ⇒ Object
Returns the value of attribute signature.
Class Method Summary collapse
-
.calc_signature(name, inputs) ⇒ String
Creates error strings.
-
.encoded_error_signature(signature) ⇒ String
Encodes an error signature.
Instance Method Summary collapse
-
#decode(data) ⇒ Array
Decodes a revert error payload.
-
#initialize(data) ⇒ Error
constructor
Constructor of the Error class.
Constructor Details
#initialize(data) ⇒ Error
Constructor of the Eth::Contract::Error class.
26 27 28 29 30 31 32 33 |
# File 'lib/eth/contract/error.rb', line 26 def initialize(data) @name = data["name"] @inputs = data.fetch("inputs", []).map do |input| Eth::Contract::FunctionInput.new(input) end @error_string = self.class.calc_signature(@name, @inputs) @signature = self.class.encoded_error_signature(@error_string) end |
Instance Attribute Details
#error_string ⇒ Object
Returns the value of attribute error_string.
21 22 23 |
# File 'lib/eth/contract/error.rb', line 21 def error_string @error_string end |
#inputs ⇒ Object
Returns the value of attribute inputs.
21 22 23 |
# File 'lib/eth/contract/error.rb', line 21 def inputs @inputs end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/eth/contract/error.rb', line 21 def name @name end |
#signature ⇒ Object
Returns the value of attribute signature.
21 22 23 |
# File 'lib/eth/contract/error.rb', line 21 def signature @signature end |
Class Method Details
.calc_signature(name, inputs) ⇒ String
Creates error strings.
40 41 42 |
# File 'lib/eth/contract/error.rb', line 40 def self.calc_signature(name, inputs) "#{name}(#{inputs.map { |x| x.parsed_type.to_s }.join(",")})" end |
.encoded_error_signature(signature) ⇒ String
Encodes an error signature.
48 49 50 |
# File 'lib/eth/contract/error.rb', line 48 def self.encoded_error_signature(signature) Util.prefix_hex(Util.bin_to_hex(Util.keccak256(signature)[0..3])) end |